BuyLimit gives invalid price error

Dear Members,

I am trying to write an Expert Advisor with MQL5 that initiates buy limits based on certain EMA values. Here is the code that I have written in OnTick() function.

MqlRates priceData[]; //create a price array
   
   //sort the array from the current candle downwards
   ArraySetAsSeries(priceData, true);
   
   //copy candle prices for 5 candles into array
   CopyRates(_Symbol, _Period, 0,5, priceData);
   
   //EMA Based Trading
   
   int ema8 = iMA(_Symbol, _Period, 8, 0, MODE_EMA, PRICE_CLOSE);
   int ema21 = iMA(_Symbol, _Period, 21, 0, MODE_EMA, PRICE_CLOSE);
   
   //Arrays to store EMAs
   double ema8Array[], ema21Array[];
   
   
   //Sorting EMAs fot the current candle downwards 
   ArraySetAsSeries(ema8Array, true);
   ArraySetAsSeries(ema21Array, true);
   
   //Defined EMA8, one line, current candle, 5 candles, store result
   CopyBuffer(ema8,0,0,5,ema8Array);
   
   //Defined EMA21, one line, current candle, 5 candles, store result
   CopyBuffer(ema21,0,0,5,ema21Array);
   
   if(ema8Array[0] > ema21Array[0])
   {
      
      if(
      (ema8Array[0] >= priceData[1].close) 
      && 
      (priceData[1].close < ema21Array[0]))
      {
        Print("Chance To Buy"); 
        
        double closePrices[5];
        
        closePrices[0]=priceData[1].close;
        closePrices[1]=priceData[2].close;
        closePrices[2]=priceData[3].close;
        closePrices[3]=priceData[4].close;
        
        if((OrdersTotal() == 0) && (PositionsTotal() == 0))
        {
         int maxValue=ArrayMaximum(closePrices,0,WHOLE_ARRAY);
         double buyStop=closePrices[maxValue]+0.00003;
         double stopLoss=priceData[1].close-0.00004;
         double takeProfit=buyStop+(buyStop-stopLoss);
         
         trade.BuyLimit(0.01,buyStop,_Symbol,0,0,ORDER_TIME_GTC,0,"Limit Added");
        }
      }
      
   }

When I run it it strategy testing with EURUSD on H1 timeline, I get the following error most of the times:

2018.12.25 14:27:47.117 2017.01.02 09:00:09   failed buy limit 0.01 EURUSD at 1.05342 [Invalid price]
2018.12.25 14:27:47.117 2017.01.02 09:00:09   CTrade::OrderSend: buy limit 0.01 EURUSD at 1.05342 [invalid price]

Can you please tell me what I might be doing wrong?

Apologies in advance if this is a very basic question for your precious time, I am new into MQL5 coding and it is hard for me to understand many things. I have read the existing material as much as I can but I still do not understand why I am getting this error. Please help and thank you.

  • https://www.metatrader4.com/en/trading-platform/help/positions/orders

  • Pending Order
    Pending order is the client’s commitment to the brokerage company to buy or sell a security at a pre-defined price in the future. This type of orders is used for opening of a trade position provided the future quotes reach the pre-defined level. There are four types of pending orders available in the terminal:

    • Buy Limit – buy provided the future “ASK” price is equal to the pre-defined value. The current price level is higher than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having fallen to a certain level, will increase;
    • Buy Stop – buy provided the future “ASK” price is equal to the pre-defined value. The current price level is lower than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having reached a certain level, will keep on increasing;
    • Sell Limit – sell provided the future “BID” price is equal to the pre-defined value. The current price level is lower than the value of the placed order. Orders of this type are usually placed in anticipation of that the security price, having increased to a certain level, will fall;
    • Sell Stop – sell provided the future “BID” price is equal to the pre-defined value. The current price level is higher than the value of the placed order. Orders of this type are usually placed in anticipation of that the

Thank you very much. I understand now what I was doing wrong.