I created an indicator in Pinescript 5 with an array that I'm looping through to draw lines at the array values as well as a label for the line, however, when the chart moves to a new bar the label writes over the previous label and makes it illegible. I added a line to delete the previous label, but it's not working.
//Allows user to hide values
showTPOrth = input(true, "Show TPO RTH")
tpoRTHlevels = array.new_float(5)
array.set(tpoRTHlevels,0,5278)
array.set(tpoRTHlevels,1,5337)
array.set(tpoRTHlevels,2,5378)
array.set(tpoRTHlevels,3,5441)
array.set(tpoRTHlevels,4,5479)
if barstate.islast
if showTPOrth
for k = 0 to array.size(tpoRTHlevels) - 1level_2 = array.get(tpoRTHlevels, k)
Draw horizontal line
line.new(x1=bar_index, y1=level_2, x2=bar_index + 1, y2=level_2, extend=extend.right, color=close_price > level_2 ? #1bb622 : #cf2020, width=1)
Add a label to display the value
l=label.new(bar_index + 4, level_2, text=str.tostring(level_2), textcolor=#666666, style=label.style_label_lower_left)
label.delete(l[1]
Any help is appreciated!
I created an indicator in Pinescript 5 with an array that I'm looping through to draw lines at the array values as well as a label for the line, however, when the chart moves to a new bar the label writes over the previous label and makes it illegible. I added a line to delete the previous label, but it's not working.
//Allows user to hide values
showTPOrth = input(true, "Show TPO RTH")
tpoRTHlevels = array.new_float(5)
array.set(tpoRTHlevels,0,5278)
array.set(tpoRTHlevels,1,5337)
array.set(tpoRTHlevels,2,5378)
array.set(tpoRTHlevels,3,5441)
array.set(tpoRTHlevels,4,5479)
if barstate.islast
if showTPOrth
for k = 0 to array.size(tpoRTHlevels) - 1level_2 = array.get(tpoRTHlevels, k)
Draw horizontal line
line.new(x1=bar_index, y1=level_2, x2=bar_index + 1, y2=level_2, extend=extend.right, color=close_price > level_2 ? #1bb622 : #cf2020, width=1)
Add a label to display the value
l=label.new(bar_index + 4, level_2, text=str.tostring(level_2), textcolor=#666666, style=label.style_label_lower_left)
label.delete(l[1]
Any help is appreciated!
Try this method:
//@variable Efficient label
var efficientLabel = label.new(na, na, text = _txt, color = color(na), textcolor = chart.fg_color)
if barstate.islast
label.set_xy(efficientLabel, _x, _y)