Sidechair

label.set_x()

Browse the reference

Moves a label sideways to a new bar or time, keeping its price where it is.

Try it in the editor

The new x is read in the label's current scale, a bar index or a timestamp. The price stays put, so the label slides along a horizontal line.

Pass a value larger than bar_index to push the label ahead of the latest bar. When both coordinates change, label.set_xy() does it in one call.

Syntax

Pine Script
label.set_x(id: series label, x: series int) -> void
label.set_x(x: series int) -> void

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label that moves sideways. Its price, text and look stay as they were.
xseries intrequiredThe new bar index, or a millisecond timestamp when the label's xloc is xloc.bar_time. A value past bar_index lands right of the last bar.

Returns

Nothing.

Remarks

  • On Sidechair: a timestamp later than the last loaded bar is placed ahead of it in steps of the chart's bar length, and one earlier than the first bar sits on the first bar.

Example

Pine ScriptA start-price marker that trails three bars aheadOpen in editor
//@version=6
indicator("label.set_x: trailing marker", overlay = true)
var label axis = label.new(bar_index, close, "start", style = label.style_label_left, color = color.gray)
label.set_x(axis, bar_index + 3)

See also

Runs on Sidechair