Re-aims a label's x at a bar index or a timestamp, setting the position and the scale together.
The x and xloc arguments are taken together, because a bar index and a timestamp are not interchangeable numbers. label.set_xloc(l, time, xloc.bar_time) pins the label to a moment in time.
A time-based x can be worked out from bar duration: add a few bar lengths to time and the label lands ahead of the latest bar, whatever the chart timeframe.
Syntax
label.set_xloc(id: series label, x: series int, xloc: series string) -> void
label.set_xloc(x: series int, xloc: series string) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series label | required | The label whose x position and x scale are both replaced. Its price stays as it was. |
| x | series int | required | The x value in the new scale: a bar index for xloc.bar_index, or a millisecond timestamp such as time for xloc.bar_time. |
| xloc | series string | required | xloc.bar_index to read x as a bar index, or xloc.bar_time to read it as a timestamp. It replaces the label's current setting. |
Returns
Nothing.
Remarks
- On Sidechair: the x and the xloc are written in one call, and
label.get_x()afterwards returns the value in the new scale.
Example
//@version=6
indicator("label.set_xloc: future by time", overlay = true)
var label l = label.new(bar_index, close, "+5 bars", style = label.style_label_left)
if not na(time[1])
label.set_xloc(l, time + 5 * (time - time[1]), xloc.bar_time)
label.set_y(l, close)See also
Runs on Sidechair