The type behind every drawn rectangle: a handle to one box that a script can resize, recolor, copy and delete.
A variable of type box holds a handle to one rectangle on the chart, not the rectangle's numbers. Assigning it to a second variable gives two names for the same box, so an edit through either shows on both. Use box.copy() when you need an independent twin.
Declare an empty handle with box zone = na and fill it from box.new() when a setup appears. Boxes also fit in arrays made with array.new_box and in the fields of a user-defined type, which is how a script tracks many zones at once.
Each box has left and right edges on the time axis, top and bottom edges as prices, a fill, an outline and optional text. One box.set_* function changes each property, and a box.get_* function reads each of the four edges.
Remarks
- max_boxes_count in indicator() sets the cap: 50 by default, 500 at most. Drawing one more box removes the oldest.
- On Sidechair: a box removed by the cap or by
box.delete()still answers the box.get_* readers with the edges it had, and setters called on na are skipped without an error. - On Sidechair:
box.alllists the boxes currently on the chart in creation order, oldest first.
Example
//@version=6
indicator("box type: range box", overlay = true)
var box rng = na
if barstate.islast
if na(rng)
rng := box.new(bar_index - 20, ta.highest(high, 20), bar_index, ta.lowest(low, 20), bgcolor = color.new(color.blue, 85))
else
box.set_lefttop(rng, bar_index - 20, ta.highest(high, 20))
box.set_rightbottom(rng, bar_index, ta.lowest(low, 20))See also
Runs on Sidechair