> ## 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.

# Lines, labels, boxes and polylines

> Creating, changing and deleting lines, labels, boxes, polylines and linefills, positioning them with bars, times and chart points, and the limits on how many a script keeps.

A drawing is an object placed on the chart: a `line`, `label`, `box`, `polyline` or `linefill` (and a [`table`](https://gocharting.com/docs/scripting/chart-output/tables)).
Unlike a plot, a drawing can be created on some bars only, inside `if`, loops and functions, at positions you compute.

## Create

| Call | Draws |
| - | - |
| `line.new(x1, y1, x2, y2, xloc, extend, color, style, width, forceOverlay)` | a line segment |
| `label.new(x, y, text, xloc, yloc, color, style, textcolor, size, textalign, tooltip, ...)` | text at a point |
| `box.new(left, top, right, bottom, border_color, border_width, border_style, extend, xloc, bgcolor, text, ...)` | a rectangle |
| `polyline.new(points, curved, closed, xloc, line_color, fill_color, line_style, line_width, force_overlay)` | a path through an `array<chartPoint>` |
| `linefill.new(line1, line2, color)` | the area between two lines |

`x` values are bar indexes (`bar_index`) by default, or times in milliseconds with `xloc=xloc.bar_time`; `y` values are prices.
`extend` is `extend.none`, `left`, `right` or `both`. Styles are constants: `line.style_solid`, `dashed`, `dotted`, `arrow_left`,
`arrow_right`, `arrow_both`; `label.style_label_up`, `label_down`, `label_left`, `label_right`, `label_center`, `arrowup`,
`arrowdown`, `circle`, `square`, `diamond`, `flag`, `cross` and others.

```lipi wrap theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Swing high markers", overlay=true)
if high == talib.highest(high, 10) {
    line.new(bar_index, high, bar_index + 10, high, color=color.red, style=line.style_dashed)
    label.new(bar_index, high, str.tostring(high), style=label.style_label_down, textcolor=color.white, color=color.red)
}
```

The overlay argument is `force_overlay` on every call except `line.new`, which spells it `forceOverlay`. The other spelling is refused (The `line.new()` function does not accept a named argument `force_overlay`.).

## Change and delete

Lines, labels and boxes have `set_*` functions (`line.set_xy2`, `label.set_text`, `label.set_style`, `box.set_right`, `line.set_color`, ...) and `get_*` readers
(`line.get_y1`, `label.get_x`, ...); a linefill has `linefill.set_color`. Call them as functions or as methods: `line.set_color(l, c)` and `l.set_color(c)` are the same,
except that `line.set_xloc(l, xloc.bar_time, time, time + 1)` is a function only: the method `l.set_xloc(...)` takes just the `xloc`.
A polyline has no setters or getters: delete it and create a new one. `delete` removes any drawing, and `copy` (`line`, `label` and `box`) makes a new one with the same properties. There is no field
access: `l.x` is refused.

To update one drawing on later bars, keep it in a `static` variable, so it survives from bar to bar:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Highest high so far", overlay=true)
static line hiLine = line.new(bar_index, high, bar_index + 1, high, extend=extend.right, color=color.orange)
if high > line.get_y1(hiLine) {
    line.set_xy1(hiLine, bar_index, high)
    line.set_xy2(hiLine, bar_index + 1, high)
}
```

To keep many, push them into an `array<line>` (or `label`, `box`) and delete the oldest, as in [Arrays](https://gocharting.com/docs/scripting/language/arrays.md).

`linefill.new` shades between two lines; keep the `talib` calls outside the `if`:

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Range shading", overlay=true)
hi = talib.highest(high, 20)
lo = talib.lowest(low, 20)
if barstate.islast {
    top = line.new(bar_index - 19, hi, bar_index, hi, color=color.red)
    bottom = line.new(bar_index - 19, lo, bar_index, lo, color=color.green)
    linefill.new(top, bottom, color.new(color.blue, 0.85))
}
```

## Chart points and polylines

A `chartPoint` holds a time, a bar index and a price. Build one with `chartPoint.from_index(index, price)`,
`chartPoint.from_time(time, price)`, `chartPoint.new(time, index, price)` or `chartPoint.now(price)`. `line.new`, `box.new` and
`label.set_point` have forms that take points. `polyline.new` takes an array of at most 1000 of them (more, or none, gives `na`); fill it with `array.push`, because
`array.from` does not accept chart points.

```lipi theme={"languages":{"custom":["/languages/lipi.json","/languages/lipi-invalid.json"]}}
//@lipi=2
indicator("Up-close path", overlay=true)
static array<chartPoint> pts = array.new<chartPoint>(0)
if close > open {
    array.push(pts, chartPoint.from_index(bar_index, close))
    if array.length(pts) > 500 {
        array.shift(pts)
    }
}
if barstate.islast and array.length(pts) > 1 {
    polyline.new(pts, line_color=color.blue)
}
```

## How many a script keeps

`indicator()` and `strategy()` take `max_lines_count`, `max_labels_count`, `max_boxes_count` and `max_polylines_count` (`const`
integers): 50 of each kind by default, 500 at most (100 for polylines; see [Limits](https://gocharting.com/docs/scripting/distribution/limits.md)). Linefills stay at 50 and tables at 9.

When a kind goes a few above its limit, the oldest drawings of that kind are deleted until the limit is met. A line, label, box or
linefill that a `static` variable holds directly is never deleted this way; drawings held only in an array, and polylines, are, so keep
an array no longer than the limit. Raise the limit when the script needs more drawings on the chart: `indicator("Many levels", overlay=true, max_lines_count=500)`.


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