State
A cell holds one value, read and written through
.value:
state.bar is rolled back before every update of the forming bar, the update always starts from the last closed bar and nothing is counted twice. Use state.live only for something that should count every update, such as how many updates a bar received.
Lists and maps
state.list<T>(capacity) and state.map<T>(capacity) hold numbers, booleans, strings or null, up to 100,000 entries. A map is keyed by strings. Size them for what they will hold: adding past the capacity stops the script with OX2004, so shift a list’s oldest entry before it fills.
'live'.
Series
series(lookback) is a number with history: set the current bar’s value, then read value, or ago(n) for n bars back, up to the declared lookback (at most 5,000).
chart.ago(n) is the bar n bars ago.
Tallies
A tally sums what event handlers add during one bar:add in onTrade or onLiquidation, read value (and count) in the chart’s handlers. It empties on each new bar and never rolls back, so each trade counts once even while the bar is forming.
tallyBy(capacity) keeps a sum per key, such as per taker order or per wallet, up to 10,000 keys; read it with get(key) or entries(). Keys past its capacity are dropped for the rest of the bar.
Indicators
ta.* creates an indicator instance at the top; update feeds it a value and returns the result. Values match TradingView’s built-ins, including their seeds and how they treat na.
- Update on every bar. An instance advances only when
updateruns, so updating it inside anifgives a different result. This is Pine’s rule that every call keeps its own history, made visible. - One instance per use. Two RSIs of different sources are two instances.
valueis the result of the latest update in this run;confirmedis the value as of the stream’s last closed bar, for reading from another stream’s handler.