MT5 BUG with iBarShift?

 

Hi,

i really cannot understand why iBarShift is not working good in my code, it really seems an MT5 bug.

Here the code, very simple: 

Print("Symbols "+_Symbol+" - period: "+EnumToString(_Period)+" - Bars: "+iBars(_Symbol, _Period));
Print("shift 155 from W1: "+iBarShift(_Symbol,_Period, iTime(_Symbol,PERIOD_W1,155))+" - time bar: "+TimeToString(iTime(_Symbol,PERIOD_W1,155)) );
Print("shift 104 from MN1: "+iBarShift(_Symbol,_Period, iTime(_Symbol,PERIOD_MN1,104))+" - time bar: "+TimeToString(iTime(_Symbol,PERIOD_MN1,104)) );

Here the output:

2020.05.02 04:26:31.064	MyAutoLevels (EURJPY,W1)	Symbols EURJPY - period: PERIOD_W1 - Bars: 1391
2020.05.02 04:26:31.065	MyAutoLevels (EURJPY,W1)	shift 155 from W1: -1 - time bar: 2017.05.07 00:00
2020.05.02 04:26:31.065	MyAutoLevels (EURJPY,W1)	shift 104 from MN1: -1 - time bar: 2011.09.01 00:00

So, i really cannot understand where is the fault here, only a bug in MT5 could explain this!

Even in the same W1 TF, iBarShift cannot give me the right index!!!

2017.05.07 00:00 Bar is visible on the chart in W1 TF!!!

2011.09.01 00:00 Bar is not there in W1, but there is 2011.09.04 00:00, and its is visible and should be returned as index!


Help me please!

 

Is it on a live chart or with the Tester ?

Which MT5 build ?

 

Hi Alain

just tried your version too from here https://www.mql5.com/en/code/1864, but the result is the same, faulting. 

It is on live chart, build 2361.

iBarShift
iBarShift
  • www.mql5.com
But this function is not included in MQL5, mainly because MQL5 provides all necessary basic, low-level, functions to process such operation in a library. What I discovered, remarkably, is that all four versions are bugged, in the sense they don't reproduce exactly the MQL4 iBarShift(). Indeed, when the datetime given as input parameter, don't...
 

Working for me. Not sure what's happening on your side.

2020.05.02 00:09:33.630    339265 (EURJPY,W1)    Symbols EURJPY - period: PERIOD_W1 - Bars: 453
2020.05.02 00:09:33.630    339265 (EURJPY,W1)    shift 155 from W1: 155 - time bar: 2017.05.07 00:00
2020.05.02 00:09:33.630    339265 (EURJPY,W1)    shift 104 from MN1: 452 - time bar: 2011.09.01 00:00

 
Hi... Really i don't know what can be wrong on my side...
MT5 has really strange behaviour... If you tried same build how it is possible same code is working for you and not for me? 
Maybe a corrupeted history? Where i can delete it for this symbol? 
 

Hi... It looks like the history is not loaded
because according to doc => https://www.mql5.com/en/docs/series/ibarshift
"If such a bar is not found (history before the specified time is not available), then the function returns -1."

As a variants of solution =>
1> change time frames of the chart with your running program => D1 then W1 then MN1 then D1 again to force history loading
2> change server to obtain normal results

 
antony23:
Hi... Really i don't know what can be wrong on my side...
MT5 has really strange behaviour... If you tried same build how it is possible same code is working for you and not for me? 
Maybe a corrupeted history? Where i can delete it for this symbol? 
It's most probably an MT5 issue on week-end. I have other similar problems getting data with build 2361 but not with the last beta 2400 where all seems to work flawlessly (in that regards, as it's still a beta).
 

Hi,

i finally found the issue!


Before that lines of code, i call this:

iClose(Symbol(), PERIOD_W1, j)

I found out that at some point (inside a loop), j exceed iBars(Symbol(), PERIOD_W1)... and just after iBarShift does not work anymore, give me -1 all times!

So, i simply made this:

j<iBars(_Symbol,PERIOD_W1) && iClose(_Symbol, PERIOD_W1, j)

...and magically problem fixed!


I beleave this should not be a correct behaviour for iClose call, checking for index should be done inside the iClose. More, i cannot understand why wrong index in iClose should influence iBarShift call with correct index!

 
antony23:

Hi,

i finally found the issue!


Before that lines of code, i call this:

I found out that at some point (inside a loop), j exceed iBars(Symbol(), PERIOD_W1)... and just after iBarShift does not work anymore, give me -1 all times!

So, i simply made this:

...and magically problem fixed!


I beleave this should not be a correct behaviour for iClose call, checking for index should be done inside the iClose. More, i cannot understand why wrong index in iClose should influence iBarShift call with correct index!

Because it blocks the thread trying to get W1 data, as said previously it's an MT5 issue.

If you post me a small running code I can check it in the beta to say you if it's already solved or not.

 

Here, a stupid dummy code to show the issue:

   //iClose(_Symbol, _Period, iBars(_Symbol, _Period)-1);
   iClose(_Symbol, _Period, iBars(_Symbol, _Period));
   Print("iBarShift: "+iBarShift(_Symbol,_Period, iTime(_Symbol,_Period,1)));


iClose with iBars-1 (corrct index) is working good, iClose with iBars (wrong index) give -1 as result!

 
antony23:

Here, a stupid dummy code to show the issue:


iClose with iBars-1 (corrct index) is working good, iClose with iBars (wrong index) give -1 as result!

I don't have any problem with this, it always return 1 (Build 2361). Must be something else involved on your side.