pine-scriptpine-script-v5trendline

How to move x and y location for label.new in pinescript?


I am looking to move these labels away from the price action as they are getting in the way. I cant seem to move them by changing the label options? enter image description here

    label.delete(rsidown)
yrsil = al*bar_index + bl
rsidown := label.new(bar_index, yrsil, text=str.tostring(yrsil, "#.####"), 
color=color.red, style=label.style_text_outline, yloc=yloc.price)
label.delete(rsiup)
yrsih = ah*bar_index + bh
rsiup := label.new(bar_index, yrsih, text=str.tostring(yrsih, "#.####"), 
color=color.green, style=label.style_text_outline, yloc=yloc.price)

Solution

  • For the high label, you can detect the highest bar from 10 bar before and then print your label to this price so that no overlap occurs.
    Then, do the same for your lowest label.

    label.delete(rsiup)
    HighPlace = ta.highest(10)
    yrsih = ah*bar_index + bh
    rsiup := label.new(bar_index, HighPlace, text=str.tostring(yrsih, "#.####"), color=color.green, style=label.style_label_down, yloc=yloc.price)
    
    label.delete(rsidown)
    LowPlace = ta.lowest(10)
    yrsil = al*bar_index + bl
    rsidown := label.new(bar_index, LowPlace, text=str.tostring(yrsil, "#.####"), color=color.red, style=label.style_label_up, yloc=yloc.price)
    

    Which will place you label away from bars. enter image description here