# How to determine the first H4 bar of the day ?

100

Hi all, how can I determine the first H4 bar of the day ?

I'm trading on H4 timeframe and need to analyze some indicators at the first H4 bar of the day.

Help is appreciated.

JoDax.

1503

JoDax:

Hi all, how can I determine the first H4 bar of the day ?

I'm trading on H4 timeframe and need to analyze some indicators at the first H4 bar of the day.

Help is appreciated.

JoDax.

you must use PERIOD_H4  chart property in iTime function and specify a bar index

19170

JoDax: how can I determine the first H4 bar of the day ?

The time of the bar will be the same as the date.

`if( Time[i] == date(Time[i]) ) …`

The above fails on brokers that have a single 4 hour bar on Sunday.

`int i = iBarShift(_Symbol, _Period, date() );`
100

To be more specific, here's what I've tried:

1) I have the index (Idx) of the current H4 bar. In order to determine the start time of the current Day:

datetime v_StartDayTime = iTime(Symbol(), PERIOD_D1, Idx);

2) Now if I try to find the corresponding index of H4 bar for v_StartDayTime:

int v_Idx_H4 = iBarShift(Symbol(), PERIOD_H4, v_StartDayTime);

3) Print the Time[v_Idx_H4 ]  , but there's no H4 bar for this time

19170

JoDax: To be more specific, here's what I've tried:

1) I have the index (Idx) of the current H4 bar. In order to determine the start time of the current Day:

datetime v_StartDayTime = iTime(Symbol(), PERIOD_D1, Idx);

1. The index of the H4 bar can not be used as the index of the D1 bar. You are mixing apples and oranges.

2. On MT4: Unless the current chart is that specific pair/TF referenced, you must handle 4066/4073 errors before accessing candle values.
Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

The function linked to, opens a hidden chart for the symbol/TF in question (if not already open,) thus updating history, and temporarily placing the symbol on Market Watch (if not already there,) so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

100

You didn't answer my question: given a H4 candle how do I determine the first H4 candle of that day ?
19170

JoDax: You didn't answer my question: given a H4 candle how do I determine the first H4 candle of that day ?

I did answer that in #2 and gave two different solutions.

100

Thanks.