'How to position label.new() more specific, vertically? V5
Solution 1:[1]
When you don't specify the yloc argument of label.new(), it will use the price you pass in the second argument -which in your case is high. That's why the label points exactly to the high price.
You can use the yloc argument with something like yloc.abovebar (lbl_red below) or you can use a mathematical formula together with the price (lbl_green below).
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vitruvius
//@version=5
indicator("My script", overlay=true)
is_red = close < open
is_green = not is_red
_atr = ta.atr(10) / 4
var label lbl_red = na
var label lbl_green = na
if (barstate.islast)
lbl_red := label.new(bar_index, high, "Test", yloc=yloc.abovebar, color=color.red, style=label.style_label_down, textcolor=color.white)
lbl_green := label.new(bar_index, low - _atr, "Test", color=color.green, style=label.style_label_up, textcolor=color.white)
label.delete(lbl_red[1])
label.delete(lbl_green[1])
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | vitruvius |


