Backtesting: OnBar() vs OnTick() with Timeframe = "t1" and Data = "Tick Data from Server"

Created at 19 Feb 2015, 13:15
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!
CP

cprcrack

Joined 15.02.2015

Backtesting: OnBar() vs OnTick() with Timeframe = "t1" and Data = "Tick Data from Server"
19 Feb 2015, 13:15


I would expect OnTick() and OnBar() to be called in alternation like this:

OnTick, OnBar, OnTick, OnBar...

However, sometimes OnTick() is called twice in a row like this:

OnTick, OnBar, OnTick, OnTick, OnBar...

Could you please explain why does this happen?


@cprcrack
Replies

cprcrack
19 Feb 2015, 14:45

A simple backtest with tick timeframe and tick data from 1/10/2014 to 10/10/2014 (10 days) brings the following results:

  • Total ticks: 878872
  • Total bars: 586469

However the same backtest with 1m timeframe and 1m data for the same period brings the following result as expected:

  • Total ticks: 11278
  • Total bars: 11278

I need to understand this discrepancy for the development of my bot.


@cprcrack

cprcrack
19 Feb 2015, 16:16

Okay, I think I know what's happening. OnBar() is not fired after onTick() when the Bid Price has not changed since the last tick, even if the Spread of Ask Price has changed. Please correct me if I'm wrong.

 


@cprcrack

cprcrack
19 Feb 2015, 16:17

RE:

cprcrack said:

even if the Spread of Ask Price has changed.

I meant Spread or Ask Price.


@cprcrack

Spotware
25 Feb 2015, 17:09

You are right, OnBar event will be invoked only if bid changed (in new time period) while OnTick event is invoked on every price change (Bid or Ask).


@Spotware