Frustrated! Why do I get a 130 error when all prices are correct?

 

I seem to randomly get 130 errors when doing an OrderModify but the SL/TP levels are absolutely correct. Anybody have any ideas why?


This is so frustrating and I can’t see what else I can do with my code to fix it?


Here’s the snippet of code that is generating the error



bool ModOrder(int ticket, int ordno)
{

   double newstop = TrailStop(OrderType());
   newstop = NormalizeDouble(newstop,Digits);

   bool ok = true;
      
   double origstop = NormalizeDouble(OrderStopLoss(),Digits);
   double origtgt = NormalizeDouble(OrderTakeProfit(),Digits);

   double newtgt = NormalizeDouble(S_TGT,Digits);    
   
   if (newstop != origstop || newtgt != origtgt) // Modify SL or TP if either have changed
   {
      ok = OrderModify(ticket,OrderOpenPrice(),newstop,newtgt,0,White);

          if (!ok) {
                int err=GetLastError();
                string mess = "***ERROR*** Could not modify Trailing Stop on Order "+ticket+", Orig Stop="+ OrderStopLoss()+", New Stop="+ newstop+", New TGT="+ newtgt+", Error="+ err;
                Msg(mess);
          }
   }
   
   return(ok);
}

 
Recently I got Error 130 for something unrelated to stops.. I'll check it again and get back to you.
 
Freefox:

I seem to randomly get 130 errors when doing an OrderModify but the SL/TP levels are absolutely correct. Anybody have any ideas why?

This is so frustrating and I can’t see what else I can do with my code to fix it?

Here’s the snippet of code that is generating the error

I don't see where you are checking that the SL & TP are correct ?  they need to comply with what is written here:  Requirements and Limitations in Making Trades    what is your MODE_STOPLEVEL  ?   what are the Bid and Ask when your Modification fails ?