DSL Series¶
Series are arrays of values calculated across candles.
Built-In Candle Series¶
| Series | Description |
|---|---|
open |
Candle open price |
high |
Candle high price |
low |
Candle low price |
close |
Candle close price |
volume |
Candle volume |
bid |
Live bid price, falls back to close on history |
ask |
Live ask price, falls back to close on history |
time |
Candle timestamp from history/live bar bucket. Falls back to bar index when missing. |
Assigning Series¶
ma = ta.sma(close, 20)
History Access¶
Use [n] to access previous values.
previousClose = close[1]
previousMa = ma[1]
History offsets must be nonnegative safe integers. close[0] reads the current bar; close[barIndex] reads the first loaded bar. Negative, fractional and non-finite offsets are rejected; an offset before the loaded history yields a missing value. Future candles cannot be read.
Bar state and missing values¶
| Value/function | Meaning |
|---|---|
barIndex |
Zero-based index in the loaded calculation history, not an exchange-wide ID |
isClosed |
All indicator candles except the last are closed. In a robot onBar snapshot, the last bar is also closed |
na |
Missing numeric value (NaN) |
na(value) |
Checks null, undefined or a non-finite number |
nz(value, replacement) |
Replaces a missing/non-finite value; the optional second positional argument defaults to 0 |
Unavailable feed volume is null; it is never substituted with a price. Use nz(volume) or explicitly disable volume weighting. The parser has no true/false literals; use 0/1 for flags. Named replacement=... is not accepted by nz.
script("Closed bars", kind="indicator")
previous = nz(close[1], close)
confirmed = isClosed ? previous : na
plot(confirmed)
Named scalar arrays¶
Arrays retain values across bars within a single replay and are rebuilt for every evaluation, including each robot event. They do not persist across live updates, restarts or reloads. They are not series and have no Pine array<T> type declaration.
| Call | Result |
|---|---|
array.size("zones") |
Entry count; creates an empty named array if absent |
array.get("zones", index) |
Stored scalar; null for an absent entry at a valid index |
array.set("zones", index, value) |
Assigned value; index must already exist |
array.push("zones", value) |
New length |
array.remove("zones", index) |
Removed scalar; index must already exist |
Arguments are positional. Names match [A-Za-z][A-Za-z0-9_]{0,63}. Indices are integers 0..255. Values may be finite numbers, booleans, null/missing values (stored as null), or strings up to 256 UTF-16 units. Limits: 64 arrays, 256 entries per array and 4096 entries in total; invalid mutations stop evaluation. Calls may appear in expressions or statements, including loops.
script("Recent highs", kind="indicator")
if isClosed {
array.push("highs", high)
if array.size("highs") > 20 { array.remove("highs", 0) }
}
count = array.size("highs")
plot(count)