Sidechair

array.new_line()

Browse the reference

Builds an array to hold references to drawn lines, so later bars can stretch, recolor or delete them.

Try it in the editor

Keeping each line you draw in an array lets a later bar find it again. Push every line.new() result, then loop over the array to extend the right end, change colors or delete lines you no longer need.

Slots left without a starting line are na, and line.delete() quietly skips a na slot. The array holds references only, so clearing or shrinking it leaves the lines on the chart until each one is deleted.

Syntax

Pine Script
array.new_line(size: series int (optional), initial_value: series line (optional)) -> array<line>

Arguments

NameTypeDefaultDescription
sizeseries int0How many line slots to start with: 0 or more, up to 100,000. Most scripts start at 0 and push each new line.
initial_valueseries linenaA line stored in every starting slot, so all slots point at one drawing. Leave it out for na slots.

Returns

array<line>: A new array that holds line references, with the requested number of slots, each one na unless initial_value was given.

Remarks

  • On Sidechair: a script draws 50 lines unless indicator() sets max_lines_count, which is capped at 500. Past the limit the oldest line leaves the chart, although an array still holds its reference.

Example

Pine ScriptStretch pivot levels to the latest barOpen in editor
//@version=6
indicator("array.new_line: stretch levels", overlay = true, max_lines_count = 100)
var levels = array.new_line()
ph = ta.pivothigh(high, 5, 5)
if not na(ph)
    array.push(levels, line.new(bar_index - 5, ph, bar_index, ph, color = color.orange))
    if array.size(levels) > 8
        line.delete(array.shift(levels))
for lv in levels
    line.set_x2(lv, bar_index)
plot(array.size(levels), "Lines held", display = display.data_window)

See also

Runs on Sidechair