Error modify BUY/SELL order: 4202

 

Hello!

Can anyone tell me where is the problem? Thanks!

for(int cnt4=OrdersTotal()-1;cnt4>=0;cnt4--){ // I also try: for(int cnt4=0;cnt4<OrdersTotal(); cnt4++)
      OrderSelect(cnt4,SELECT_BY_POS,MODE_TRADES);
      if( (OrderType()<=OP_SELL) && (OrderSymbol()==Symbol()) ){
        if(OrderType()==OP_BUY){
            if(TS>0){
               if(Bid-OrderOpenPrice()>Point*(TS*places)){
                  if((OrderStopLoss()< (Bid-Point*(TS*places))) || (OrderStopLoss()==0)){
                     bool modi=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*(TS*places),0,0,Green);
                     return(0);
                  }
               }
               if (!modi){
                  Print("Error modify BUY order : ",GetLastError()); 
                  return(0); 
               }
            }
        }
        else{
          if(TS>0){
             if(OrderOpenPrice()-Ask > Point*(TS*places)){
                if((OrderStopLoss() > (Ask+Point*(TS*places))) || (OrderStopLoss()==0)){
                     modi=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*(TS*places),0,0,Red);
                     return(0);
                }
             }
             if (!modi){
                  Print("Error modify SELL order : ",GetLastError()); 
                  return(0); 
             }
          }
        }
     }
   }
 

Well i can spot 2 problems, but from your post it's unclear what the problem is you want solved.


 if(OrderType()==OP_BUY){
            if(TS>0){
               if(Bid-OrderOpenPrice()>Point*(TS*places)){
                  if((OrderStopLoss()< (Bid-Point*(TS*places))) || (OrderStopLoss()==0)){
                     bool modi=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*(TS*places),0,0,Green);
                     return(0);// you are returning here so not every open order will be updated -> use continue
                  }
               }
               if (!modi){//this will never execute since you're returning
                  Print("Error modify BUY order : ",GetLastError()); 
                  return(0); 
               }
            }
        }
hth
 
I tried without return in both places also, but still same error.
 

Error 4202 is related to Objects... It has nothing to do with OrderModify().

ERR_OBJECT_DOES_NOT_EXIST4202Object does not exist.
 

Yes, but if I delete this code then there is no error. I think problem is in this code because Print (...) is there and says "Error modify..."

 

*chuckles* those tricky bug reports catch me every time. Well at least the trailingstop function advanced a little o0

 
01005379:

Yes, but if I delete this code then there is no error. I think problem is in this code because Print (...) is there and says "Error modify..."

You should set the value of modi to a known state at the beginning of the loop and also call GetLastError() to clear the error buffer. That error probably originates somewhere else in your code...
 
Thanks! I found solution.
Reason: