Getting Error 131, Invalid trading volume no matter what the lot size is (EA)

 

Hello Everyone,


I am coding an EA, this EA had a calculating lot size function, when trying to backtest my EA my order was rejected and got error 131 Invalid trade volume, when I checked what were the trading volumes that the EA used there was nothing strange 0.1 or 0.01 or so, nothing particular, as I used a NormalizeDouble() function to make sure the lot size is has no more than 2 decimals, I checked on my optimal lot size function and could not see an error, but just in case I made the optimal lot step a comment and added a fixed lot size tried it with 0.1 and 1.1, but kept getting the same error, I checked with my broker to see if they had any restrictions on EAs or backtesting for some reason(I knew this was unlikely)  but still couldn't find a reason as to why I'm getting an invalid trade volume. I will attach part of my EA so that you have an idea on what I am doing and the Journal of the backtesting. If anyone has an idea of what this could be I would be truly grateful. Thank you in advance


if(Bid > bbUpperW && Open[0] < bbUpperW && rsiV > rsiUL)
         {
            Print("Going Short");
            double entryPrice = Bid;
            double takeProfitPrice = NormalizeDouble(bbLowerT,Digits);
            double stopLossPrice = NormalizeDouble(bbUpperS,Digits);
            //double lotSize = optimalLotsize(riskPercentage,entryPrice,stopLossPrice);
            double lotSize = 1.1;
            Alert("Lot size = "+ lotSize);
            
            int orderID = OrderSend(NULL,OP_SELL,lotSize,entryPrice,10,stopLossPrice,takeProfitPrice,NULL,magicNumber);
            if (orderID < 0)
            {
               string whatError = whichError(orderID);
               Print(whatError);
            }
            else
            {
               Print("Entry price = " + OrderOpenPrice());
               Print("Take Profit = " +OrderTakeProfit()); 
               Print("Stop Loss = " + OrderStopLoss());
               Print("Lot size = "+ lotSize);
               Print("Trade ID = " + orderID);
            }
         }
Files:
errorTrade.PNG  17 kb
 

How are we supposed to know what whichError() does and why do you send the orderID to it?

               string whatError = whichError(orderID);
               Print(whatError);
 
            int orderID = OrderSend(NULL,OP_SELL,lotSize,entryPrice,10,stopLossPrice,takeProfitPrice,NULL,magicNumber);

Be careful with NULL.

  1. On MT4, you can use NULL in place of _Symbol only in those calls that the documentation specially says you can. iHigh does, iCustom does, MarketInfo does not, OrderSend does not.
  2. Don't use NULL (except for pointers where you explicitly check for it.) Use _Symbol and _Period, that is minimalist as possible and more efficient.
  3. Zero is the same as PERIOD_CURRENT which means _Period. Don't hard code numbers.
  4. MT4: No need for a function call with iHigh(NULL,0,s) just use the predefined arrays, i.e. High[].
  5. Cloud Protector Bug? - MQL4 programming forum (2020)
Reason: