Market hours / OnTick() mismatch in backtest

Created at 01 Apr 2024, 15:11
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!
NC

ncel01

Joined 19.03.2020

Market hours / OnTick() mismatch in backtest
01 Apr 2024, 15:11


Hello,

I've noticed a mismatch between market hours and OnTick() event when backtesting.
Broker: Varianse
Symbol: UT100.v

Outcome (UTC +0):
From 21:00 to 22:00 → Symbol.MarketHours.IsOpened() returns false while OnTick() keeps being triggered due to a change in price.
From 22:00 to 23:00 → There is no price change ( OnTick() is not triggered ) while Symbol.MarketHours.IsOpened() = true

For your reference I've added a code sample below.
This is probably not a unique case with this broker / instrument.

using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class OnTimertest : Robot
    {
        [Parameter("Operations per hour", DefaultValue = 6)]
        public double OpPerHour { get; set; }


        private int _onTimerCounter = 0;

        protected override void OnStart()
        {
            Timer.Start(1);
        }

        protected override void OnTimer()
        {
            _onTimerCounter++;

            if (_onTimerCounter % (3600 / OpPerHour) == 0)

                Print("Market is open : ", Symbol.MarketHours.IsOpened());

        }

        protected override void OnTick()
        {
            if (_onTimerCounter % (3600 / OpPerHour) == 0)
                Print("OnTick() trigger : ", Symbol.Bid);
        }
    }
}

@ncel01
Replies

PanagiotisCharalampous
02 Apr 2024, 09:42

Hi ncel01,

MarketHours are taken from current schedule, historical prices may not correspond to current schedule

Best regards,

Panagiotis


@PanagiotisCharalampous

ncel01
02 Apr 2024, 10:44

RE: Market hours / OnTick() mismatch in backtest

PanagiotisCharalampous said: 

Hi ncel01,

MarketHours are taken from current schedule, historical prices may not correspond to current schedule

Best regards,

Panagiotis

Hi Panagiotis,

It's not exactly an issue then.

That's clear! Thanks.


@ncel01