Arrays
## Arrays
`array<int>`, `array<float>`, `array<bool>`, `array<string>`, `array<color>` and the drawing handles
`array<line>`, `array<box>`, `array<label>` (Pine's `float[]` and `line[]` also work in declarations).
Create with `array.new_float(size, initial_value)` (and new_int, new_bool, new_string, new_color, new_line,
new_box, new_label) or `array.from(1, 2, 3)`. Methods work on arrays: `a.push(x)` is `array.push(a, x)`, also on call
results (`a.slice(0, 3).sum()`).
- `var a = array.new_float(0)` keeps one array across bars; without var a new array is made on every bar.
- Keep the newest n drawings: `lines.push(line.new(...))`, then `if lines.size() > n` `line.delete(lines.shift())`.
- `str.split(s, ",")` gives an `array<string>`; `str.tonumber(e)` reads a number (na if it is none).
- An array value is a handle: `b = a` does not copy (use `a.copy()`). `array<float> a = na` means no array.
- Indexes start at 0; negative indexes count from the end (`a.get(-1)` is the last). An index outside the
array, pop/shift/first/last on an empty array, or a call on an na array stops the script with a runtime
error. Loop over elements with `for v in a` or `for [i, v] in a` (runs zero times on an empty array; the
number of iterations is fixed at loop start, elements pushed in the body are not visited, removing elements
ends the loop early; an na array is a runtime error). With `for i = 0 to a.size() - 1` guard with
`if a.size() > 0` (an empty array would run i = 0, -1).
- sum, avg, min, max, median, stdev, variance skip na elements. `a.sort(order.descending)` sorts in place.
`slice` and `copy` return new arrays (slice is a copy, not a view).
- Not allowed: history of an array (`a[1]`; keep past values in a var array instead), arrays in ta.* functions,
nz or str.tostring (use `a.join(", ")` for text), arrays of arrays, arrays in request.security.
```lynt
indicator("Rolling median and last pivots", overlay=true)
len = input.int(20, "Median length", minval=1)
var window = array.new_float(0)
window.push(close)
if window.size() > len
window.shift()
plot(window.size() == len ? window.median() : na, "Rolling median", color=color.amber)
// the last 5 pivot highs, newest last
var pivots = array.new_float(0)
ph = ta.pivothigh(high, 3, 3)
if not na(ph)
pivots.push(ph)
if pivots.size() > 5
pivots.shift()
plot(pivots.size() > 0 ? pivots.max() : na, "Highest of last 5 pivots", color=color.slate, style=plot.style_stepline)
```