# Extended sessions

An extended session is a period beyond the official trading hours of the exchange when trading still occurs.
The library allows you to display extended sessions for symbols that support them.
Note that extended sessions are only visible on [intraday resolutions](https://charting-library-docs.xstaging.tv/latest/connecting_data/time-and-sessions/configure-datafeed-resolutions.md#resolution-in-minutes-intraday).

The extended session includes regular, pre-market, and post-market subsessions. Either a pre-market or post-market subsession can be missed. When the chart displays an extended session, the subsessions are represented as colored areas.

## Enable extended sessions

To enable extended sessions, do the following:

- Add the [`pre_post_market_sessions`](../../customization/Featuresets.md#pre_post_market_sessions) featureset to the [`enabled_features`](../../api/interfaces/Charting_Library.ChartingLibraryWidgetOptions.md#enabled_features) array.
- Specify the [`subsession_id`](../Symbology.md#subsession_id) and [`subsessions`](../Symbology.md#subsessions) properties in [`LibrarySymbolInfo`](../../api/interfaces/Charting_Library.LibrarySymbolInfo.md) for symbols that support extended sessions. Refer to the [Configure datafeed](#configure-the-datafeed) section for more information.

### Specify the default session type

The chart can display regular or extended sessions. To specify the default session type, provide the [`mainSeriesProperties.sessionId`](../../api/interfaces/Charting_Library.ChartPropertiesOverrides.md#mainseriespropertiessessionid) property within [`overrides`].

```js
var widget = window.tvWidget = new TradingView.widget({
    // ...
    overrides: {
        "mainSeriesProperties.sessionId": "extended",
    }
});
```

### Specify subsession colors

Subsessions are represented on the chart as colored areas. You can specify default colors for pre-market and post-market subsessions using the [`overrides`] property in the [Widget Constructor](https://charting-library-docs.xstaging.tv/latest/configuration/Widget-Constructor.md).

```js
var widget = window.tvWidget = new TradingView.widget({
    // ...
    overrides: {
        "backgrounds.preMarket.color": "rgba(200,0,0,0.08)",
        "backgrounds.postMarket.color": "rgba(0,0,200,0.08)",
    }
});
```

To change the colors on the fly, use the [`applyOverrides`](../../api/interfaces/Charting_Library.IChartingLibraryWidget.md#applyoverrides) method.

```javascript
widget.applyOverrides({"backgrounds.outOfSession.color": "rgba(0,0,0,0.2)"});
widget.applyOverrides({"backgrounds.preMarket.color": "rgba(200,0,0,0.08)"});
widget.applyOverrides({"backgrounds.postMarket.color": "rgba(0,0,200,0.08)"});
```

Users can adjust the subsession colors in the _Chart settings_ dialog in the UI.

## Change the session type

You can switch between the sessions in the UI or using the API.

### In UI

Users can change the session type in the following ways:

- Use the drop-down menu on the bottom toolbar.

- Use the drop-down menu in the _Chart settings_ dialog.

### Using API

You can use the [`applyOverrides`](../../api/interfaces/Charting_Library.IChartingLibraryWidget.md#applyoverrides) method to change the session type on the fly.

```js
widget.applyOverrides({ "mainSeriesProperties.sessionId": "extended" });
```

## Configure the datafeed

To display extended sessions on the chart, you should provide additional data in [`LibrarySymbolInfo`].

:::tip

`LibrarySymbolInfo` is an object that contains information about a certain symbol. You should return this object to the library when it calls the [`resolveSymbol`] method. Refer to [Symbology](https://charting-library-docs.xstaging.tv/latest/connecting_data/Symbology.md) for more information on how to implement `LibrarySymbolInfo`.

:::

Consider the `LibrarySymbolInfo` object for a symbol that supports a regular session only.

```json
{
    "name": "AAPL",
    "ticker": "AAPL",
    "exchange": "NasdaqNM",
    "timezone": "Etc/UTC",
    "description": "Apple Inc.",
    "type": "stock",
    "pricescale": 100,
    "minmov": 1,
    "has_intraday": true,
    "supported_resolutions": ["60"],
    "has_daily": false,
    "intraday_multipliers": ["1"],
    "format": "price",
    "session": "0930-1600"
}
```

If the symbol supports an extended session, you should additionally specify the [`subsession_id`](../Symbology.md#subsession_id) and [`subsessions`] properties.
The code sample below specifies an extended session that starts at 04:00 and ends at 20:00. It includes a pre-market subsession from 04:00 to 09:30, a regular subsession from 09:30 to 16:00, and a post-market subsession from 16:00 to 20:00.

```json
{
    "name": "AAPL",
    "ticker": "AAPL",
    "exchange": "NasdaqNM",
    "timezone": "Etc/UTC",
    "description": "Apple Inc.",
    "type": "stock",
    "pricescale": 100,
    "minmov": 1,
    "has_intraday": true,
    "supported_resolutions": ["60"],
    "has_daily": false,
    "intraday_multipliers": ["1"],
    "format": "price",
    "session": "0930-1600",
    // highlight-start
    "subsession_id": "regular",
    "subsessions": [
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1600"
        },
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000"
        },
        {
            "description": "Pre-market",
            "id": "premarket",
            "session": "0400-0930"
        },
        {
            "description": "Post-market",
            "id": "postmarket",
            "session": "1600-2000"
        }
    ]
    // highlight-end
}
```

Note that the `session` and `subsession_id` values depend on the current session type selected on the chart.
If the session type is changed either [in the UI](#in-ui) or [using the API](#using-api), you should **update** the [`LibrarySymbolInfo`] object.

### Handle session switch

When the session type is changed, the library needs to request all data from scratch.
To do this, the library calls [`resolveSymbol`] once again with an additional [`SymbolResolveExtension`](../../api/interfaces/Charting_Library.SymbolResolveExtension.md) parameter. In `SymbolResolveExtension`, the [`session`](../../api/interfaces/Charting_Library.SymbolResolveExtension.md#session) property indicates what session type should be displayed on the chart.

In response, you should return the updated [`LibrarySymbolInfo`] object with the following properties changed:

- `subsession_id`: the property's value should match the [`SymbolResolveExtension.session`](../../api/interfaces/Charting_Library.SymbolResolveExtension.md#session) value. The value is either `"regular"` or `"extended"`.
- `session`: the property's value should match the corresponding [`LibrarySubsessionInfo.session`](../../api/interfaces/Charting_Library.LibrarySubsessionInfo.md#session) value specified in `subsessions`. For example, if the chart displays `"extended"` session, and for this session type `LibrarySubsessionInfo.session` is `"0400-2000"`, the `LibrarySymbolInfo.session` value should also be `"0400-2000"`.

 :::tip

 You can use the following expression to make sure that [`session`](../../api/interfaces/Charting_Library.LibrarySymbolInfo.md#session) is correct. The expression should always be `true`:

 ```javascript
 symbolInfo.session === symbolInfo.subsessions.find(x => x.id === subsession_id).session
 ```

 :::

#### Example

Consider the example. The current symbol on the chart is `AAPL` and the session type is regular. You should return the following [`LibrarySymbolInfo`] object to the library:

```json
{
    "name": "AAPL",
    "ticker": "AAPL",
    "exchange": "NasdaqNM",
    "timezone": "Etc/UTC",
    "description": "Apple Inc.",
    "type": "stock",
    "pricescale": 100,
    "minmov": 1,
    "has_intraday": true,
    "supported_resolutions": ["60"],
    "has_daily": false,
    "intraday_multipliers": ["1"],
    "format": "price",
    // highlight-start
    "session": "0930-1600",
    "subsession_id": "regular",
    // highlight-end
    "subsessions": [
        // highlight-start
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1600"
        },
        // highlight-end
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000"
        },
        {
            "description": "Pre-market",
            "id": "premarket",
            "session": "0400-0930"
        },
        {
            "description": "Post-market",
            "id": "postmarket",
            "session": "1600-2000"
        }
    ]
}
```

Then, the chart is switched to the extended session. The library calls `resolveSymbol` once again.
In response, you should update the `subsession_id` and `session` properties, so they match the corresponding values defined for the extended session in `subsessions`:

```json
{
    "name": "AAPL",
    "ticker": "AAPL",
    "exchange": "NasdaqNM",
    "timezone": "Etc/UTC",
    "description": "Apple Inc.",
    "type": "stock",
    "pricescale": 100,
    "minmov": 1,
    "has_intraday": true,
    "supported_resolutions": ["60"],
    "has_daily": false,
    "intraday_multipliers": ["1"],
    "format": "price",
    // highlight-start
    "session": "0400-2000",      // The value is changed
    "subsession_id": "extended", // The value is changed
    // highlight-end
    "subsessions": [
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1600"
        },
        // highlight-start
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000"
        },
        // highlight-end
        {
            "description": "Pre-market",
            "id": "premarket",
            "session": "0400-0930"
        },
        {
            "description": "Post-market",
            "id": "postmarket",
            "session": "1600-2000"
        }
    ]
}
```

### Corrections for extended sessions

Corrections are changes in the default trading session for specific days.
For regular sessions, you should only specify the [`corrections`](../Symbology.md#corrections) property in `LibrarySymbolInfo`.
However, for extended sessions, you should additionally provide [`session-correction`](../../api/interfaces/Charting_Library.LibrarySubsessionInfo.md#session-correction) for each subsession in `subsessions`.

For example, you need to display the following sessions:

- Regular. The default regular session starts at 09:30 and ends at 17:00. On 2019&#8209;07&#8209;03, 2019&#8209;11&#8209;29, and 2019&#8209;12&#8209;24, the session starts at 09:30 and ends at 13:00.
- Extended. The default extended session starts at 04:00 and ends at 20:00. On 2019&#8209;07&#8209;03, 2019&#8209;11&#8209;29, and 2019&#8209;12&#8209;24, the session starts at 04:00 and ends at 21:00.
- Pre-market. This session always starts at 04:00 and ends at 09:30.
- Post-market. The default post-market session starts at 17:00 and ends at 20:00. However, on 2019&#8209;07&#8209;03, 2019&#8209;11&#8209;29, and 2019&#8209;12-24, the session time shifts because of the changes in the regular and extended sessions. On these days, the post-market session starts at 13:00 and ends at 21:00.

```javascript
{
    // ...
    "subsessions": [
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1700",
            "session-correction": "0930-1300:20190703,20191129,20191224",
        },
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000",
            "session-correction": "0400-2100:20190703,20191129,20191224",
        },
        {
            "description": "Pre-market",
            "id": "premarket",
            "session": "0400-0930",
        },
        {
            "description": "Post-market",
            "id": "postmarket",
            "session": "1700-2000",
            "session-correction": "1300-2100:20190703,20191129,20191224",
        }
    ],
}
```

:::caution

Time changes in one session may cause changes in the related sessions. Make sure you specify corrections for all sessions that require them to avoid visual bugs.

:::

As mentioned [earlier](#handle-session-switch), you should update the `session` and `session_id` properties in `LibrarySymbolInfo` when the session type is changed.
If you specify corrections, you should also update the `corrections` property.
This property should contain one of the `session-correction` values, depending on the currently selected session type in the UI.
For example, the current type is `"regular"`, therefore, `corrections` is equal to the `session-correction` value specified for the regular session.

```javascript
{
    // ...
    "session": "0930-1700",
    "subsession_id": "regular",
    // highlight-next-line
    "corrections": "0930-1300:20190703,20191129,20191224",
    "subsessions": [
        // highlight-start
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1700",
            // highlight-next-line
            "session-correction": "0930-1300:20190703,20191129,20191224",
        },
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000",
            "session-correction": "0400-2100:20190703,20191129,20191224",
        },
        // ...
    ],
}
```

If the type is changed to `"extended"`, you should update `corrections` to match the `session-correction` value specified for the extended session.

```javascript
{
    // ...
    "session": "0400-2000",
    "subsession_id": "extended",
    // highlight-next-line
    "corrections": "0400-2100:20190703,20191129,20191224",
    "subsessions": [
        {
            "description": "Regular Trading Hours",
            "id": "regular",
            "session": "0930-1700",
            "session-correction": "0930-1300:20190703,20191129,20191224",
        },
        {
            "description": "Extended Trading Hours",
            "id": "extended",
            "session": "0400-2000",
            // highlight-next-line
            "session-correction": "0400-2100:20190703,20191129,20191224",
        },
        // ...
    ],
}
```

## Enable the price line

:::info

This feature is only available in [Trading Platform](https://charting-library-docs.xstaging.tv/latest/trading_terminal.md) as it requires [quote data](https://charting-library-docs.xstaging.tv/latest/trading_terminal/trading-concepts/quotes.md).

:::

The library allows you to display pre-/post-market price lines. These lines appear only during the pre-/post-market sessions when the chart shows only the regular session. However, if the chart is set to display the extended session, the lines will not be visible, as the data is already displayed on the chart.

To enable the lines, you should do the following:

- Enable the [`pre_post_market_price_line`](../../customization/Featuresets.md#pre_post_market_price_line) featureset.
- Provide the [`rtc`](../../api/interfaces/Datafeed.DatafeedQuoteValues.md#rtc) property in the [`DatafeedQuoteValues`](../../api/interfaces/Datafeed.DatafeedQuoteValues.md) object.

You can also display information on the pre-/post-market price in [Details](https://charting-library-docs.xstaging.tv/latest/trading_terminal.md#details).
To do this, you should additionally provide the [`rch`], [`rchp`], and [`rtc_time`] properties in the [`DatafeedQuoteValues`](../../api/interfaces/Datafeed.DatafeedQuoteValues.md) object.

[`LibrarySymbolInfo`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.LibrarySymbolInfo
[`resolveSymbol`]: https://charting-library-docs.xstaging.tv/latest/connecting_data/datafeed-api/required-methods.md#resolvesymbol
[`subsessions`]: https://charting-library-docs.xstaging.tv/latest/connecting_data/Symbology.md#subsessions
[`overrides`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ChartingLibraryWidgetOptions#overrides
[`rch`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Datafeed.DatafeedQuoteValues#rch
[`rchp`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Datafeed.DatafeedQuoteValues#rchp
[`rtc_time`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Datafeed.DatafeedQuoteValues#rtc_time

---

## Sitemap

- [All documentation pages](https://charting-library-docs.xstaging.tv/llms.txt)
- [Full page map with headings](https://charting-library-docs.xstaging.tv/docs_map.md)
