Issue back testing with iBarShift()

 

Hi all,

when back testing my EA I have an issue with the iBarShift() function.

I am trying to find the bar number based on a time.

- I find for example the highest high - int i=iHighest(NULL,0,MODE_HIGH,10,1)

- I then want to find out what bar the shift is on so try, for example int Bar=iBarShift(NULL,0,Time[i]);

- This returns -1 as the bar is not found (int Bar=iBarShift(NULL,0,Time[0]); is also not found).

- I only use iBarShift() because Bars-i doesn't work either.

- Print (Bars); at the start of my EA gives me 1001 - altough Time[0] gives me the specified start date (for example 01.12.2010) and I can draw a VLINE on the chart to show the start of my testing.

- As Bars is 1001, the EA returns 1001 (Bars) - 4 (i). But Bar 997 is somewhere in Jan 2007, obviously messing up my results (when trying to find out a bar which should be in Dec 2010).

Any ideas guys?

Thanks,

G

 

A) you only get 1000 'pre start time' bars in Strategy Tester

B) It sounds like you're missing bars. To check, view the chart (with pair, timeframe & dates) that you're running your EA against. Hit 'Refresh' to get more history (that's a 'quick and unreliable fix' - search other posts/articles for more details on improving history)

 
You can also set the parameter in iBarsShift() to return the nearest bar if the exact bar is not found... I believe it's the last parameter
 

You only get 100 (hundred) pre start time bars in the Strategy Tester, not a thousand. Bars is initially 101.

I find for example the highest high - int i=iHighest(NULL,0,MODE_HIGH,10,1)

- I then want to find out what bar the shift is on so try, for example int Bar=iBarShift(NULL,0,Time[i]);

iHighest returns the highest bar shift. You already know what bar, i. Bar will always be exactly equal to i.

If i equals 4, then it is the 4th back that is the highest, not then 997th.

If you are scanning more then the amount of history then things get messed up, but given the code stated, not possible. The problem is else where. Post the actual code