Jump to content

Cannot place orders in any Expert Advisor; Error Code 130 and 131


Recommended Posts

I have been attempting to place a trade, any trade, in my Demo Account, using an Expert Advisor. When the EA issues a Buy or Sell order, I get error code 130 or 131.

Yes, I have the AutoTrading button enabled on the chart, and "Live Trading" is checked. 

Yes, I am trading EURUSD.FX. And yes, I can place a manual trade, either Buy or Sell.

For your information, I am using Linux, with Wine that emulates Windows. I have not experienced any other issues, and as I said, I can issue manual Buy and Sell orders. So I don't think Wine is getting in the way. I think it's something with my Buy and Sell order within the EA. Maybe the wrong lot size, or some other parameter. I have tried changing the lot size, but it makes no difference.

I am posting here the code from my EA, and the code for the function, which gets called from the EA. I am also posting a screen print, showing the actual error code.

I realize that if I get this code to work, I will be submitting Buy or Sell orders extremely rapidly, until I run out of margin. I am on a Demo Account, so I'm not worried about that right now. I'll address that issue when I can actually get some orders submitted.

So, what gives? What am I doing wrong? Thanks.

bool CheckOpenOrders(){ 
        // We need to scan all the open and pending orders to see if there are any.
        // OrdersTotal returns the total number of market and pending orders.
        // What we do is scan all orders and check if they are of the same symbol as the one where the EA is running.
        for( int i = 0 ; i < OrdersTotal() ; i++ ) { 
                // We select the order of index i selecting by position and from the pool of market/pending trades.
                OrderSelect( i, SELECT_BY_POS, MODE_TRADES ); 
                // If the pair of the order is equal to the pair where the EA is running.
                if (OrderSymbol() == Symbol()) return(true); 
        } 
        // If the loop finishes it mean there were no open orders for that pair.
        return(false); 

//+------------------------------------------------------------------+
//|                                                 Alternator01.mq4 |
//|                                                     Len Cheatham |
//|                                             https://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright "Len Cheatham"
#property link      "https://www.mql4.com"
#property version   "1.00"
#property strict
#include <C:/Program Files (x86)/IG MetaTrader 4 Terminal/MQL4/Include/Strings/CustomFunctions01.mqh>
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   Alert("Are there open orders for this currency? ",CheckOpenOrders()); 
   Alert("");
   Alert("Symbol = ", Symbol());  
   if (Close[0] > Open[0])
   {
     int orderID = OrderSend(_Symbol,OP_BUY,0.0001,Ask,10,1.001,1.001);
     if(orderID < 0) Alert("Buy Order rejected, Order error: " + GetLastError());
//     if(CheckOpenOrders())
//     {
//       if // Sell the current 
//     }
   }
   else
     {
       if (Close[0] < Open[0])
       {
         int orderID = OrderSend(_Symbol,OP_SELL,0.0001,Bid,10,1.001,1.001);
         if(orderID < 0) Alert("Sell Order rejected, Order error: " + GetLastError());
       }
     }
  }
//+------------------------------------------------------------------+
 

Screenshot from 2022-03-24 09-22-41.png

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • image.png

  • Posts

    • ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA Elliott Elliott Wave Technical Analysis TradingLounge (1D Chart)   Greetings, Our Elliott Wave analysis today updates the Australian Stock Exchange (ASX) with COMMONWEALTH BANK OF AUSTRALIA. - CBA. We identify a correction wave as the 2-red wave that has just ended, and we are continuously watching for a CBA for a Long-term trade.     ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA Elliott Wave Technical Analysis   ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA 1D Chart (Semilog Scale) Analysis   Function: Major trend (Minor degree, red) Mode: Motive Structure: Impulse Position: Wave 3-red Details: The short-term outlook indicates a fairly rapid and strong price increase from the low of 109.94, suggesting that the 2-red wave has concluded, and the 3-red wave is unfolding. Pushing above and breaking the upper boundary line of the channel further clarifies this bullish view. We are closely monitoring CBA as we identify a long-term trading opportunity by seeking a strong support level at the Minor Level 110. Invalidation point: 96.15       ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA Elliott Wave Technical Analysis TradingLounge (4-Hour Chart)   ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA Elliott Wave Technical Analysis ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA 4-Hour Chart Analysis   Function: Major trend (Minor degree, red)   Mode: Motive   Structure: Impulse   Position: Wave 3-red   Details: The shorter-term outlook suggests that the recent completion of the 1-red wave and the initiation of the 2-red wave have occurred to push prices lower. It appears that the 2-red wave has completed, allowing the 3-red wave to unfold upwards. We are closely monitoring CBA as there is a potential long-term trading opportunity with CBA. A rise above 120.60 would clarify the bullish outlook.   Invalidation point: 95.15         Conclusion:   Our analysis, forecast of contextual trends, and short-term outlook for ASX: COMMONWEALTH BANK OF AUSTRALIA. - CBA aim to provide readers with insights into the current market trends and how to capitalize on them effectively. We offer specific price points that act as validation or invalidation signals for our wave count, enhancing the confidence in our perspective. By combining these factors, we strive to offer readers the most objective and professional perspective on market trends.   Technical Analyst: Hua (Shane) Cuong, CEWA-M (Master’s Designation).   Source : Tradinglounge.com get trial here!  
    • Elliott Wave Analysis TradingLounge Daily Chart, Cadarno/ U.S. dollar(ADAUSD) ADAUSD Elliott Wave Technical Analysis  Function: Counter Trend Mode: Corrective Structure: Flat Position: Wave C Direction Next higher Degrees: wave (II) of Impulse Wave Cancel invalid level:  Details: Wave II Is equal to 61.8% of Wave I at 0.358 Cadarno/ U.S. dollar(ADAUSD)Trading Strategy: The second wave correction in the Expanded Flat pattern, where we are in the middle of a decline in Wave C, will have five extended internal sub-waves. But we still have one more decline left for Wave C to complete. So wait for the correction to complete to rejoin the trend. Cardano/ U.S. dollar(ADAUSD)Technical Indicators: The price is below the MA200 indicating a Dow trend, The Wave Oscillator is a Bearish Momentum.       Elliott Wave Analysis TradingLounge H4 Chart, Cadarno/ U.S. dollar(ADAUSD) ADAUSD Elliott Wave Technical Analysis  Function: Follow Trend Mode: Motive Structure: Impulse Position: Wave 4 Direction Next higher Degrees: wave C of Flat Wave Cancel invalid level:  Details: A short-term pullback in wave 4 before falling again in wave 5. Cardano/ U.S. dollar(ADAUSD)Trading Strategy: The second wave correction in the Expanded Flat pattern, where we are in the middle of a decline in Wave C, will have five extended internal sub-waves. But we still have one more decline left for Wave C to complete. So wait for the correction to complete to rejoin the trend. Cardano/ U.S. dollar(ADAUSD)Technical Indicators: The price is below the MA200 indicating a Dow trend, The Wave Oscillator is a Bearish Momentum. Technical Analyst : Kittiampon Somboonsod Source : Tradinglounge.com get trial here!    
×
×
  • Create New...
us