Built-in Variables

Pine Script gives you a treasure trove of pre-calculated data. Every time your script runs on a bar, dozens of variables are already populated with price data, volume, time information, symbol metadata, and bar state. You do not need to fetch or compute any of this yourself -- it is simply there, ready to use.

Understanding these built-in variables is essential because they form the raw material for every indicator and strategy you will ever build.

OHLCV Data

The most fundamental built-in variables are the five that describe each bar's price action and activity. Every candlestick chart is built from these values.

VariableDescriptionWhen you would use it
openPrice at the start of the barDetecting gaps, calculating candle body direction
highHighest price during the barFinding resistance, measuring volatility
lowLowest price during the barFinding support, measuring volatility
closePrice at the end of the barMost indicators use close as the default input
volumeNumber of shares/contracts tradedConfirming moves, spotting climactic activity

Using OHLCV to analyze candle structure

Let's calculate several properties of each candle to understand what these variables tell us in practice.

Pine Script
//@version=5
indicator("Candle Anatomy", overlay=false)

body = close - open
upperWick = high - math.max(close, open)
lowerWick = math.min(close, open) - low
totalRange = high - low

plot(body, "Body (pos=bullish)", color=body > 0 ? color.green : color.red, style=plot.style_columns)

What happened: We used all four price variables to decompose a candle into its parts. The body is close - open (positive means bullish). The upper wick extends from the higher of close/open to the high. The lower wick extends from the lower of close/open down to the low. These derived values are the basis for pattern recognition.

Continue reading

Sign in or create a free account to unlock Built-in Variables and access the full academy.

Free account · No credit card required