Builds an array to hold references to drawn labels, so later bars can recolor, retext or remove them.
Keep every label you create in an array and later bars can edit or remove them. With array.unshift() the newest label sits at index 0 and older ones shift back, which lets a loop treat the oldest labels differently from the newest.
Each item is a reference to a label already drawn. Dropping an item from the array leaves the text on the chart until label.delete() is called, and label.delete() ignores a na slot.
Syntax
array.new_label(size: series int (optional), initial_value: series label (optional)) -> array<label>Arguments
| Name | Type | Default | Description |
|---|---|---|---|
| size | series int | 0 | How many label slots to start with: 0 or more, up to 100,000. Start at 0 and add labels as signals appear. |
| initial_value | series label | na | A label stored in every starting slot, so all slots share one drawing. Leave it out and the slots are na. |
Returns
array<label>: A new array that holds label references, with the requested number of slots, each one na unless initial_value was given.
Remarks
- On Sidechair: labels start with room for 50 per script, raised with max_labels_count up to 500. When a new label pushes the count past that, the oldest label disappears from the chart even if an array still points to it.
Example
//@version=6
indicator("array.new_label: fade older tags", overlay = true)
var tags = array.new_label()
if ta.crossover(close, ta.sma(close, 20))
array.unshift(tags, label.new(bar_index, low, "up", style = label.style_label_up, color = color.green, textcolor = color.white))
if array.size(tags) > 1
for i = 1 to array.size(tags) - 1
label.set_color(array.get(tags, i), color.gray)
if array.size(tags) > 4
label.delete(array.pop(tags))
plot(array.size(tags), "Tags kept", display = display.data_window)See also
Runs on Sidechair