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.
| Variable | Description | When you would use it |
|---|---|---|
open | Price at the start of the bar | Detecting gaps, calculating candle body direction |
high | Highest price during the bar | Finding resistance, measuring volatility |
low | Lowest price during the bar | Finding support, measuring volatility |
close | Price at the end of the bar | Most indicators use close as the default input |
volume | Number of shares/contracts traded | Confirming 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.
//@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