Removes a label from the chart, and does nothing when the handle is na or already deleted.
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
label.delete(id: series label) -> void
label.delete() -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series label | required | The 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()orarray.pop()as well. - On Sidechair: a deleted label leaves
label.allstraight away, and the method form tag.delete() does the same aslabel.delete(tag).
Examples
//@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)//@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