Language
Arrays, matrices and maps
Collections of values: rolling windows with arrays, grids with matrices, and lookups with maps. Up to 100,000 elements each.
Arrays#
An array holds a list of one type. Declare it with var so it survives between bars, otherwise you get a new empty array every bar.
//@version=6indicator("Rolling median of ranges")var array<float> ranges = array.new<float>()ranges.push(high - low)if ranges.size() > 50 ranges.shift()plot(ranges.median(), "Median range", color = color.orange)plot(high - low, "Range", color = color.new(color.gray, 50), style = plot.style_columns)The pattern above is a rolling window: push the newest, shift the oldest once it is long enough.
Common functions: push, pop, shift, unshift, get, set, size, sum, avg, median, max, min, stdev, sort, includes, indexof, slice, join. The full list is in the reference.
Matrices#
A two-dimensional grid: matrix.new<float>(rows, columns, initial), then get, set, row, col, transpose, mult and more.
Maps#
Key-value lookups: map.new<string, float>(), then put, get, contains, remove, keys, values.
var map<string, float> levels = map.new<string, float>()levels.put("high", ta.highest(high, 20))levels.put("low", ta.lowest(low, 20))plot(levels.get("high"))Limits#
Arrays, matrices and tables hold at most 100,000 elements; asking for more stops the script with "The requested size exceeds the 100000 element limit". Index out of range is a runtime error naming the line.