calculate time of 10th next candles

 

Hi

how can i get the time of 10th candle later on H1 timeframe?

 
mohsen bahrami:

Hi

how can i get the time of 10th candle later on H1 timeframe?

datetime TimeCurrentPlusTenCandleOfOneHour = TimeCurrent() + (10 * 3600);
 
mohsen bahrami:

Hi

how can i get the time of 10th candle later on H1 timeframe?

You can't for certain as there may be missing bars (weekend or the symbol is not traded 24 hours per day) unless there are already 10 bars formed after the point that you are checking.

You can check back and see if the current bar is the tenth bar after a certain point.

 
   datetime nowH1 = TimeCurrent(); nowH1 -= nowH1 % PeriodSeconds(PERIOD_H1);
datetime TimeCurrentPlusTenCandleOfOneHour = nowH1 + (10 * 3600);
This assumes every bar every exists. 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
          No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum
 
whroeder1:
This assumes every bar every exists. 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
          No candle if open = close ? - MQL4 and MetaTrader 4 - MQL4 programming forum

thanks alot

 
datetime Next_10_Candle = TimeSeconds() + ( 10 * 3600 );
 

datetime Next_10_Candle = PERIOD_M1 + ( 10 * 60 );

datetime Next_10_Candle = PERIOD_H1 + ( 10 * 1 );

or

datetime Next_10_Candle = PERIOD_M1 + ( 600 * PERIOD_M1 );

datetime Next_10_Candle = PERIOD_H1 + ( 10 * PERIOD_H1 );

TRY.

 
Krzysztof Lippok #:
datetime Next_10_Candle = TimeSeconds() + ( 10 * 3600 );

TimeSeconds() only exists in MQL4 and it needs a datetime parameter.

Anyway it is not suitable for the OP's requirements as your code will return a time at 10 AM on 1st January 1970.

 
Krzysztof Lippok #:

datetime Next_10_Candle = PERIOD_M1 + ( 10 * 60 );

datetime Next_10_Candle = PERIOD_H1 + ( 10 * 1 );

or

datetime Next_10_Candle = PERIOD_M1 + ( 600 * PERIOD_M1 );

datetime Next_10_Candle = PERIOD_H1 + ( 10 * PERIOD_H1 );

TRY.

I have no idea what you are trying to achieve here!

PERIOD_M1 etc. are enumerations, they are not datetime.