Skip to content

003 — Price data and series

Trading charts are built from bars. Pine Script gives you direct access to each bar’s market data.

Built-in Meaning
open Opening price
high Highest price
low Lowest price
close Closing or current price
volume Reported volume

These values are series. Their value can change from one bar to the next.

Use square brackets to access an earlier bar:

close // Current bar's close
close[1] // Previous bar's close
close[2] // Close two bars ago

The number inside the brackets is the historical offset.

Calculate close-to-close change in basis points

Section titled “Calculate close-to-close change in basis points”

One basis point is 0.01%, so 100 basis points equal 1%.

//@version=6
indicator("Close Change in BPS", overlay = false)
float changeBps = (close / close[1] - 1.0) * 10000.0
color barColor = changeBps >= 0 ? color.green : color.red
plot(
changeBps,
"Close change (bps)",
style = plot.style_columns,
color = barColor
)
hline(0, "Zero")
(close / close[1] - 1.0) * 10000.0

Suppose the previous close was 100 and the current close is 101:

(101 / 100 - 1) × 10,000 = 100 bps

The price increased by 1%, which equals 100 basis points.

color barColor = changeBps >= 0 ? color.green : color.red

This uses the ternary operator:

condition ? value_when_true : value_when_false

Green is selected when the change is zero or positive; otherwise red is selected.

On the first available chart bar, close[1] does not exist. Calculations depending on it return na, meaning “not available.” This is normal. The plot begins when enough historical data exists.