Series, state and history

Every top level let and var is a series. The script executes once per bar, oldest to newest, and stores one value per bar. Function parameters and function local declarations are plain scalars for that call and have no history.

FormMeaning
let name: type = expressionRecomputed on every bar and immutable.
var name: type = expressionInitialised on the first bar, then carries its previous value forward.
name := expressionUpdates a top level var, or a local inside a function or loop body.
name += expressionShort for name := name + expression. -=, *= and /= work the same way.
name[offset]The value offset bars back. 0 is the current bar, 1 the previous one.

The history offset must be a whole number from 0 through 200,000. It may be computed. Reading before the first bar gives nan.

var cumulative: float = 0
cumulative := nz(cumulative[1], 0) + tape.delta()

let previous_close: float = close[1]
let gap: float = open - close[1]

Chart globals

NameTypeMeaning
openfloatBar open.
highfloatBar high.
lowfloatBar low.
closefloatBar close, and the current price on the forming bar.
volumefloatBar volume.
timefloatBar start, epoch milliseconds.
time_endfloatBar end, epoch milliseconds.
bar_indexintPosition of the bar in the loaded window, starting at 0.
bar_countintHow many bars this run received.
last_barboolTrue only on the newest bar in the window. This is how a drawing is pinned to the right edge.
is_formingboolTrue on the bar the chart is still building, which is the newest bar of the window.
nanfloatThe absent numeric value. na is the same value.
hl2float(high + low) / 2
hlc3float(high + low + close) / 3
ohlc4float(open + high + low + close) / 4
hlcc4float(high + low + close + close) / 4

Globals carry history too, so close[1], high[3] and hlc3[2] are valid. A script that declares its own series, function, parameter or local named hl2, hlc3, ohlc4, hlcc4 or na keeps its own meaning for that name everywhere in the script. They work on every bar type the chart offers, including range, volume, tick, delta and seconds bars, because a script receives bars rather than a chart type.

Every layer of the market, Orderflow to optionflow, on one chart.

Institutional grade Orderflow data with backtesting and journaling built in. Join the waitlist for early access.

Get Access