IBarShift error

 

iBarShift does not seem to work properly with build 840.

I never see 1440 bars in a 1 day period using M1 timeframe.

I've seen a limitation on 1000 bars in the past and than things go wrong.

Is this a know bug ?


I've also added a list with the log-file.


Here's the code :

 previousday_start = iTime(NULL,PERIOD_D1,i);
 previousday_end   = previousday_start + 24*60*60 -60;
 
 start_bar = iBarShift(NULL,PERIOD_M1,previousday_start);
 end_bar   = iBarShift(NULL,PERIOD_M1,previousday_end);
 
 
 // ***** ONLY FOR TEST *****
 datetime testtime;
 int currentbar=0;
 int end = end_bar+1440;
 Log("end_bar = " + end_bar + "start_bar = " + start_bar);
 
 for (i= end_bar; i< end; i++)
 {
  testtime = iTime(NULL, PERIOD_M1, i);
  currentbar = iBarShift(NULL,PERIOD_M1,testtime);
  Log( "i = " + i + " Time = " + TimeToStr(testtime,TIME_DATE|TIME_SECONDS) + "  BarNr = " + currentbar);
 }
 Log ("end of cycle");
 // ***** ONLY FOR TEST TILL HERE *****

Files:
 
Danny_pip: I never see 1440 bars in a 1 day period using M1 timeframe.
  1. Don't paste code
    Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. Expected. If there is no tick in a minute, there will not be a M1 bar. "Free-of-Holes" Charts - MQL4 Articles
 

I believe you don't understand the problem WHRoeder; In one day there are 1440 minutes; every minute has a barnumber that should be able to be reached with iBarShift to find back the exact bar corresponding with that time.

 
Danny_pip:

I believe you don't understand the problem WHRoeder; In one day there are 1440 minutes; every minute has a barnumber that should be able to be reached with iBarShift to find back the exact bar corresponding with that time.

What about minutes at weekend? 
 

Danny_pip:

In one day there are 1440 minutes;

every minute has a barnumber

that should be able to be reached

Irrelevant.

Wrong

And wrong. No tick that minute, no bar for that minute. No minute bars over the week end either. Did you bother to read the article I linked to? What part of "holes" was unclear?



 
WHRoeder:

Irrelevant.

Wrong

And wrong. No tick that minute, no bar for that minute. No minute bars over the week end either. Did you bother to read the article I linked to? What part of "holes" was unclear?

The problem is that it's systematically showing up every day; even if there are ticks for that minute; do the test yourself ! This function does not work properly.
 
No, you prove it. Take your time, get your shift, print the shift and time of that shift and the time of the next bar. Show your code and your result.
 
Danny_pip:
The problem is that it's systematically showing up every day; even if there are ticks for that minute; do the test yourself ! This function does not work properly.
This function is working as expected. MT4 doesn't draw a bar if there is no tick, on M1 timeframe there is ALWAYS missing bars.
 

The 1000 bar limitation is still there. Whenever I attempt to get the bar index of a time that's way past the 1000th bar on the current chart (M1 in my case, but I definitely have more than enough history data), iBarShift returns 1000 bars.

@Danny_Pip said this is a past issue. Was there a fix at any point or is this something we'll never get through with?


 
Filip Pop:

The 1000 bar limitation is still there. Whenever I attempt to get the bar index of a time that's way past the 1000th bar on the current chart (M1 in my case, but I definitely have more than enough history data), iBarShift returns 1000 bars.

@Danny_Pip said this is a past issue. Was there a fix at any point or is this something we'll never get through with?


There is no such limitation.

Must be a specific issue, depending on your settings, data and code.

 
Alain Verleyen:

There is no such limitation.

Must be a specific issue, depending on your settings, data and code.


There sure appears to be one, I've replicated and reduced the problem to this - when trying to get the index of the bar that is more than 1000 bars behind the point where the test started in Strategy tester, iBarShift will erroneously return 1000 - that is the maximum, even if you have data past that. The next bar you'll have available 10001 bars back, still 1000 bars prior to the test start.


The Strategy Tester seems to have a blind spot for time and price data (on any TF) that is more than 1000 bars behind the start of the backtest. The iTime() function also seems to be messed up in a similar way.

You can replicate the bug like I did (with 2 different brokers) by printing this inside OnTick() and/or OnInit():

   Print("999 TEST: "+iTime(Symbol(),Period(),999)+" "+iBarShift(Symbol(),Period(),iTime(Symbol(),Period(),999)));
   Print("1000 TEST: "+iTime(Symbol(),Period(),1000)+" "+iBarShift(Symbol(),Period(),iTime(Symbol(),Period(),1000)));
   Print("1001 TEST: "+iTime(Symbol(),Period(),1001)+" "+iBarShift(Symbol(),Period(),iTime(Symbol(),Period(),1001)));

What you'll then get in the logs is this:


2017.04.21 00:11:25.591 2017.04.12 00:10:00  Test EURUSD,M5: 1001 TEST: 2017.04.06 12:15:00 1001

2017.04.21 00:11:25.591 2017.04.12 00:10:00  Test EURUSD,M5: 1000 TEST: 2017.04.06 12:20:00 1000

2017.04.21 00:11:25.591 2017.04.12 00:10:00  Test EURUSD,M5: 999 TEST: 2017.04.06 12:25:00 999

2017.04.21 00:11:25.591 2017.04.12 00:10:00  Test EURUSD,M5: On Tick                                                          - 3rd candle, here it has 1001 bars back


2017.04.21 00:11:25.327 2017.04.12 00:05:00  Test EURUSD,M5: 1001 TEST: 2017.04.06 12:10:00 1001

2017.04.21 00:11:25.327 2017.04.12 00:05:00  Test EURUSD,M5: 1000 TEST: 2017.04.06 12:15:00 1000

2017.04.21 00:11:25.327 2017.04.12 00:05:00  Test EURUSD,M5: 999 TEST: 2017.04.06 12:20:00 999

2017.04.21 00:11:25.327 2017.04.12 00:05:00  Test EURUSD,M5: On Tick                                                                                   - I test with Open Prices Only, so this is 2nd candle - here it has 1001 bars back


2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 1001 TEST: 1970.01.01 00:00:00 1000                         - 1st tick, 1st candle - same issue

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 1000 TEST: 2017.04.06 12:10:00 1000

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 999 TEST: 2017.04.06 12:15:00 999

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: On Tick


2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 1001 TEST: 1970.01.01 00:00:00 1000                                         - logs show MT4 failing to get the time and index of the bar with index 1001 inside OnInit

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 1000 TEST: 2017.04.06 12:10:00 1000

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: 999 TEST: 2017.04.06 12:15:00 999

2017.04.21 00:11:23.245 2017.04.12 00:00:00  Test EURUSD,M5: On Init                    


If you think this 1000 limitation is due to any settings, then please share your secret with us.