> ## Documentation Index
> Fetch the complete documentation index at: https://gocharting.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# How to keep drawings under the limit

> Keeping the newest N boxes, lines or labels in an array and deleting the oldest, and raising the limit with max_boxes_count and its siblings.

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.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Last 20 wide-bar boxes", overlay=true, max_boxes_count=100)
static array<box> boxes = array.new<box>(0)
if barstate.isconfirmed and high - low > talib.sma(high - low, 20) * 1.5 {
    array.push(boxes, box.new(bar_index, high, bar_index + 1, low, bgcolor=color.new(color.orange, 0.2)))
    if array.length(boxes) > 20 {
        box.delete(array.shift(boxes))
    }
}
```

`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

| Kind | Default | Set with | Highest |
| - | - | - | - |
| lines | 50 | `max_lines_count` | 500 |
| labels | 50 | `max_labels_count` | 500 |
| boxes | 50 | `max_boxes_count` | 500 |
| polylines | 50 | `max_polylines_count` | 100 |
| linefills | 50 | none | 50 |
| tables | 9 | none | 9 (one per position) |

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](https://gocharting.com/docs/scripting/how-to/keep-one-label-that-moves.md)) 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

> [!WARNING]
>
> 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.
>
> ```lipi-invalid theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
> //@lipi=2
> indicator("Variable limit", overlay=true, max_boxes_count=input.int(100, "Boxes"))
> plot(close)
> ```

The editor's check reports it. See [Lines, labels, boxes and polylines](https://gocharting.com/docs/scripting/chart-output/drawings.md),
[Limits](https://gocharting.com/docs/scripting/distribution/limits.md) and [Arrays](https://gocharting.com/docs/scripting/language/arrays.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.