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.
you must use PERIOD_H4 chart property in iTime function and specify a bar index
The time of the bar will be the same as the date.
if( Time[i] == date(Time[i]) ) …
Find bar of the same time
one day ago - Simple Trading Strategies - MQL4 programming forum
The above fails on brokers that have a single 4 hour bar on Sunday.
int i = iBarShift(_Symbol, _Period, date() );
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
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
or MarketInfo(symbol, MODE_BID)
don't also return zero on the first call.
I did answer that in #2 and gave two