Sidechair

array.new_box()

Browse the reference

Builds an array to hold references to drawn boxes, so later bars can extend, recolor or retire each zone.

Try it in the editor

One box per zone, kept in an array, lets a script extend each zone while it is valid and retire it once price breaks through. Slots without a starting box hold na.

Removing a box from the array does not erase it: the rectangle stays at its last size. That is how a script freezes a finished zone while it stops updating it.

Syntax

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

Arguments

NameTypeDefaultDescription
sizeseries int0How many box slots to start with: 0 or more, up to 100,000. Zones are usually pushed one at a time, so 0 is the common start.
initial_valueseries boxnaA box stored in every starting slot, so all slots share one rectangle. Leave it out and the slots are na.

Returns

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

Remarks

  • On Sidechair: boxes use the same default of 50 per script as lines and labels, and max_boxes_count raises it to 500 at most. Once a new box goes past the limit, the oldest one is the first to go.

Example

Pine ScriptExtend zones until a close breaks themOpen in editor
//@version=6
indicator("array.new_box: zones until broken", overlay = true)
var live = array.new_box()
if bar_index % 25 == 0
    array.push(live, box.new(bar_index, high, bar_index + 1, low, border_color = color.teal, bgcolor = color.new(color.teal, 85)))
if array.size(live) > 0
    for i = array.size(live) - 1 to 0
        zone = array.get(live, i)
        if close < box.get_bottom(zone)
            box.set_bgcolor(zone, color.new(color.red, 80))
            array.remove(live, i)
        else
            box.set_right(zone, bar_index)
plot(array.size(live), "Zones still open", display = display.data_window)

See also

Runs on Sidechair