Sidechair

label.set_xy()

Browse the reference

Moves a label to a new bar and a new price in one call.

Try it in the editor

It sets x and y together, which is how a single var label is kept on a moving target: label.set_xy(l, bar_index, high). Separate set_x and set_y calls do the same in two steps.

x is interpreted in the label's current xloc. A label that must follow a swing that is not on the current bar takes the bar from a function such as ta.lowestbars().

Syntax

Pine Script
label.set_xy(id: series label, x: series int, y: series int/float) -> void
label.set_xy(x: series int, y: series int/float) -> void

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label to relocate on both axes. Its text, colors and style are untouched.
xseries intrequiredThe new bar index, or a millisecond timestamp when the label's xloc is xloc.bar_time.
yseries int/floatrequiredThe new price level. Ignored while the label's yloc is yloc.abovebar or yloc.belowbar.

Returns

Nothing.

Example

Pine ScriptMarker that tracks the 50-bar low wherever it sitsOpen in editor
//@version=6
indicator("label.set_xy: rolling low", overlay = true)
var label lo = label.new(bar_index, low, "", style = label.style_label_up, color = color.red)
label.set_xy(lo, bar_index + ta.lowestbars(low, 50), ta.lowest(low, 50))
label.set_text(lo, str.tostring(ta.lowest(low, 50), "#.##"))

See also

Runs on Sidechair