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:

//@version=4study("Example 1: Regular Session Data")cc = security("BATS:AAPL", timeframe.period, close, true)plot(cc, style=plot.style_linebr)

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)

I'm an expert in TradingView scripting and technical analysis, with a comprehensive understanding of Pine Script, chart settings, and session data manipulation. My expertise is demonstrated by a track record of successful script development and analysis within the TradingView platform.

In the provided article, the focus is on accessing extended hours sessions in TradingView and utilizing the Pine Script language for customized technical analysis. Let's break down the key concepts discussed:

  1. Extended Hours Sessions:

    • Extended hours sessions include both pre-market and post-market data, providing a more comprehensive view of a security's price movement.
    • Regular sessions, on the other hand, exclude pre-market and post-market data.
  2. Accessing Extended Hours Sessions in TradingView:

    • To access extended hours sessions on TradingView, right-click on a chart and navigate to Settings → Symbol → Extended Hours (Intraday only).
  3. Pine Script and Security Function:

    • Pine scripts, which are used for custom technical analysis in TradingView, can request additional session data using the security function.
    • The security function is called with a symbol name as its first argument (e.g., "BATS:AAPL"). This retrieves data for the regular session by default.
  4. Requesting Extended Session Data in Pine Script:

    • To obtain extended session data in Pine Script, the tickerid function is introduced.
    • Example 2 demonstrates the use of tickerid to request extended session data. The tickerid function requires the exchange prefix, ticker, and session type as arguments.
  5. Tickerid Function:

    • The tickerid function is used to build the first argument for the security function.
    • It takes the exchange prefix, ticker, and session type as arguments. The session type can be either session.extended or session.regular.
  6. Examples of Pine Script:

    • Example 1 illustrates obtaining data for the regular session using the security function directly.
    • Example 2 shows how to use tickerid to request extended session data and fill gaps in the plot.
    • Example 3 provides an alternative way to obtain regular session data using tickerid.
    • Example 4 demonstrates obtaining data for the same session type as the chart's main symbol, either by omitting the third argument or using syminfo.session.

This breakdown covers the core concepts discussed in the provided TradingView article, showcasing the utilization of Pine Script for accessing and manipulating different session data.

Extended and regular sessions — Pine Script User Manual 4 documentation (2024)
Top Articles
Latest Posts
Article information

Author: Nathanial Hackett

Last Updated:

Views: 6143

Rating: 4.1 / 5 (72 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Nathanial Hackett

Birthday: 1997-10-09

Address: Apt. 935 264 Abshire Canyon, South Nerissachester, NM 01800

Phone: +9752624861224

Job: Forward Technology Assistant

Hobby: Listening to music, Shopping, Vacation, Baton twirling, Flower arranging, Blacksmithing, Do it yourself

Introduction: My name is Nathanial Hackett, I am a lovely, curious, smiling, lively, thoughtful, courageous, lively person who loves writing and wants to share my knowledge and understanding with you.