GetNextSession()

View as Markdown

Definition

Calculates the next available session relative to the “timeLocal” value used in the method’s input.

This method needs to be used before you can accurately determine various session properties such as ActualSessionBegin or ActualTradingDayEndLocal, etc.

Property Value

A bool value when true indicates the method was able to successfully calculate the next trading session; otherwise false.

This method is resource intensive and should ONLY be reserved for situations when calculations would be limited to a few specific use cases. For example, calling this method for each bar in the OnBarUpdate() method would NOT be recommended.

Parameters

ParameterDescription
timeLocalincludesEndTimeStamp
The DateTime value used to calculate the next trading day.A bool determining if a timestamp of <n>:00 should fall into the current session. (e.g., used for time based intraday series such as minute or second).

===

Syntax

\<sessioniterator\>.GetNextSession(DateTime timeLocal, bool includesEndTimeStamp)

Examples

Getting Next Session of the Primary Bars Object

1SessionIterator sessionIterator;
2protected override void OnStateChange()
3{
4 if (State == State.Historical)
5 {
6 sessionIterator = new SessionIterator(Bars);
7 }
8}
9
10protected override void OnBarUpdate()
11{
12 // on new bars session, find the next trading session
13 if (Bars.IsFirstBarOfSession)
14 {
15 // use the current bar time to calculate the next session
16 sessionIterator.GetNextSession(Time[0], true);
17 }

csharp Getting Next Session of a Secondary Time Series

1SessionIterator rthSessionIterator;
2protected override void OnStateChange()
3{
4 if (State == State.Configure)
5 {
6 // add a 1440 minute bar using the RTH hours
7 AddDataSeries(Instrument.FullName, new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1440 }, "CME US Index Futures RTH");
8 }
9 else if (State == State.Historical)
10 {
11 // store a session iterator built from the secondary (RTH) bars
12 rthSessionIterator = new SessionIterator(BarsArray[1]);
13 }
14}
15
16protected override void OnBarUpdate()
17{
18 // on the primary bars session, find the next trading session for the RTH bars
19 if (Bars.IsFirstBarOfSession)
20 {
21 // use the current bar time to calculate the next RTH session
22 rthSessionIterator.GetNextSession(Time[0], true);
23 }