Sidechair

array.new_linefill()

Browse the reference

Builds an array to hold references to line fills, kept beside the lines each fill joins.

Try it in the editor

A linefill paints the band between two existing lines. Keep each fill in an array beside the lines it joins, so one loop can recolor or retire a pair.

linefill.get_line1() and linefill.get_line2() return the two lines of any stored fill. Slots begin as na, and the array holds references only, so a fill stays until linefill.delete() is called.

Syntax

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

Arguments

NameTypeDefaultDescription
sizeseries int0How many fill slots to start with: 0 or more, up to 100,000. Start at 0 and unshift each fill as it is created.
initial_valueseries linefillnaA linefill stored in every starting slot. Leave it out and the slots are na until a fill is set into them.

Returns

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

Example

Pine ScriptRecolor the newest fill by candle directionOpen in editor
//@version=6
indicator("array.new_linefill: newest fill", overlay = true)
var fills = array.new_linefill()
if bar_index % 50 == 0
    top = line.new(bar_index, high, bar_index + 20, high)
    bot = line.new(bar_index, low, bar_index + 20, low)
    array.unshift(fills, linefill.new(top, bot, color.new(color.blue, 85)))
if array.size(fills) > 0
    newest = array.get(fills, 0)
    linefill.set_color(newest, close > open ? color.new(color.green, 80) : color.new(color.red, 80))
if array.size(fills) > 3
    linefill.delete(array.pop(fills))
plot(close)

See also

Runs on Sidechair