Open Only back testing mystery

 

In Open Only back testing mode, a tick is supposed to occur at the start of a bar only. A simple test of this assumption reveals a mystery. Anyone willing to help, please help to answer and resolve the mystery.

This simple test code (attached) was run on EURUSD M1 timeframe with OnTimer interval set at 1 second. It is printing out ask/bid values every second at OnTimer event. New bars are noted. OnTick events are ignored.

The ask/bid prices change on the bar start, as expected. But they also change at 40 s into the bar, and sometimes at 20 s. This is consistent throughout any test intervals. WHY???


Here is a subset of the output:


OD 0 10:35:03.781 Core 2 2018.01.02 00:07:53   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

PK 0 10:35:03.781 Core 2 2018.01.02 00:07:54   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

QR 0 10:35:03.781 Core 2 2018.01.02 00:07:55   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

FI 0 10:35:03.781 Core 2 2018.01.02 00:07:56   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

CP 0 10:35:03.781 Core 2 2018.01.02 00:07:57   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

LG 0 10:35:03.781 Core 2 2018.01.02 00:07:58   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

MN 0 10:35:03.781 Core 2 2018.01.02 00:07:59   time_arr=2018.01.02 00:05:00 itime=2018.01.02 00:07:00 Bid_price=1.20053 BarBid=1.20053 Ask_price=1.20087 BarAsk=1.20087 Open[0]=1.20023 iopen=1.20053

EF 0 10:35:03.781 Core 2 2018.01.02 00:08:00   A new bar has appeared on symbol EURUSD at 2018.01.02 00:08

RH 0 10:35:03.781 Core 2 2018.01.02 00:08:00   NEW BAR 

LQ 0 10:35:03.781 Core 2 2018.01.02 00:08:00   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

IH 0 10:35:03.781 Core 2 2018.01.02 00:08:01   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

JO 0 10:35:03.781 Core 2 2018.01.02 00:08:02   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

CF 0 10:35:03.781 Core 2 2018.01.02 00:08:03   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

HM 0 10:35:03.781 Core 2 2018.01.02 00:08:04   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

ME 0 10:35:03.781 Core 2 2018.01.02 00:08:05   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

NL 0 10:35:03.781 Core 2 2018.01.02 00:08:06   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

OS 0 10:35:03.781 Core 2 2018.01.02 00:08:07   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

DJ 0 10:35:03.781 Core 2 2018.01.02 00:08:08   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

QQ 0 10:35:03.781 Core 2 2018.01.02 00:08:09   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

GH 0 10:35:03.781 Core 2 2018.01.02 00:08:10   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

FO 0 10:35:03.781 Core 2 2018.01.02 00:08:11   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

EF 0 10:35:03.781 Core 2 2018.01.02 00:08:12   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

PN 0 10:35:03.781 Core 2 2018.01.02 00:08:13   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

KE 0 10:35:03.781 Core 2 2018.01.02 00:08:14   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

RL 0 10:35:03.781 Core 2 2018.01.02 00:08:15   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

QS 0 10:35:03.781 Core 2 2018.01.02 00:08:16   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

DJ 0 10:35:03.781 Core 2 2018.01.02 00:08:17   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

OQ 0 10:35:03.781 Core 2 2018.01.02 00:08:18   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

NH 0 10:35:03.781 Core 2 2018.01.02 00:08:19   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

FO 0 10:35:03.781 Core 2 2018.01.02 00:08:20   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

OG 0 10:35:03.781 Core 2 2018.01.02 00:08:21   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

PN 0 10:35:03.781 Core 2 2018.01.02 00:08:22   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

ME 0 10:35:03.781 Core 2 2018.01.02 00:08:23   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

RL 0 10:35:03.781 Core 2 2018.01.02 00:08:24   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

CS 0 10:35:03.781 Core 2 2018.01.02 00:08:25   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

DJ 0 10:35:03.781 Core 2 2018.01.02 00:08:26   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

IQ 0 10:35:03.781 Core 2 2018.01.02 00:08:27   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

NH 0 10:35:03.781 Core 2 2018.01.02 00:08:28   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

GP 0 10:35:03.781 Core 2 2018.01.02 00:08:29   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

QG 0 10:35:03.781 Core 2 2018.01.02 00:08:30   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

LN 0 10:35:03.781 Core 2 2018.01.02 00:08:31   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

KE 0 10:35:03.781 Core 2 2018.01.02 00:08:32   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

JL 0 10:35:03.781 Core 2 2018.01.02 00:08:33   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

ES 0 10:35:03.781 Core 2 2018.01.02 00:08:34   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

HJ 0 10:35:03.781 Core 2 2018.01.02 00:08:35   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

GQ 0 10:35:03.781 Core 2 2018.01.02 00:08:36   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

NI 0 10:35:03.781 Core 2 2018.01.02 00:08:37   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

IP 0 10:35:03.781 Core 2 2018.01.02 00:08:38   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

DG 0 10:35:03.781 Core 2 2018.01.02 00:08:39   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20045 BarBid=1.20045 Ask_price=1.20079 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

CN 0 10:35:03.781 Core 2 2018.01.02 00:08:40   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

RE 0 10:35:03.781 Core 2 2018.01.02 00:08:41   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

QL 0 10:35:03.781 Core 2 2018.01.02 00:08:42   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

LS 0 10:35:03.781 Core 2 2018.01.02 00:08:43   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

OJ 0 10:35:03.781 Core 2 2018.01.02 00:08:44   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

FR 0 10:35:03.781 Core 2 2018.01.02 00:08:45   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

EI 0 10:35:03.781 Core 2 2018.01.02 00:08:46   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

HP 0 10:35:03.781 Core 2 2018.01.02 00:08:47   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

KG 0 10:35:03.781 Core 2 2018.01.02 00:08:48   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

JN 0 10:35:03.781 Core 2 2018.01.02 00:08:49   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

PE 0 10:35:03.781 Core 2 2018.01.02 00:08:50   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

ML 0 10:35:03.781 Core 2 2018.01.02 00:08:51   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045

NS 0 10:35:03.781 Core 2 2018.01.02 00:08:52   time_arr=2018.01.02 00:06:00 itime=2018.01.02 00:08:00 Bid_price=1.20072 BarBid=1.20045 Ask_price=1.20106 BarAsk=1.20079 Open[0]=1.20046 iopen=1.20045



Files:
TimeTest.mq5  8 kb
 

This is normal behaviour, please read the documentation carefully :

"Open Prices Only"

In this mode ticks are generated based on the OHLC prices of the timeframe selected for testing. The OnTick() function of the Expert Advisor runs only at the beginning of the bar at the Open price. Due to this feature, stop levels and pending may trigger at a price that differs from the specified one (especially when testing on higher timeframes). Instead, we have an opportunity to quickly run an evaluation test of the Expert Advisor.

W1 and MN1 periods are the exceptions in the "Open Price Only" ticks generation mode: for these timeframes ticks are generated for the OHLC prices of each day, not OHLC prices of the week or month.

Suppose we test an Expert Advisor on EURUSD H1 in the "Open Prices Only" mode. In this case the total number of ticks (control points) will be no more than 4*number of one-hour bars within the tested interval. But the OnTick() handler is called only at the opening of the one-hour bar. The checks required for a correct testing occur on the rest of the ticks (that are "hidden" from the EA).

 
Alain Verleyen:

This is normal behaviour, please read the documentation carefully :

Thank you Alain for your response. If I understand it correctly, there are up to 4 hidden control points / ticks inside each bar, in addition to the tick at the beginning of each bar.  Does it mean that there is no way to generate "open only" results in "every tick" method because there is no way to reproduce the control points?
 
milev:
Thank you Alain for your response. If I understand it correctly, there are up to 4 hidden control points / ticks inside each bar, in addition to the tick at the beginning of each bar.  Does it mean that there is no way to generate "open only" results in "every tick" method because there is no way to reproduce the control points?

There is up to 4 ticks (control points) including the one triggering OnTick().

I don't understand why you would need to generate "open only" in "every tick" mode. Doesn't make sense to me.

 
Alain Verleyen:

There is up to 4 ticks (control points) including the one triggering OnTick().

I don't understand why you would need to generate "open only" in "every tick" mode. Doesn't make sense to me.

Because I get excellent results in Open Only mode and losing money in Every Tick mode (which is closer to real life). I spent weeks trying to align the ET mode with OO mode and found out that it is partly possible by forcing ET mode to operate with data received at the first bar tick, but then OO receives a control point tick that can't be duplicated in ET mode and that changes the whole Ask/Bid dynamics. Any suggestion on how to overcome this predicament would be greatly appreciated.

 
milev:

Because I get excellent results in Open Only mode and losing money in Every Tick mode (which is closer to real life). I spent weeks trying to align the ET mode with OO mode and found out that it is partly possible by forcing ET mode to operate with data received at the first bar tick, but then OO receives a control point tick that can't be duplicated in ET mode and that changes the whole Ask/Bid dynamics. Any suggestion on how to overcome this predicament would be greatly appreciated.

You don't want your EA to align with some tester method, unless your intend is to not use but only sell the EA.

You can not withdraw tester money. You need to align to the real world. For that, every tick based on real tick is closest to real life.

 
milev:

Because I get excellent results in Open Only mode and losing money in Every Tick mode (which is closer to real life). I spent weeks trying to align the ET mode with OO mode and found out that it is partly possible by forcing ET mode to operate with data received at the first bar tick, but then OO receives a control point tick that can't be duplicated in ET mode and that changes the whole Ask/Bid dynamics. Any suggestion on how to overcome this predicament would be greatly appreciated.

The only suggestion I can make is for you to forget this idea.

If you get good results in "Open Prices only" but not  in "Every tick" that means your strategy or the way you coded it in your EA is not suitable to be used with "Open Prices only".

You really need to read the documentation carefully and understand it (same link as before) :

If there are no open positions or pending orders, we don't need to perform these checks on hidden ticks, and the increase of speed may be quite substantial. This "Open prices only" mode is well suited for testing strategies, which process deals only at the opening of the bar and do not use pending orders, as well as StopLoss and TakeProfit orders. For the class of such strategies, the necessary accuracy of testing is preserved.

Obviously your strategy is not of "this class".

 
thanks