Sidechair

label.set_y()

Browse the reference

Moves a label up or down to a new price, keeping its bar where it is.

Try it in the editor

The price is only honoured when the label's yloc is yloc.price, the default. A label set to yloc.abovebar or yloc.belowbar follows its bar instead.

The x stays fixed, so the label can anchor to the bar where an event began while its height follows something that keeps changing, such as a run-up high.

Syntax

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

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label that moves up or down. Its bar position stays as it was.
yseries int/floatrequiredThe new price level. It has no visible effect while the label's yloc is yloc.abovebar or yloc.belowbar.

Returns

Nothing.

Remarks

  • On Sidechair: the stored y is still updated for a pinned label, and label.get_y() returns it even though the label is drawn off the bar.

Example

Pine ScriptA run-up label that climbs to the highest high since the crossOpen in editor
//@version=6
indicator("label.set_y: climbing peak", overlay = true)
var label peak = na
if ta.crossover(close, ta.sma(close, 20))
    peak := label.new(bar_index, high, "run-up", style = label.style_label_down, color = color.green)
if not na(peak)
    label.set_y(peak, math.max(label.get_y(peak), high))

See also

Runs on Sidechair