positiveday: or the nearest bar shift depending on the
exact.
| Translation problem, reported 2013.05.23 iBarShift doesn't match documentation. - MQL4 forum |
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello, I've found a wrong response from IBarShift.
On the MQL4 user manual iBarShift reports :
"Returned value
Bar shift with the open time specified. If the bar having the specified open time is missing, the function will return -1 or the nearest bar shift depending on the exact. "
It writes the "nearest" bar.
Now the example.
I want to calculate offset D1 bars using H1 bars.
The only way to add 2 Hours offset to a Daily timeframe is to add 2 hours to D1 open times and get H1 bars in order to know OHLC of new offset/virtual bar.
//============================================================
// it's Monday 7 July 2003 at 02:00
datetime ThisBarTime = iTime( Symbol(), PERIOD_D1, 1 );
Print ("ThisBarTime A " + TimeToString(ThisBarTime));
The Print returns the Sunday bar open time, this because Sunday data are present and start from 21:00
>>> 2003.07.07 02:00 ThisBarTime A 2003.07.06 00:00
ThisBarTime += 7200; // add two hours offset
Print ("ThisBarTime B " + TimeToString(ThisBarTime));
New date is at 02:00 of Sunday
>>> 2003.07.07 02:00 ThisBarTime B 2003.07.06 02:00
Using iBarShift I want to get the NEAREST bar to 02:00 of Sunday, the nearest bar is the bar at 21:00 of Sunday
int SubTFStartBar = iBarShift( Symbol(), PERIOD_H1, ThisBarTime);
Print ("SubTFStartBar " + IntegerToString(SubTFStartBar) + " barTime " + TimeToString(iTime(Symbol(),PERIOD_H1,SubTFStartBar)));
This is the wrong result, the nearest bar is not the bar of Friday at 20:00, but the near bar on Sunday 21:00
>>> 2003.07.07 02:00 SubTFStartBar 6 barTime 2003.07.04 20:00
Another call to know the H1 end bar after 24 hours
int SubTFEndBar = iBarShift( Symbol(), PERIOD_H1, ThisBarTime + (PERIOD_D1 * 60) - (PERIOD_H1 * 60) );
Print ("SubTFEndBar " + IntegerToString(SubTFEndBar) + " barTime " + TimeToString(iTime(Symbol(),PERIOD_H1,SubTFEndBar)));
Correct response, for the end of the period.
>>> 2003.07.07 02:00 SubTFEndBar 1 barTime 2003.07.07 01:00
I know that I can substitute the iBarShift with a "while" cycle that search correctly what I want, but I don't understand why iBarShift don't return the correct bar number.