Backtesting: OnBar vs OnTick

Created at 01 Sep 2014, 18:58
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
PE

pennyfx

Joined 27.09.2012

Backtesting: OnBar vs OnTick
01 Sep 2014, 18:58


I have a strategy that relies on OnTick().  When backtesting I get wildly different results between 1m bars and tick data.   My question is how does OnTick function when backtesting with 1m bars?   Does it get fired on close of each per 1m bar or something different?

 

 


@pennyfx
Replies

Spotware
02 Sep 2014, 09:57

In Minute bars data mode we generate 4 ticks (open, high, low, close) for every m1 bar.


@Spotware

AlexanderRC
03 Sep 2014, 01:41

RE:

Spotware said:

In Minute bars data mode we generate 4 ticks (open, high, low, close) for every m1 bar.

Do these 4 ticks happen in the order listed?

What happens with limit and stop orders which existed before the bar if the entry price for them happens to be somewhere between high and low?

What happens if the stop and limit orders are placed somewhere between these 4 ticks?


@AlexanderRC

Spotware
03 Sep 2014, 10:04

Order is fixed: open, high, low, close.

Backtester fills limit orders by target price or better. Stop orders could be filled by worse price.

Example 1.

  • Place Buy Limit order at 1.2345
  • Next tick: Ask = 1.2320
  • Order will be filled by 1.2320

Example 2.

  • Place Buy Stop order at 1.2345
  • Next tick: Ask = 1.2350
  • Order will be filled by 1.2350

@Spotware

Spotware
15 Oct 2014, 09:27

We have changed m1 data mode in cAlgo 1.27. Since now we generate 1 tick (open price) per minute bar.


@Spotware

AlexanderRC
15 Oct 2014, 18:29

RE:

Spotware said:

We have changed m1 data mode in cAlgo 1.27. Since now we generate 1 tick (open price) per minute bar.

Please bring back the old mode of "open, high, low, close". Adding "open, low, high, close" as a variant would also be helpful.

Using m1 (or any other timeframe) with high and low may be faster than tick data for cBot optimization when such tradeoff between accuracy and speed is acceptable.


@AlexanderRC

Spotware
16 Oct 2014, 09:44

Why are you not satisfied with m1 open prices data mode?

We decided to remove m1 OHLC mode because it provides extra information to cBot during backtesting. Imagine that you could collect prices during a minute, than choose the highest/lowest one, go back in time and trade at that price. It is not possible in live running, but OHLC data mode worked in that way in backtesting. That is why we decided to replace it to open prices data mode.


@Spotware

AlexanderRC
16 Oct 2014, 17:08

RE:

Spotware said:

Why are you not satisfied with m1 open prices data mode?

We decided to remove m1 OHLC mode because it provides extra information to cBot during backtesting. Imagine that you could collect prices during a minute, than choose the highest/lowest one, go back in time and trade at that price. It is not possible in live running, but OHLC data mode worked in that way in backtesting. That is why we decided to replace it to open prices data mode.

"Going back in time" during backtesting? What do you mean? As far as I remember Server.Time increased monotonically during OHLC backtesting.


@AlexanderRC

Spotware
16 Oct 2014, 17:51

OHLC data mode quarantines that second tick in every minute is the highest price of current minute and all other ticks in current minute will have smaller prices. It is extra information that could cause misleading Optimization and Backtesting results. That is why we decided to remove OHLC data mode from backtesting and optimization.


@Spotware

AlexanderRC
17 Oct 2014, 14:16

RE:

Spotware said:

OHLC data mode quarantines that second tick in every minute is the highest price of current minute and all other ticks in current minute will have smaller prices. It is extra information that could cause misleading Optimization and Backtesting results. That is why we decided to remove OHLC data mode from backtesting and optimization.

Now I see.

Another approach would be to add an additional piece of information to the bar: whether high or low occurred first (or when they occurred exactly). That you would simulate highs and lows in the order they occurred (or even at the exact time they occurred).

For now to get the best combination of speed an accuracy I am going to skip certain OnTick() events if the price went monotonically up or down and that does not require reevaluation. But that depends on the logic of the specific cBot in question.


@AlexanderRC