Download MetaTrader 5

Libraries: iBarShift - page 2

To add comments, please log in or register
Alain Verleyen
Moderator
33799
Alain Verleyen  
RaptorUK:

Yes,  the Russian translated via Google tells a different story . . .

 . . .  it's not about the Open time but about the time being within the life of a bar . . .

Yes, so my version works as Russian documentation. Have you reported this translation error to Service Desk ?
Simon Gniadkowski
Moderator
18046
Simon Gniadkowski  
angevoyageur:
Yes, so my version works as Russian documentation. Have you reported this translation error to Service Desk ?
Nope.
Alain Verleyen
Moderator
33799
Alain Verleyen  
RaptorUK:
Nope.
Done.
Simon Gniadkowski
Moderator
18046
Simon Gniadkowski  
angevoyageur:
Done.
Thank you 
Alain Verleyen
Moderator
33799
Alain Verleyen  
Build 880 fix the bug on Bars(), and all is working well now.
Pasi Hakamaki
7322
Pasi Hakamaki  
angevoyageur:
Build 880 fix the bug on Bars(), and all is working well now.
Carl Schreiber
7673
Carl Schreiber  

I think there is a minor bug in your code:

//--- if time > LastBar we always return 0
   if(time>LastBar)
      return(0);

If the the last tick 'opens' a new bar then if(time>LastBar) becomes false - because now time == LastBar

And later we land here:

 if(checkcandle[0]==time)
         return(shift-1);

And now shift == 0 which returns -1 instead of 0!

So I think this:

//--- if time > LastBar we always return 0
   if(time>LastBar)
      return(0);

should be changed to

//--- if time > LastBar we always return 0
   if(time>=LastBar)
      return(0);

Calli

Alain Verleyen
Moderator
33799
Alain Verleyen  
Carl Schreiber:

I think there is a minor bug in your code:

If the the last tick 'opens' a new bar then if(time>LastBar) becomes false - because now time == LastBar

Not sure what you mean ? I think 'last tick' is irrelevant. When you use the function either time=LastBar or not.

And later we land here:

And now shift == 0 which returns -1 instead of 0!

if time==Lastbar then shift=1  and not 0. So there is no bug (shift comes from Bars() which is the bars count, that's why we return 'shift-1').

So I think this:

should be changed to

Calli

Your correction would work too, but the case 'time==LastBar' is processed as a "normal" case.

The statement

 if(time>LastBar)

was added as a bug fix if time is greater than current bar 0 time.

Carl Schreiber
7673
Carl Schreiber  

Check it yourself (in mt4).

start it on a e.g. m5 chart. The script stops if your function (I renamed it to iBarShift_MQ5) returns an index less than 0.

I changed the returned negative values in order to know from where the negative index was returned (could have used e.g. __LINE__ as well).

Files:
Alain Verleyen
Moderator
33799
Alain Verleyen  
Carl Schreiber:

Check it yourself (in mt4).

start it on a e.g. m5 chart. The script stops if your function (I renamed it to iBarShift_MQ5) returns an index less than 0.

I changed the returned negative values in order to know from where the negative index was returned (could have used e.g. __LINE__ as well).

?

This is a code for mql5/MT5. No point to use it under mql4/MT4.

123
To add comments, please log in or register