Closing a trade after specific number of candles

 
hello
can anyone help me in editing an mlq5 code where an open trade will close after a number of candles,as an input...and all trades to close after the daily target is reached. thanks
 
  1. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help (2017)

  2. Read the time the trade opened. IBarShift will tell you the number of candles. What's the problem?

 
GERALD MALESELA MATLOGA:
hello
can anyone help me in editing an mlq5 code where an open trade will close after a number of candles,as an input...and all trades to close after the daily target is reached. thanks

Convert the numbers of bars in seconds:

datetime tCls = tPosOpen + (datetime)(NoBars*PeriodSeconds(_Period));

(Not tested!!)

 
Carl Schreiber #:
datetime tCls = tPosOpen + (datetime)(NoBars*PeriodSeconds(_Period));

That assumes that all bars exist — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
          "Free-of-Holes" Charts - MQL4 Articles (2006)
          No candle if open = close ? - MQL4 programming forum (2010)

Use iBarShift.

 
William Roeder #:

That assumes that all bars exist — they don't. What if there are no ticks during a specific candle period? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific), requires knowledge of when your broker stops and starts (not necessary the same as the market.)
          "Free-of-Holes" Charts - MQL4 Articles (2006)
          No candle if open = close ? - MQL4 programming forum (2010)

Use iBarShift.

Well I assumed that the number of bars is known the moment the position is opened.

BTW, do you remember the none-official parameter to get the initial deposit and/or money transfers. If my memory does not deceive me, there was/is at least this for MQL4.

 
Carl Schreiber #:

Well I assumed that the number of bars is known the moment the position is opened.

BTW, do you remember the none-official parameter to get the initial deposit and/or money transfers. If my memory does not deceive me, there was/is at least this for MQL4.

If I remember correctly, in MQL4, In history the deposits are OrderType 6.

 

Do not assume history has only closed orders.
          OrderType() == 6, 7 in the history pool? - MQL4 programming forum (2017)

Reason: