Cancelling BUYSTOP/SELLSTOP Orders

 

Thanks for everyones help in this forum so far its been amazing. 

MT4

Can anyone help me with my next mission. I have worked out how to code an EA with OP_BUYSTOP orders on my rules but if the trades are never triggered how do I cancel them after a certain amount of time. for example the next day. Thanks in advance

 
Adam Woods:

Thanks for everyones help in this forum so far its been amazing. 

MT4

Can anyone help me with my next mission. I have worked out how to code an EA with OP_BUYSTOP orders on my rules but if the trades are never triggered how do I cancel them after a certain amount of time. for example the next day. Thanks in advance

Try this ;)

int Expiration=12;//Expiration after xx hours
datetime expire=0;


expire=TimeCurrent()+Expiration*60*60;

ticket=OrderSend(Symbol(),OP_BUYSTOP,-,-,-,-,-,-,-,expire,Green);
 
If your broker allows expiration time (usually a min and max) then use it per Kenneth's post. Otherwise, remember the expiration time and when expired, delete the pending order.
Reason: