Skip to main content

TradingTime

TradingTime defines a time window during which the strategy is allowed to trade. Outside these windows, the strategy will not open new positions. Multiple TradingTime instances can be added to Strategy.TradingTimes for complex schedules.

Namespace: MZpack.NT8.Algo Source: [INSTALL PATH]/API/TradingTime.cs

Properties

PropertyTypeDescription
BeginDateTimeStart time of the trading window (time-of-day portion is used)
EndDateTimeEnd time of the trading window (time-of-day portion is used)

Methods

MethodReturn TypeDescription
IsTrade(DateTime time)boolReturns true if the given time is inside the trading window
IsIdle(DateTime time)boolReturns true if the given time is outside the trading window

Example: Trade RTH Session Only

OnCreateAlgoStrategy = () =>
{
var strategy = new Strategy("RTH_Only", this);

// Only trade during Regular Trading Hours (9:30 AM - 4:00 PM ET)
strategy.TradingTimes = new List<TradingTime>
{
new TradingTime
{
Begin = DateTime.Parse("09:30"),
End = DateTime.Parse("16:00")
}
};

// ... configure patterns, entries, etc.
strategy.Initialize(entryPattern);
return strategy;
};

Example: Multiple Trading Windows

// Trade morning and afternoon sessions, skip lunch
strategy.TradingTimes = new List<TradingTime>
{
new TradingTime
{
Begin = DateTime.Parse("09:30"),
End = DateTime.Parse("11:30")
},
new TradingTime
{
Begin = DateTime.Parse("13:00"),
End = DateTime.Parse("15:45")
}
};

Integration with Strategy

The strategy checks TradingTimes via Strategy.IsTrade(DateTime time, out string reason). If the current time is outside all trading windows, IsTrade returns false and the strategy skips position opening. The TradingDays property on Strategy provides day-of-week filtering separately.

See Also