Set order to expire after 20 mins if the price is not hit

 

The following code works but the order is not canceled after the expiration.

datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_M20);

trade.BuyStop(0.10,Ask+100*_Point,_Symbol,buySl,Ask+300*_Point,ORDER_TIME_GTC,expiration,0);

I have defined by buySl as a variable and it gets set, how ever my time variable is like it's being ignored

 
Nickbahson:

The following code works but the order is not canceled after the expiration.

I have defined by buySl as a variable and it gets set, how ever my time variable is like it's being ignored


Of course not working, you using Order Time GTC option. Change it to Time Specified.

datetime expiration=TimeTradeServer()+PeriodSeconds(PERIOD_M20);

trade.BuyStop(0.10,Ask+100*_Point,_Symbol,buySl,Ask+300*_Point,ORDER_TIME_SPECIFIED,expiration,0);