iBarShift doesn't match documentation.

 

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.

int      iGetShift(datetime tm, int p=0){
   if(p == 0)  p = Period();
   //{ At https://forum.mql4.com/55743 I report that iBarShift doesn't match the
   // documentation. It returned bar 49 hours earlier instead of bar 1 hour
   //} later, (weekend gap.) This routine returns the nearest bar.
   int      iBar     = iBarShift(NULL, p, tm);  
   datetime barBeg   = iTime(NULL, p, iBar),
            barEnd   = barBeg + p * 60;         if(barEnd > tm)   return(iBar);
                                                if(iBar <= 0)     return(iBar);
   datetime nxtBeg   = iTime(NULL, p, iBar - 1);
   if( (tm - barEnd) > (nxtBeg - tm) ) iBar--;
   return(iBar);                                                              }
 
WHRoeder:

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.

Is this new with build 500 ?
 
I don't have a previous version to test. It may not be new, it could be translation problem of 'nearest'.
 
WHRoeder:
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

 
WHRoeder:
I don't have a previous version to test. It may not be new, it could be translation problem of 'nearest'.
Could well be,  it could be nearest in terms of bar number and not nearest in terms of datetime.
 
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.
 

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):

iBarShift test #1 

The older bar (relative to requested bar) could be the "next" bar that angevoyageur mentioned.

 
WHRoeder:
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.
LOL . . .  only if you consider the situation logically,  sorry,  I'll get my coat  
 

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*

 
Alekss Zukovskis #:

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
   );
Reason: