Extended and regular sessions — Pine Script User Manual 4 documentation (2024)

On TradingView you can access extended hours sessions byright-clicking on a chart and choosing SettingsSymbolExtended Hours (Intraday only).There are two types of sessions: regular (excluding pre- and post-marketdata) and extended (including pre- and post-market data).Pine scripts may request additional session data using thesecurity function.

The security function can be called with a symbol name(“EXCHANGE_PREFIX:TICKER”, e.g., “BATS:AAPL”) as its first argument.Used this way, the security function will return data for the regular session. For example:

Extended and regular sessions — Pine Script User Manual 4 documentation (1)

If you want the security call to return extended session data, youmust first use the tickerid functionto build security call’s first argument:

//@version=4study("Example 2: Extended Session Data")t = tickerid("BATS", "AAPL", session.extended)cc = security(t, timeframe.period, close, true)plot(cc, style=plot.style_linebr)

Extended and regular sessions — Pine Script User Manual 4 documentation (2)

Notice that the previous chart’s gaps in the script’s plot are now filled. Also keep in mindthat the background coloring on the chart is not produced by our example scripts;it is due to the chart’s settings showing extended hours.

The first argument of the tickerid function is an exchange prefix (“BATS”) and thesecond argument is a ticker (“AAPL”). The third argument specifies the typeof the session (session.extended or session.regular). So Example 1could be rewritten as:

//@version=4study("Example 3: Regular Session Data (using tickerid)")t = tickerid("BATS", "AAPL", session.regular)cc = security("BATS:AAPL", timeframe.period, close, true)plot(cc, style=plot.style_linebr)

If you want to request the same session specification used for the chart’s mainsymbol, omit the third argument; it is optional. Or, if you want your code toexplicitly declare your intention, use the syminfo.sessionbuilt-in variable as the third argument to tickerid function, as itholds the session type of the chart’s main symbol:

//@version=4study("Example 4: Same as Main Symbol Session Type Data")t = tickerid("BATS", "AAPL", syminfo.session)cc = security(t, timeframe.period, close, true)plot(cc, style=plot.style_linebr)
Extended and regular sessions — Pine Script User Manual 4 documentation (2024)
Top Articles
Latest Posts
Article information

Author: Madonna Wisozk

Last Updated:

Views: 6024

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Madonna Wisozk

Birthday: 2001-02-23

Address: 656 Gerhold Summit, Sidneyberg, FL 78179-2512

Phone: +6742282696652

Job: Customer Banking Liaison

Hobby: Flower arranging, Yo-yoing, Tai chi, Rowing, Macrame, Urban exploration, Knife making

Introduction: My name is Madonna Wisozk, I am a attractive, healthy, thoughtful, faithful, open, vivacious, zany person who loves writing and wants to share my knowledge and understanding with you.