Home » Symbol Information Functions » Accessing Chart Information in Pine Script

Accessing Chart Information in Pine Script

Photo of author
Published on


In the realm of financial scripting and technical analysis, Pine Script stands out as a powerful tool for creating customized indicators and strategies. Pine Script, especially in its latest iteration – Version 5, offers a range of built-in variables that empower scripts to access and manipulate chart-related data effectively. This article focuses on leveraging Pine Script Version 5 to access essential chart information, which includes:

Each of these elements plays a crucial role in crafting insightful and dynamic trading scripts. Let’s dive into the specifics of each and explore how to harness them in your Pine Script coding.

Prices and Volume

Accessing Price Data

In Pine Script, accessing price data is straightforward, thanks to predefined variables. These variables represent the open, high, low, and close prices of the chart’s bars. The syntax for these variables in Version 5 is as follows:

  • openPrice for the opening price
  • highPrice for the highest price
  • lowPrice for the lowest price
  • closePrice for the closing price
indicator("Price Data Example", overlay=true)
plot(openPrice, color=color.green, title="Open Price")
plot(highPrice, color=color.red, title="High Price")
plot(lowPrice, color=color.blue, title="Low Price")
plot(closePrice, color=color.orange, title="Close Price")
Prices and Volume

Accessing Volume Data

Similarly, accessing volume data is made easy with a dedicated variable:

  • chartVolume for the volume of the trading symbol
indicator("Volume Data Example", overlay=true)
plot(chartVolume, color=color.purple, title="Volume")
Accessing Volume Data

Symbol Information

Gaining insights into the symbol (e.g., stock, currency pair, etc.) that the script is analyzing is crucial for contextual understanding. Pine Script provides the syminfo prefix to access this data:

  • syminfo.tickerid for the symbol’s ticker ID
  • syminfo.description for the symbol’s description
indicator("Symbol Information Example", overlay=true)
label.new(bar_index, high, text=syminfo.tickerid + "\n" + syminfo.description, color=color.fuchsia)
Symbol Information

Chart Timeframe

The timeframe of the chart is another critical piece of information. Pine Script offers a simple way to access this:

  • timeframe.period to get the current chart timeframe
indicator("Timeframe Example", overlay=true)
label.new(bar_index, high, text="Timeframe: " + timeframe.period, color=color.navy)
Chart Timeframe

Session Information

Session information pertains to the specific trading times of the symbol. This can be accessed using:

  • session.ismarket to check if the market is open
  • session.regular for regular trading hours
indicator("Session Information Example", overlay=true)

// Define a boolean variable to check if the current bar is in the regular session
isRegularSession = not na(time(timeframe.period, session.regular))

// Use bgcolor to indicate if the market is open, with updated transparency handling
openMarketColor = session.ismarket ? color.new(color.green, 90) : color.new(color.red, 90)

// Use plotchar to indicate regular session
plotchar(isRegularSession, title="Regular Session", location=location.top, char='R', color=color.blue)
Session Information

Key Features and Takeaways:

  • Version 5 Upgrade: Make sure your scripts are using Pine Script Version 5 for these features.
  • Price and Volume Data: Easily accessible with predefined variables like openPrice, highPrice, lowPrice, closePrice, and chartVolume.
  • Symbol Information: Access symbol details using syminfo.tickerid and syminfo.description.
  • Chart Timeframe: Determine the chart’s timeframe with timeframe.period.
  • Session Information: Understand market sessions with variables like session.ismarket and session.regular.

Leave a Comment