Error 1 and I don't know why

 

Hi,

I want to change the TakeProfit of an existing order.

But I am getting always the "OrderModify error 1"

Here is a part of my code:

   for(int i=0;i<=OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderSymbol()!=Symbol())  continue;
      if(OrderMagicNumber()!=MagicNumber)  continue;  
        {
            if(OrderType()==OP_BUY)
              {
               if(OrderStopLoss() == 0)
                 OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-PointX()*SL-spread,OrderOpenPrice()+PointX()*TP,0,Yellow);
               if(OrderStopLoss() != 0)
                 OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),GlobalVariableGet("TPPreis"+MagicNumber)+PointX()*TP,0,Yellow);
              
              }  
            if(OrderType()==OP_SELL)
              {
               if(OrderStopLoss() == 0)
                 OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+PointX()*SL+spread,OrderOpenPrice()-PointX()*TP,0,Yellow);
               if(OrderStopLoss() != 0)
                 {
                 OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),GlobalVariableGet("TPPreis"+MagicNumber)-PointX()*TP,0,Yellow); 
                 }
              }
        }
     }    
It works, but how can I prevent the error-message?
 

Hi,

Try to normalize price values.

For example, Position Management Module 7.6 of AIS2 Trading Robot is totally free of these messages.

Exactly, lines 491 and 494 prevent from the order modification message 1:

...     
//< 7.6.3. Order Modify Trading Function 28 >                                                                 //< 490>
         if ( avd.Stop                > 0 )                                                                   //< 491>
            { int  ali.TrailPoints    = MathRound       (    MathAbs       ( OrderStopLoss ()  - avd.Stop )   //< 492>
                                                                           / avd.QuotePoint               ) ; //< 493>
              if ( ali.TrailPoints   >= MarketInfo      (    aes.Symbol    , MODE_FREEZELEVEL           ) )   //< 494>
                 {                                                                                            //< 495>
               //< Trading Function Execution Sequence >                                                      //< 496>
               //< Step 1 >                                                                                   //< 497>
... 
  

Thanks to Gordon.

Best regards

 
sunshineh:

Hi,

I want to change the TakeProfit of an existing order.

But I am getting always the "OrderModify error 1"

Here is a part of my code:

It works, but how can I prevent the error-message?

This error might also happen if your OrderModify() is attempting to change s/l or t/p with the same value they already have. So make sure that can't happen in your GlobalVariableGet() method of setting s/l and t/p.

Reason: