I’ve coded it as follows. ( the _strTimeSpanDuration should be something like 6:30 to mean trade for 6 1/2 hours from the open )
// In the OnStartUp() method:
TimeSpan timeSpanSessionStart = Bars.Session.NextBeginTime.TimeOfDay;
timeSpanDuration = TimeSpan.Parse(_strTimeSpanDuration);
// the time rule will return false if trading should stop
protected virtual bool TimeRule()
{
TimeSpan timeSpanSessionStart = Bars.Session.NextBeginTime.TimeOfDay;
TimeSpan timeSpanTradingStop = timeSpanSessionStart.Add(timeSpanDuration);
return this.Time[0].TimeOfDay < timeSpanTradingStop;
}
Is this all correctly done? It is working on my computer ( Easter Time ) but I don't know if it's correct for other zones.

Comment