Getting OrderModify Error 1 Although The Order Was Modified Successfully

 

Hey Guys!

In my backtest result, the order was modified successfully by changing the SL at the Order Open Price upon reaching 80% of total profit (Break Even). However, I still received the OrderModify Error 1 message.

    if(pip_Diff < 0.00400)
    {
      BuyOrder();
      SellOrder();
      
      for(int i=0; i<OrdersTotal(); i++)      
      if(OrderSelect(BuyTicket, SELECT_BY_TICKET)==True)  
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_BUY && OrdersTotal() == 1)
         {
            if(OrderProfit() >= lot*722*0.8 && OrderProfit() <= lot*722*1)
            {
               OrderModify(BuyTicket, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(x, Digits), NormalizeDouble(OrderTakeProfit(), Digits), 0, clrNONE);
            }
         }
         
      }
  
      for(int i=0; i<OrdersTotal(); i++)      
      if(OrderSelect(SellTicket, SELECT_BY_TICKET)==True)  
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL && OrdersTotal() == 1)
         {
            if(OrderProfit() >= lot*722*0.8 && OrderProfit() <= lot*722*1)
            {
               OrderModify(SellTicket, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(y, Digits), NormalizeDouble(OrderTakeProfit(), Digits), 0, clrNONE);
            }
         }
         
      }      
    }

The TP value does not change, only changed the SL value. Still, getting the Error 1.

 
      for(int i=0; i<OrdersTotal(); i++)      
      if(OrderSelect(BuyTicket, SELECT_BY_TICKET)==True)  

Why are you looping using OrdersTotal() when you are modifying the same ticket number?

If there are n orders open, you will try to modify the same ticket n times!

 
Keith Watford:

Why are you looping using OrdersTotal() when you are modifying the same ticket number?

If there are n orders open, you will try to modify the same ticket n times!

I removed the loop and tried again, but still getting the same error.
 
Gary:
I removed the loop and tried again, but still getting the same error.

Are you checking that the order has not already been modified?
You will get an error if you are trying to modify an order with the same values.

 
Keith Watford:

Are you checking that the order has not already been modified?
You will get an error if you are trying to modify an order with the same values.

The SL was set at 200 pips

if(NormalizeDouble(Bid, 5) <=  NormalizeDouble(y-1000*_Point, 5) && Total == 0 && Orders_Per_Day == False && Hour() > 0 && DayOfWeek() >= 1 && DayOfWeek() <= 5)
{
   Print("SELL BIG");
   SellTicket = OrderSend(Symbol(), OP_SELLLIMIT, lot, y, 0, y+2000*_Point, y-1000*_Point, NULL, Magic, 0, clrRed); 
} 
The order has still been modified according the my trading rule, which is moving the SL to Order Open Price upon reaching 80% profit. I just want to modify the order once, to get the order break even.
for(int i=0; i<OrdersTotal(); i++)      
      if(OrderSelect(SellTicket, SELECT_BY_TICKET)==True)  
      {
         if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == OP_SELL && OrdersTotal() == 1)
         {
            if(OrderProfit() >= lot*722*0.8 && OrderProfit() <= lot*722*1)
            {
               OrderModify(SellTicket, NormalizeDouble(OrderOpenPrice(), Digits), NormalizeDouble(y, Digits), NormalizeDouble(OrderTakeProfit(), Digits), 0, clrNONE);
            }
         }
         
      }      

The value y is my Order Open Price

 
Keith Watford:

Are you checking that the order has not already been modified?
You will get an error if you are trying to modify an order with the same values.

So the SL initially was set at 200 pips. As shown in the code above, I'm modifying the SL back to the Order Open Price (y). Therefore, the only value changed is the SL. The order was modified successfully in backtesting, just that I don't know why am I still getting the error.
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
Calculations of technical indicators require price values and/or values of volumes, on which calculations will be performed. There are 7 predefined identifiers from the ENUM_APPLIED_PRICE enumeration, used to specify the desired price base for calculations. If a technical indicator uses for calculations price data, type of which is set by...
 

What I found out is the order was modified at 11:45 and TP at 13:14. 


And I received the error at 13:12.

So, if that is what you meant before. If the order has been modified for the first time, in this case, at 11:45. And the EA attempts to modify again (with the same value) at 13:12. That's why I received Error 1 message right?

Files:
1.PNG  9 kb
Capture.PNG  19 kb
Reason: