SessionIterator

View as Markdown

Definition

Allows you to traverse through various trading hours data elements which apply to a segment of bars.

Should you wish to obtain trading hours information for historical bar values, you need to construct and store your own session iterator object based of the desired bars series array.

Parameters

  • bars
  • The Bars object used to create the SessionIterator

Warning: The properties in this class should NOT be accessed within the OnStateChange() method before the State has reached State.DataLoaded.

Methods and Properties

Method/PropertyDescription
ActualSessionBeginObtains the sessions start day and start time converted to the PC’s local time zone
ActualSessionEndObtains the sessions end day and end time converted to the PC’s local time zone
ActualTradingDayEndLocalReturns the sessions End-Of-Day (EOD) in the local timezone
ActualTradingDayExchangeObtains the date of a session representing the trading date of the exchange
CalculateTradingDay()Calculates the current trading date of a specified date
GetNextSession()Calculates the next available session relative to a specified date
GetTradingDay()Returns the actual trading date based on the exchange
GetTradingDayBeginLocal()Converts the trading day begin time from the exchange timezone to local time
GetTradingDayEndLocal()Converts the trading day end time from the exchange timezone to local time
IsInSession()Indicates if a specified date is within the bounds of the current session
IsNewSession()Indicates if a specified time is greater than the actual session end of the current session
IsTradingDayDefined()Indicates if a trading day is defined for a specific date

Tip: In order to calculate a session information for another multi-instrument or multi-time frame script, you can pass in the desired BarsArray array value as the SessionIterator bars object.

Examples

1private SessionIterator sessionIterator;
2
3protected override void OnStateChange()
4{
5 if (State == State.DataLoaded)
6 {
7 //stores the sessions once bars are ready, but before OnBarUpdate is called
8 sessionIterator = new SessionIterator(Bars);
9 }
10}
11
12protected override void OnBarUpdate()
13{
14 // on new bars session, find the next trading session
15 if (Bars.IsFirstBarOfSession)
16 {
17 Print("Calculating trading day for " + Time[0]);
18 // use the current bar time to calculate the next session
19 sessionIterator.GetNextSession(Time[0], true);
20
21 // store the desired session information
22 DateTime tradingDay = sessionIterator.ActualTradingDayExchange;
23 DateTime beginTime = sessionIterator.ActualSessionBegin;
24 DateTime endTime = sessionIterator.ActualSessionEnd;
25
26 Print(string.Format("The Current Trading Day {0} starts at {1} and ends at {2}",
27 tradingDay.ToShortDateString(), beginTime, endTime));
28 // Output:
29 // Calculating trading day from 9/30/2015 4:01:00 PM
30 //The Current Trading Day 10/1/2015 starts at 9/30/2015 4:00:00 PM and ends at 10/1/2015 3:00:00 PM
31 }
32}