Market hours / OnTick() mismatch in backtest
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);
}
}
}
Replies
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
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