MarketHours.TimeTillClose DST bug?
MarketHours.TimeTillClose DST bug?
03 Jan 2020, 12:40
Hi
On FxPro, I am seeing that the result returned by TimeTillClose can be out by an hour - this seems to happen around the time of DST changeover.
e.g. when backtesting with GBPUSD with my local offset currently at GMT+1, when the last weekly minute tick on Friday is at 21:59, MarketHours.TimeTillClose() is returning > 1:00, even though TradingSession.EndTime returns 22:00.
I would code around this using e.g. NodaTime, but I am not sure what assumptions you are making in TradingSessions - it just returns a TimeSpan with no hint of time zone or offset..
Replies
bishbashbosh
21 Jan 2020, 12:38
( Updated at: 21 Dec 2023, 09:21 )
using System;
using System.Collections.Generic;
using System.Linq;
using cAlgo.API;
namespace cAlgo.Robots
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TimeTillCloseDemo : Robot
{
private readonly Dictionary<DateTime, TimeSpan> _timesTillClose;
private static readonly TimeSpan Hours12 = TimeSpan.FromHours(12);
public TimeTillCloseDemo()
{
_timesTillClose = new Dictionary<DateTime, TimeSpan>();
}
protected override void OnTick()
{
var date = MarketSeries.OpenTime.LastValue.Date;
var timeTillClose = Symbol.MarketHours.TimeTillClose();
if (timeTillClose < Hours12)
{
_timesTillClose[date] = timeTillClose;
}
}
protected override void OnStop()
{
const int top = 10;
Print("Top {0} TimeTillClose values upon last tick of the day follow...", top);
var ordered = _timesTillClose.OrderByDescending(kvp => kvp.Value);
foreach (var keyValuePair in ordered.Take(top))
{
Print("{0:t} on {1:dddd, d MMMM}", keyValuePair.Value, keyValuePair.Key);
}
}
}
}
Running against the entirety of 2019 on EURUSD 3h gives for me:
@bishbashbosh
PanagiotisCharalampous
05 Feb 2020, 14:12
Hi bishbashbosh,
The issue results from the fact that we do not save historical market hours therefore we just use the current setting of the broker. So it might cause this discrepancy during periods with a different DST setting.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
07 Jan 2020, 08:58
Hi bishbashbosh,
Can you provide us with a cBot that will allow us to reproduce the problem?
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous