Sidechair

line.delete()

Browse the reference

Takes a line off the chart and frees its place in the drawing limit.

Try it in the editor

The line vanishes at once and drops out of line.all. The variable that held it still points at the old object, and deleting it again, or deleting na, does nothing.

To keep one line on the chart at a time, delete the previous line before creating the next. Deleting lines that have grown stale also keeps a script clear of the max_lines_count cap.

Syntax

Pine Script
line.delete(id: series line) -> void
line.delete() -> void

Arguments

NameTypeDefaultDescription
idseries linerequiredThe line to remove from the chart. na is accepted and nothing happens.

Returns

Nothing.

Remarks

Example

Pine ScriptDelete lines older than 120 barsOpen in editor
//@version=6
indicator("line.delete: expire old lines", overlay = true)
if bar_index % 10 == 0
    line.new(bar_index, close, bar_index + 8, close, color = color.blue)
for ln in line.all
    if line.get_x1(ln) < bar_index - 120
        line.delete(ln)

See also

Runs on Sidechair