invalid ticket for ordermodify

 

i wrote this small EA to modify orders. everytime i launch it, the error "invalid ticket for ordermodify" pops up. can someone please guide me where am i going wrong. :( i am really not able to understand how to use the order select function. any insight would be helpful :)

extern int PipSL =  20;
extern int PipTP =  10;


int start()
  {
  

double SL;
double TP;
int pip = 0.0001;
if (Digits == 2 || Digits == 3) {pip = 0.01;}  
  
for(int i=OrdersTotal()-1;i>=0;i--)
   {
      OrderSelect(i, SELECT_BY_TICKET);
      if (OrderType()==OP_BUY) {
      SL = NormalizeDouble(OrderOpenPrice() - (PipSL * pip),Digits);
      TP = NormalizeDouble(OrderOpenPrice() + (PipTP * pip),Digits);
      OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Blue);}
      

      if (OrderType()==OP_SELL) {
      SL = NormalizeDouble(OrderOpenPrice()  + (PipSL * pip),Digits);
      TP = NormalizeDouble(OrderOpenPrice()  - (PipTP * pip),Digits);
      OrderModify(OrderTicket(),OrderOpenPrice(),SL,TP,0,Red);}  
   }
   return(0);
  }
 

https://book.mql4.com//

You're selecting by ticket but using index values.

Learn the basics, read the book.

 
cryptex:

i wrote this small EA to modify orders. everytime i launch it, the error "invalid ticket for ordermodify" pops up. can someone please guide me where am i going wrong. :( i am really not able to understand how to use the order select function. any insight would be helpful :)


Is i also your ticketnumber...... if you select by ticket

 
ubzen:

https://book.mql4.com//

You're selecting by ticket but using index values.

Learn the basics, read the book.


have read it quite a few times. i still dont understand how orderselect function works :(
 
cryptex:

have read it quite a few times. i still dont understand how orderselect function works :(


SELECT_BY_POS and... SELECT_BY_TICKET

check the differences using them