Sidechair

label.get_x()

Browse the reference

Returns a label's x coordinate: a bar index, or a millisecond timestamp for a label placed by time.

Try it in the editor

The scale matches the label's xloc. A label on xloc.bar_index gives a bar index you can subtract from bar_index; one on xloc.bar_time gives a timestamp you compare with time.

Reading it after label.set_x() or label.set_xloc() returns the new value, so it is also how a script learns where a label that other code moved ended up.

Syntax

Pine Script
label.get_x(id: series label) -> series int
label.get_x() -> series int

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label whose x coordinate is read. A bar index for xloc.bar_index labels, a timestamp for xloc.bar_time ones.

Returns

series int: The label's x coordinate.

Remarks

  • On Sidechair: a na label gives na, and the number is returned exactly as stored, with no rounding to a whole bar.

Example

Pine ScriptDelete labels once they are 50 bars oldOpen in editor
//@version=6
indicator("label.get_x: expire old labels", overlay = true)
var array<label> tags = array.new<label>()
if bar_index % 15 == 0
    tags.push(label.new(bar_index, high, str.tostring(bar_index), style = label.style_label_down))
if tags.size() > 0 and bar_index - label.get_x(tags.first()) > 50
    label.delete(tags.shift())

See also

Runs on Sidechair