Scheduled events allow you to trigger code blocks for execution at specific times according to rules you set. This feature helps coordinate your algorithm activities and perform analysis at regular intervals; while letting the trading engine take care of market holidays.

The scheduling is set with two rules: the DateRules and TimeRules classes. The schedule manager takes one of each and executes an action code block:

Schedule.On(DateRules.On(2013, 10, 7), TimeRules.At(13, 0), () => 
         Debug("Specific Time: Fired at : " + Time);

The date rules can be specified as below:

Scheduled Events Date Rules
DateRules.On(2013, 10, 7) On a specific date
DateRules.EveryDay("SPY") Every trading day for SPY
DateRules.Every(DayOfWeek.Monday, ...) On specific days of week
DateRules.EveryDay() Every day
DateRules.MonthStart("SPY") SPY trading start of each month

The time rules trigger specify when on the day the event should be triggered. They can be specified as below:

Scheduled Events Time Rules
TimeRules.At(13, 0) At a specific time, 1:00pm
TimeRules.AfterMarketOpen("SPY", 10) Run 10 minutes after market open for SPY
TimeRules.BeforeMarketClose("SPY", 10) Run 10 minutes before market close for SPY
TimeRules.Every(TimeSpan.FromMinutes(10)) Every 10 minutes during day specified

For a demonstration see the tutorial video below:

Sign In to comment in this post.