Missing tick data to indicators during backtesting visual mode

Created at 13 Feb 2019, 21:37
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!
RM

rmssf

Joined 08.06.2016

Missing tick data to indicators during backtesting visual mode
13 Feb 2019, 21:37


Using cTrader version 3.3, I've noticed calls to indicator's Calculate() function being skipped and thus tick data missed to indicators while backtesting a cbot in visual mode, with a missing ratio increasing at higher simulation speeds. At maximum speed the ratio of missing data is almost 100%.

This affects users testing indicators in visual mode that make use of tick data.

While this may happen by design to speedup the simulation, I believe this behaviour should be noted as a warning when the above conditions are met (backtesting in visual mode a cbot with an indicator using tick data).

Regards,
Rui


@rmssf
Replies

PanagiotisCharalampous
14 Feb 2019, 09:23

Hi Rui,

Can you give us exact steps to reproduce this issue? Do you have any cBot and Indicator that we can use to observe this behavior?

Best Regards,

Panagiotis

 


@PanagiotisCharalampous

rmssf
14 Feb 2019, 19:34 ( Updated at: 21 Dec 2023, 09:21 )

Hello Mr. Panagiotis,

I've used an empty cbot just to test the indicator.

After noticing that tick data in an indicator was inconsistent during backtesting in visual mode I've built the simple indicator below to analyze what was happening, it just draws the number of times the function Calculate() is called over the simulation period.

namespace cAlgo
{
    [Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None, ScalePrecision = 0)]
    public class TickCount : Indicator
    {
        [Output("Tick count")]
        public IndicatorDataSeries TickCountOutput { get; set; }

        private int count = 0;
        private bool plot_zero = false;

        public override void Calculate(int index)
        {
            if (IsLastBar)
            {
                if (!plot_zero)
                {
                    plot_zero = true;
                    TickCountOutput[index - 1] = 0;
                }
                TickCountOutput[index] = count++;
            }
        }
    }
}


So looking closely it seems that calls to Calculate() are done asynchronously with respect to the tick data from server, in which the calls appear instead to being triggered by a timer.
Because of this behavior, for indicators that depend on tick data from server, a backtesting in visual mode produces invalid results. However I assume that there may be not many users impacted by this, as tick data is not commonly used in indicators.

 

Below is the indicator output at a constant simulation speed of 1000x. Notice the linear output without correlation to the tick volume.

 

Below is the indicator output at a simulation speed gradually increasing from minimum to maximum speed. The frequency at which Calculate() is called is not linear with the simulation speed, which results in that at higher speeds the amount of tick data missed by the indicator is close to 100%.

 

Regards,
Rui

 


@rmssf

PanagiotisCharalampous
15 Feb 2019, 09:21

Hi Rui,

Thanks, we will investigate this.

Best Regards,

Panagiotis


@PanagiotisCharalampous

sylvain.rochette@gmail.com
23 Feb 2020, 19:01

I have a similar problem.

 

When I backtest the tick are important to me, I select the tick data from server (accurate)

If 99% of the ticks are not used in indicators, it's completely useless in my optinion if your algo use indicators, its impossible to rely on them while backtesting.

Add an option under  tick data from server (accurate)

like tick data for indicators (accurate) will add latency

so it is up to us to select and test this with this option not up to you, you cannot code something if you cannot rely on backtesting...

 

Thank you!!


@sylvain.rochette@gmail.com

ctid2514471
24 Jan 2021, 03:54

RE:

PanagiotisCharalampous said:

Hi Rui,

Thanks, we will investigate this.

Best Regards,

Panagiotis

Hey Panagiotis - Did this issue ever get resolved?

I'm looking at making a tick-based cBot, but I am confused (and concerned) about the situation with Indicators and Back-testing.

Are there any resources to add clarity around this?


@ctid2514471

PanagiotisCharalampous
25 Jan 2021, 08:50

Hi ctid2514471,

This happens only during visual backtesting to indicators added on the backtesting chart. This is by design to speed up the backtesting process. Indicators references by cBots and cBot execution should not be affected.

Best Regards,

Panagiotis 

Join us on Telegram  


@PanagiotisCharalampous

ctid2514471
25 Jan 2021, 16:36

RE:

PanagiotisCharalampous said:

This happens only during visual backtesting to indicators added on the backtesting chart. This is by design to speed up the backtesting process. Indicators references by cBots and cBot execution should not be affected.

Ahh, good to know.

Good info to wrap this thread up. Thanks again.


@ctid2514471