Returns a label's x coordinate: a bar index, or a millisecond timestamp for a label placed by time.
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
label.get_x(id: series label) -> series int
label.get_x() -> series intArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series label | required | The 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
//@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