Skip to main content
A script may hold only so many drawings of each kind at once, and the oldest are deleted when it goes past the limit. To decide which ones go, keep the drawings in an array and delete the oldest yourself once the array holds more than you want.
array.push adds the newest box at the end; array.shift removes and returns the oldest, which box.delete removes from the chart. The same pattern works for line and label arrays.

The limits

These are arguments of indicator and strategy. A value above the highest is clamped, not refused; zero or a negative value gives the default. They must be constants: an input is refused. When a kind goes a few over its limit, the oldest drawings of that kind are deleted until the count is back at the limit. A line, label, box or linefill held directly in a static variable (as in How to keep one label that moves) is skipped and never trimmed, but a drawing held only inside an array is not protected. Keep your array’s cap at or below the limit, as above, so that your own deletion always comes first and the array never holds a drawing the script has already lost.

The mistake to avoid

Setting the limit from an input. The compiler says: Cannot call indicator with argument max_boxes_count=input.int(100,"Boxes"). An argument of input int type was used but a const int is expected.
The editor’s check reports it. See Lines, labels, boxes and polylines, Limits and Arrays.