The type of an ordered list of values that all share one type, such as array<float> or array<string>.
An array holds items in order and grows or shrinks while the script runs. Declare one with the generic form, array<float> prices = array.new<float>(), or let the type come from the creating function: array.new_float(), array.from(1, 2, 3).
Items are read and written by index. Indexes start at 0, and in Pine v6 a negative index counts back from the end. An array lives across bars only when it is declared with var; without var, a new empty array is built on every bar.
Remarks
- Arrays are reference types: assigning one to a second variable shares the same list, and
array.copy()makes an independent one. - An array holds at most 100,000 items.
- Keep rolling windows in a var array; an array created without var is rebuilt empty on every bar.
Example
//@version=6
indicator("Array type: last 5 closes", overlay = true)
var array<float> window = array.new<float>()
array.push(window, close)
if array.size(window) > 5
array.shift(window)
plot(array.avg(window), "Average of last 5")See also
Runs on Sidechair