Moves a label up or down to a new price, keeping its bar where it is.
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
label.set_y(id: series label, y: series int/float) -> void
label.set_y(y: series int/float) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series label | required | The label that moves up or down. Its bar position stays as it was. |
| y | series int/ | required | The 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
//@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