The idea of this function is to delete the pending order if not executed in 290 seconds from the time order is placed. However, at 290 seconds the order is NOT being deleted. It takes an extra 10 to 20 seconds for the order to delete and I have no idea why. Can you please look into this code and help me fix it. Thanks in advance.
Inserted Code
extern int OrderKillInSeconds = 290; int buyv,cmd,totalp; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { Del(); Other conditions to buy and sell goes here } //+------------------------------------------------------------------+ /* Delete Pending Orders - Kill Order in seconds */ bool Del() { //---- totalp=OrdersTotal(); //---- for(int i=0; i<totalp; i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) { cmd=OrderType(); buyv = TimeCurrent() - OrderOpenTime(); //---- pending orders only are considered if((cmd!=OP_BUY && cmd!=OP_SELL) && (buyv > Minute() + OrderKillInSeconds) ) { //---- print selected order OrderPrint(); //---- delete first pending order result=OrderDelete(OrderTicket()); if(result!=TRUE) Print("LastError = ", GetLastError()); break; } } else { Print( "Error when order select ", GetLastError()); break; } } //---- return(0); } /* Delete Pending Orders */