OrderModify not working, reporting error 4754

 

I'm trying to code my EA in mql5 and after a certain condition is met I would like the EA to loop through all the open orders and modify the SL, to just a few pips above/below the order open price but after double checking over and over it keeps on reporting Error 4754. I check and ensure that orders do indeed exist and that I am calling them according to their ticket numbers but its still not functioning.. This is my first time posting in the forum, hope I didnt infringe on any rules..

void breakEven(double currPrice)
{
   breakEvenComment = "2 Pips Up, now we lock!";
   bool positionSelectedbool;
   
       
   if(tradetype == 1)
   {
      for(int i=PositionsTotal()-1; i>=0; i--)
      {
         string symbol=PositionGetSymbol(POSITION_SYMBOL);
         ulong ticket=PositionGetTicket(i);
         Print(ticket);
         if(PositionGetSymbol(POSITION_SYMBOL)==Symbol() && trade.RequestMagic() == magiknumBuy)
         {  
            double orderOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
            double orderTP = PositionGetDouble(POSITION_TP);
            double orderSL = PositionGetDouble(POSITION_SL);
            
            if( ((currPrice - orderOpenPrice) >= 200000 * _Point) && orderSL < orderOpenPrice)
            {
               Print(breakEvenComment);
               positionSelectedbool = PositionSelectByTicket(ticket);
               PositionSelect(_Symbol);
               
               if(trade.OrderModify(ticket,orderOpenPrice,(orderOpenPrice+20000*_Point),orderTP,ORDER_TIME_GTC,0,0) == true)
               {
                  Print("Buy Order Modified Successfully!");
               }
               else
               {
                  int errorCode = GetLastError();
                  Print("Error: " + IntegerToString(errorCode) + ErrorDescription(errorCode));
               }
            }
         }
      }
   }
   
   if(tradetype == 2)
   {
      for(int i=PositionsTotal()-1; i>=0; i--)
      {
         string symbol=PositionGetSymbol(POSITION_SYMBOL);
         ulong ticket=PositionGetTicket(i);
         Print(ticket);
      
         if(PositionGetSymbol(POSITION_SYMBOL)==Symbol() && trade.RequestMagic() == magiknumSell)
         {  
            double orderOpenPrice = PositionGetDouble(POSITION_PRICE_OPEN);
            double orderTP = PositionGetDouble(POSITION_TP);
            double orderSL = PositionGetDouble(POSITION_SL);
            
            if( ((orderOpenPrice - currPrice) >= 200000 * _Point) && orderSL > orderOpenPrice)
            {
               Print(breakEvenComment);
               positionSelectedbool = PositionSelectByTicket(ticket);
               PositionSelect(_Symbol);
               
               if(trade.OrderModify(ticket,orderOpenPrice,(orderOpenPrice-20000*_Point),orderTP,ORDER_TIME_GTC,0,0) == true)
               {
                  Print("Sell Order Modified Successfully!");
               }
               else
               {  
                  int errorCode = GetLastError();
                  Print("Error: " + IntegerToString(errorCode) + ErrorDescription(errorCode));
               }
            }
         }
      }
   }
}
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
Documentation on MQL5: Constants, Enumerations and Structures / Indicator Constants / Price Constants
  • www.mql5.com
Price Constants - Indicator Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
NasdaqDude 24:

I'm trying to code my EA in mql5 and after a certain condition is met I would like the EA to loop through all the open orders and modify the SL, to just a few pips above/below the order open price but after double checking over and over it keeps on reporting Error 4754. I check and ensure that orders do indeed exist and that I am calling them according to their ticket numbers but its still not functioning.. This is my first time posting in the forum, hope I didnt infringe on any rules.

OMG!! eye just realized that I'm not trying to modify an ORDER, I'm trying to modify a POSITION, hence I'm using PositionModify() now, and I haven't even compiled it yet, but I know that was the problem lol.. Thanks 4 solving your own problem, NasdaqDude 24!

 
Lmao I just searched up this error more than 20 months later and I just realized the same thing.. I'm using OrderModify Instead of PositionModify.. I'm so used to MQL4 that doesn't differentiate between orders and positions. Damn
Reason: