Switches a label between sitting at a price and hugging the bar's high or low.
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
label.set_yloc(id: series label, yloc: series string) -> void
label.set_yloc(yloc: series string) -> voidArguments
| Name | Type | Default | Description |
|---|---|---|---|
| id | series label | required | The label whose vertical placement mode changes. Its stored price is kept. |
| yloc | series string | required | yloc.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.abovebarandyloc.belowbarfollow 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
//@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