IsInSession()

View as Markdown

Definition

Indicates a specified date is within the bounds of the current session, according to the configured Trading Hours template.

Additionally this method will internally trigger a GetNextSession() call to calculate the next available session relative to the “timeLocal” value used in the method’s input.

Property Value

A bool value when true indicates the specified time is within the current trading session; otherwise false.

Parameters

ParameterDescription
timeLocalThe DateTime value used to calculate the next trading day.
includesEndTimeStampA 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).
isIntraDayA bool determining if IsInSession() considers the time of day (when true) or only the date (when false).

Syntax

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

Examples

1private SessionIterator sessionIterator;
2
3protected override void OnStateChange()
4{
5 if (State == State.Historical)
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 // Only place an order if the time three hours from now will still be within the current session
15 if (sessionIterator.IsInSession(DateTime.Now.AddHours(3), true, true) /* && additional conditions here */)
16 EnterLongStopMarket(CurrentDayOHL().High[0] + TickSize);
17}