Again OrderModify Error 130 and sometimes 1

 

Hi,

I can't understand, what I am doing wrong!

First I send an order without TP and SL.

After that I use this function:

void Order_modify()
  {
   double spread = Ask-Bid;
   
   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(OrderStopLoss()!=0)  return;
           {
            if(OrderType()==OP_BUY)
              {
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-PointX()*Long_SL-spread,OrderOpenPrice()+PointX()*Long_TP,0,Blue);
              }  
            if(OrderType()==OP_SELL)
              {
               OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+PointX()*Short_SL+spread,OrderOpenPrice()-PointX()*Short_TP,0,Blue);
              }
           }
        }
     }    
   return;          
  }
An when I open my backtest, it works nearly all the time but sometimes it happens like at the following screenshot an I become the OrderModify Error 130! First Screenhot is at H4 (like the EA is working) the second Screenhot is zoomed at M15.
[Deleted]  

You have to check if the new value of SL and TP are different from the older before OrderModify to avoid error.

 

Hi,

I want to use the

Order_modify()

function in my post above. It doesn't work when I have many orders open and the order on the first position has changed the SL and TP

because of this line

         if(OrderStopLoss()!=0)  return;


so I tought...

but the strange thing is, that I get for every order than the first one an order error 130.


Can anybody tell me how I have to change this function for a multiordersystem??

 
What is the value of PointX()*Long_SL-spread ? does OrderOpenPrice()-PointX()*Long_SL-spread need to be Normalized ? are you on a 4 or 5 digit broker ? if 5 digit have you taken this into account ?
 
  1. it does NOT need to be normalized, normalize is never needed. What is PointX()*long_SL-spread? It must be larger than MarketInfo(Symbol(), MODE_STOPLEVEL)*Point (3 pips or 30 points on IBFX)
  2. for(int i=0;i<=OrdersTotal();i++)
         {
          if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
    i==OrdersTotal will always fail, drop the =. You must count down when closing/deleting or in the presence of multiple orders and other EAs on other charts. Simplify and use positive logic.
        for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if (
            OrderSelect(pos, SELECT_BY_POS)                 // Only my orders w/
        &&  OrderMagicNumber()  == magic.number             // my magic number
        &&  OrderSymbol()       == Symbol() ){              // and my pair.
    
  3. if(OrderStopLoss()!=0)  return;
    make the EA incompatible with multiple orders