Getting Error Code 138 in Backtesting

 

Hello,


I have written a code which is running as per my requirement in the demo account. However, when I wanted to perform a backtesting of the EA, it is giving me "OrderSend error 138" for all the trades. 


Is there a way to resolve this. 


      if(TotalBuyOrdersCount(TradeSymbol)==0)
      {
         if((int)MarketInfo(TradeSymbol, MODE_DIGITS)%2==1)
            TP = NormalizeDouble(TakeProfit*(double)MarketInfo(TradeSymbol, MODE_POINT)*10,(int)MarketInfo(TradeSymbol, MODE_DIGITS));
         else
            TP = NormalizeDouble(TakeProfit*(double)MarketInfo(TradeSymbol, MODE_POINT)*10,(int)MarketInfo(TradeSymbol, MODE_DIGITS));
         SL = TP*10;
         aku = OrderSend(TradeSymbol, OP_BUY, LotSize, (double)MarketInfo(TradeSymbol, MODE_BID), 10, (double)MarketInfo(TradeSymbol, MODE_ASK)-SL, (double)MarketInfo(TradeSymbol, MODE_ASK)+TP, "NeoLogic",22349,0,clrNONE);
         
      }
 
Amar K Uttarkar: Hello, I have written a code which is running as per my requirement in the demo account. However, when I wanted to perform a backtesting of the EA, it is giving me "OrderSend error 138" for all the trades. Is there a way to resolve this. 

Did you search the forum for other threads and posts about OrderSend Error 138? You would have found many, many threads and posts on it!

Did you make the effort to look at the MQL4 documentation to see what Error 138 means? It means there was a "requote"!

Do you know what a "requote" is? Did you search the web for the meaning of a "Requote"? It means that the price you are requesting is not accepted by the broker at that time.

The reason is that you are trying to buy at the bid price, but the market will only allow you to buy it at the ask price.

Why do you not know this? Because you did not read the documentation: Requirements and Limitations in Making Trades

The rules are that you enter a Buy at the market Ask price and exit at the Bid price. For a Sell you enter at the market Bid price and exit at the Ask price.

Reason: