Sidechair

label.delete()

Browse the reference

Removes a label from the chart, and does nothing when the handle is na or already deleted.

Try it in the editor

The label disappears at once and the variable that held it keeps a handle that no longer draws anything. Deleting an already deleted label, or na, does nothing, so a replace-the-label pattern needs no guard on the first bar.

Pair it with a var variable to replace a label each bar: delete the old one, then create the new one. To keep the last few labels instead of one, store them in an array and delete the one that leaves it.

Syntax

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

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label to remove from the chart. Passing na, or a label that is already gone, does nothing.

Returns

Nothing.

Remarks

  • Deleting does not free the slot in an array that stores the label; call array.remove() or array.pop() as well.
  • On Sidechair: a deleted label leaves label.all straight away, and the method form tag.delete() does the same as label.delete(tag).

Examples

Pine ScriptOnly the latest cross is labelledOpen in editor
//@version=6
indicator("label.delete: replace", overlay = true)
var label last = na
if ta.crossover(close, ta.sma(close, 20))
    label.delete(last)
    last := label.new(bar_index, low, "cross", style = label.style_label_up, color = color.teal)
Pine ScriptKeep the last three crossesOpen in editor
//@version=6
indicator("label.delete: rolling window", overlay = true)
var array<label> marks = array.new<label>()
if ta.crossunder(close, ta.sma(close, 20))
    marks.push(label.new(bar_index, high, "x", style = label.style_label_down, color = color.red))
    if marks.size() > 3
        label.delete(marks.shift())

See also

Runs on Sidechair