> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.ninjatrader.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.ninjatrader.com/_mcp/server.

# SessionIterator

## 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/Property                                                                                               | Description                                                                                 |
| ------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------- |
| [ActualSessionBegin](/developer/desktop-sdk/references/common/sessioniterator/actualsessionbegin)             | Obtains the sessions start day and start time converted to the PC's local time zone         |
| [ActualSessionEnd](/developer/desktop-sdk/references/common/sessioniterator/actualsessionend)                 | Obtains the sessions end day and end time converted to the PC's local time zone             |
| [ActualTradingDayEndLocal](/developer/desktop-sdk/references/common/sessioniterator/actualtradingdayendlocal) | Returns the sessions End-Of-Day (EOD) in the local timezone                                 |
| [ActualTradingDayExchange](/developer/desktop-sdk/references/common/sessioniterator/actualtradingdayexchange) | Obtains the date of a session representing the trading date of the exchange                 |
| [CalculateTradingDay()](/developer/unsorted/calculatetradingday)                                              | Calculates the current trading date of a specified date                                     |
| [GetNextSession()](/developer/desktop-sdk/references/common/sessioniterator/getnextsession)                   | Calculates the next available session relative to a specified date                          |
| [GetTradingDay()](/developer/desktop-sdk/references/common/sessioniterator/gettradingday)                     | Returns the actual trading date based on the exchange                                       |
| [GetTradingDayBeginLocal()](/developer/desktop-sdk/references/common/sessioniterator/gettradingdaybeginlocal) | Converts the trading day begin time from the exchange timezone to local time                |
| [GetTradingDayEndLocal()](/developer/desktop-sdk/references/common/sessioniterator/gettradingdayendlocal)     | Converts the trading day end time from the exchange timezone to local time                  |
| [IsInSession()](/developer/desktop-sdk/references/common/sessioniterator/isinsession)                         | Indicates if a specified date is within the bounds of the current session                   |
| [IsNewSession()](/developer/desktop-sdk/references/common/sessioniterator/isnewsession)                       | Indicates if a specified time is greater than the actual session end of the current session |
| [IsTradingDayDefined()](/developer/desktop-sdk/references/common/sessioniterator/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

```csharp
private SessionIterator sessionIterator;

protected override void OnStateChange()
{
    if (State == State.DataLoaded)
    {
        //stores the sessions once bars are ready, but before OnBarUpdate is called
        sessionIterator = new SessionIterator(Bars);
    }
}

protected override void OnBarUpdate()
{
    // on new bars session, find the next trading session
    if (Bars.IsFirstBarOfSession)
    {
        Print("Calculating trading day for " + Time[0]);
        // use the current bar time to calculate the next session
        sessionIterator.GetNextSession(Time[0], true);

        // store the desired session information
        DateTime tradingDay   = sessionIterator.ActualTradingDayExchange;
        DateTime beginTime    = sessionIterator.ActualSessionBegin;
        DateTime endTime      = sessionIterator.ActualSessionEnd;

        Print(string.Format("The Current Trading Day {0} starts at {1} and ends at {2}",
                            tradingDay.ToShortDateString(), beginTime, endTime));
        // Output:
        // Calculating trading day from 9/30/2015 4:01:00 PM
        //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
    }
}
```