iBarShift Issue

 

I've create a loop that calculates a previous date and then the iBarShift from this, but it doesn't seem to work) what am I missing?

   for(int r = 0; r <= 150; r++)
   {
      datetime AfterMidnight = StrToTime("00:00")  - (3600 * 24 * r);
      int MidnightShift = iBarShift(NULL, 60, AfterMidnight);

      
      Print("Loop : " + IntegerToString(r)
            + " : Shift : " + IntegerToString(MidnightShift)
            + " : Date : " + TimeToStr(AfterMidnight)
            );
   } 

The result seem to stop working/repeat after a certain limit... I'm not missing any candle data (downloaded from TickStory - no issues)


Yet went it shifts bar from a different date it works (implying data there for that candle).... although this one repeats after 1549

But some of them (from different starting points) work well into the 1000s of candle shifts rather than maxing out

 
iRick:

I've create a loop that calculates a previous date and then the iBarShift from this, but it doesn't seem to work) what am I missing?

The result seem to stop working/repeat after a certain limit... I'm not missing any candle data (downloaded from TickStory - no issues)


Yet went it shifts bar from a different date it works (implying data there for that candle).... although this one repeats after 1549

But some of them (from different starting points) work well into the 1000s of candle shifts rather than maxing out

try this

   int Bar = iBars(_Symbol,_Period);
   for(int r = 0; r <= Bar; r++)
 
Abubakar Saidu:

try this

The problem isn’t with the loop, changing the loop end won’t fix the issue
 
iRick:

I've create a loop that calculates a previous date and then the iBarShift from this, but it doesn't seem to work) what am I missing?

You are trying to get the shift of a bar that does not exist, so it returns the highest bar index.

The strategy tester starts with 1000 bars history.

 
Keith Watford:

You are trying to get the shift of a bar that does not exist, so it returns the highest bar index.

The strategy tester starts with 1000 bars history.

I have Tickstory data for 2005-2019 so the bar should exist, you can also see from the second screen shot it returning the correct bar shift from a different starting point for the same dates, backing up that the bar exists... I’m also seeing it work for bar shifts in the 10,000s.... but intermittently when I set this loop on a weekly basis in StrategyTester it’ll max out at varying points
 
Keith Watford:

You are trying to get the shift of a bar that does not exist, so it returns the highest bar index.

The strategy tester starts with 1000 bars history.

ahhhh, I see, from the start date it can only go back 1000 bars, but once it moves through it can go back further

So instead of testing from say 2010-01-01, I'd start from 2009-07-01 and set the EA to not trade until 2010 so that the strategy tester will have enough bar shift history avaiable

 
iRick:

ahhhh, I see, from the start date it can only go back 1000 bars, but once it moves through it can go back further

So instead of testing from say 2010-01-01, I'd start from 2009-07-01 and set the EA to not trade until 2010 so that the strategy tester will have enough bar shift history avaiable

That's it.