Sidechair

label.set_yloc()

Browse the reference

Switches a label between sitting at a price and hugging the bar's high or low.

Try it in the editor

yloc.price puts the label at its y value. yloc.abovebar and yloc.belowbar keep it next to the bar's high or low regardless of y, which avoids overlapping candles.

Choose per label from the bar's direction: under up bars, over down bars. The stored y is kept, so switching back to yloc.price restores the old height.

Syntax

Pine Script
label.set_yloc(id: series label, yloc: series string) -> void
label.set_yloc(yloc: series string) -> void

Arguments

NameTypeDefaultDescription
idseries labelrequiredThe label whose vertical placement mode changes. Its stored price is kept.
ylocseries stringrequiredyloc.price places the label at its y value. yloc.abovebar and yloc.belowbar pin it just off the bar's high or low and ignore y.

Returns

Nothing.

Remarks

  • On Sidechair: yloc.abovebar and yloc.belowbar follow the bar's high and low only when the script is an overlay. In a script with its own pane the label stays at its y.

Example

Pine ScriptUnder up bars, over down barsOpen in editor
//@version=6
indicator("label.set_yloc: by direction", overlay = true)
if bar_index % 3 == 0
    l = label.new(bar_index, close, close >= open ? "up" : "dn", color = close >= open ? color.green : color.red)
    label.set_yloc(l, close >= open ? yloc.belowbar : yloc.abovebar)

See also

Runs on Sidechair