Pending Order Expire

 

Hey,

I'm trying to figure out how to set an expire time for a pending order.  So far that part of my code looks like this:

   CTrade trade;
   trade.SetExpertMagicNumber(MagicNr);
   trade.SetDeviationInPoints(Slippage*z);
   
   if (PositionsTotal() || OrdersTotal() != 0) {return;}
   
   
   if (GetSignal() == LONG)
   {
   
      OrderPrice = iLow(_Symbol,_Period,iLowest(_Symbol,_Period,MODE_LOW,Donchian,0)) + 5*_Point*z; //iLow and iLowest are functions from an included file
      SL = OrderPrice - SLPips*z*_Point;
      TP = OrderPrice + RRR*SLPips*_Point*z;
      expire = TimeCurrent() + 3600*2;
      trade.BuyLimit(lot,OrderPrice,_Symbol,SL,TP,0,expire);

   
   }
   
   if (GetSignal() == SHORT)
   {
   
      OrderPrice = iHigh(_Symbol,_Period,iHighest(_Symbol,_Period,MODE_HIGH,Donchian,0)) - 5*_Point*z; //iHigh and iHighest are functions from an included file
      SL = OrderPrice + SLPips*z*_Point;
      TP = OrderPrice - RRR*SLPips*_Point*z;
      expire = TimeCurrent() + 3600*2;
      trade.SellLimit(lot,OrderPrice,_Symbol,SL,TP,0,expire);
   
   }
   

 To my knowledge the expiry date is set at two hours from now.  But it does not work the orders won't expire.

Any help will be appreciated.

Thanks! 

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
 
Saidar:

Hey,

I'm trying to figure out how to set an expire time for a pending order.  So far that part of my code looks like this:

 To my knowledge the expiry date is set at two hours from now.  But it does not work the orders won't expire.

Any help will be appreciated.

Thanks! 

 trade.SellLimit(lot,OrderPrice,_Symbol,SL,TP,ORDER_TIME_SPECIFIED,expire);
 
This is what jshumaker mean : ORDER_TIME_SPECIFIED (click that). Sometime brokers don't accept expiration date, so be prepare to check the trade result for an error and prepare to delete the order as well.
Reason: