Make order expire after three candles

azromero
27

I would like to change my order time type to valid until next 3 candles from good until the end of day:

T.BuyLimit(LotSize, (ask-(45*_Point)), MySymbol, 0, 0, ORDER_TIME_DAY, Comments);

I tried this, but it didn't work:

T.BuyLimit(LotSize, (ask-(45*_Point)), MySymbol, 0, 0, ORDER_TIME_SPECIFIED, 3, Comments);

Does anybody knows how to do it? Thanks!

Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Order Properties - Trade Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Mahadi Hasan Razu
1650

You can add 3 candles time to your current candle time get your Custom Time for expiration. 


datetime OrderTimeSpecified = iTime(NULL,0,0) + (3*PeriodSeconds());
William Roeder
27845
William Roeder  
  1. Note that some brokers do not allow expiration time.

  2. There is no need to create pending orders in code.
    1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)
    2. Don't worry about it unless you're scalping M1 or trading news.
    3. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.
azromero
27
azromero  
Mahadi Hasan Razu #:

You can add 3 candles time to your current candle time get your Custom Time for expiration. 


Thank you for the solution!