EA using bar open price help required

 

Hi all

I am using the standard bar open code

if (timeold!=Time[0]){
timeold=Time[0];
to kick off my EA decisions for trading when a new bar opens. In the back testing however I get completely different results using every tick for a run compared to using open prices only.

I would have thought the results should have been similar since I only use the prices involved in the candles of the prevoius 3 candles ie. Time[1],Time[2] and Time[3]

not the current candle Time[0].

I want my EA to use only the H,L,O,C data for each candle and I am not interested in all the ticks in between. Is my understanding of the back testing data options correct or should I be doing it another way.

Thanks

Paul

 
My first guess would be that the "open prices only" presents the bars as they exist in history, while "every tick" mode might inject ticks also for the missing bars. Perhaps. It depends on your time frame, but at least up to M15, it's common that the history omits bars: in addition to weekend holes, you find mid-week holes where Time[i+1]-Time[i] > Period()*60. And my guess is that the "open prices" mode presents the bars as they are, but thet "every tick" invents mid-week bars. That would explain a difference, though you will have to verify by yourself that my guess is on the right track.
 

Hi Ralph

Thanks for the reply. I am using 1 hour time frame. I think what you are saying is that since my code works on candle open time and doesn't care about ticks the results of the back testing using "open price only" is accurate. So really I should ignore the different result from using "every tick" because this method is creating erroneous data. This does create a bit of a conundrum since I want to use the candle open to enter trades but every tick to decide the trade exit, so I guess I can't use the back tester to test both at the same time.

 
You might of course run it on M1 instead, and make your EA discover first tick of the hour as well as first tick of the bar. Then you have a repeatable backtesting, and some degree of reliability in transferring to forward testing.
static datetime time = 0;
if (Time[0] == time ) return( 0 );
time = Time[0];
... code for first-tick-for-bar activity here
 
static int hour = -1;
if ( TimeHour( time ) == hour ) return( 0 );
hour = TimeHour( time );
... code for first-tick-for-hour here

Not every tick, of course, but maybe M1 is fast enough...
 

Hi Ralph

That's a good idea I shall use it because M1 gives plenty of resolution for the get out condition. Thanks a lot.

Reason: