iBarShift - MQL4 Documentation states that when a match is not found it returns the nearest (exact == false).
In tester (Build 500) on M15 bar <2001.02.19 01:30>, iBarShift returned 11, for a request of <2001.02.18 22:00>
Time[11] = <2001.02.16 21:00> 49 hours earlier - Last bar before market close in my history.
Time[10] = <2001.02.18 23:00> 1 hour after request - market open bar.
The nearest bar in time is 10 not 11.
I don't have a previous version to test. It may not be new, it could be translation problem of 'nearest'.
When I used google translate on Russian documentation it returns :
FALSE - iBarShift returns next
I don't have a previous version to test. It may not be new, it could be translation problem of 'nearest'.
The term "nearest" does seem to refer to time, but it appears that iBarShift() returns the older bar (relative to requested bar) rather than the newer bar.
For example, the following code
datetime date1 = D'2013.05.18 01:00'; datetime date2 = D'2013.05.19 22:00'; datetime date3 = D'2013.05.20 00:59'; int shift_for_date1 = iBarShift(Symbol(), PERIOD_H1, date1); int shift_for_date2 = iBarShift(Symbol(), PERIOD_H1, date2); int shift_for_date3 = iBarShift(Symbol(), PERIOD_H1, date3); Print ("iBarshift for date1 returns bar with date: ", TimeToStr(iTime(Symbol(), PERIOD_H1, shift_for_date1), TIME_DATE|TIME_MINUTES)); Print ("iBarshift for date2 returns bar with date: ", TimeToStr(iTime(Symbol(), PERIOD_H1, shift_for_date2), TIME_DATE|TIME_MINUTES)); Print ("iBarshift for date3 returns bar with date: ", TimeToStr(iTime(Symbol(), PERIOD_H1, shift_for_date3), TIME_DATE|TIME_MINUTES));
produced the following results in the log (on build 427):
The older bar (relative to requested bar) could be the "next" bar that angevoyageur mentioned.
If the requested bar doesn't exist then there's only the one before and the one after - no nearest in terms of bar numbers. Nearest can only be in terms of time.

i have the same problem with "iMA" now
it states in documentation that it takes in 7 inputs, but lo' and behold! its actually 6 now!
they removed the "shift" and i needed it so much *angery*
i have the same problem with "iMA" now
it states in documentation that it takes in 7 inputs, but lo' and behold! its actually 6 now!
they removed the "shift" and i needed it so much *angery*
That's not what the documentation states. iMA - Technical Indicators - MQL4 Reference
double iMA( string symbol, // symbol int timeframe, // timeframe int ma_period, // MA averaging period int ma_shift, // MA shift int ma_method, // averaging method int applied_price, // applied price int shift // shift );

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
iBarShift - MQL4 Documentation states that when a match is not found it returns the nearest (exact == false).
In tester (Build 500) on M15 bar <2001.02.19 01:30>, iBarShift returned 11, for a request of <2001.02.18 22:00>
Time[11] = <2001.02.16 21:00> 49 hours earlier - Last bar before market close in my history.
Time[10] = <2001.02.18 23:00> 1 hour after request - market open bar.
The nearest bar in time is 10 not 11.