pine-scriptpine-script-v5pine-script-v4

Deletion of labels not working in Pine script


var label H1 = na
var label H2 = na
var label H3 = na
t1 = time('0930', session.extended)  // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter

//plot(t, style=linebr) // debug
is_first = na(t1[1]) and not na(t1) or t1[1] < t1
day_high = float(na)
day_low = float(na)

if is_first and barstate.isconfirmed
    day_high := high1
    day_low := low1
    day_low
else
    day_high := day_high[1]
    day_low := day_low[1]
    day_low

if high1 > day_high
    day_high := high1
    day_high
    H1 := label.new(x=bar_index, y=high+30, text="", color=color.white, style=label.style_label_down, size = size.tiny)
    //line.new(bar_index + 25, high[0], bar_index, high[0], extend = extend.none, color = color.white, width = 3, style=line.style_solid)
    alert("EF",alert.freq_once_per_bar_close)
if low1 < day_low and support<0 and wt2 > -50
    day_low := low1
    day_low
    H2 := label.new(x=bar_index, y=low-30, text="", color=color.white, style=label.style_label_up, size = size.tiny)
    //line.new(bar_index + 25, low[0], bar_index, low[0], extend = extend.none, color = color.white, width = 3, style=line.style_solid)
    alert("GH",alert.freq_once_per_bar_close)

//plot(day_high, color=color.new(color.black, 0))
//plot(day_low, color=color.new(color.black, 0))

//--------------------------------------------------------------------------------------------------------
t2 = time('0930', session.extended)  // 1440=60*24 is the number of minutes in a whole day. You may use "0930-1600" as second session parameter
is_first1 = na(t2[1]) and not na(t2) or t2[1] < t2

DAY_HIGH10 = float(na)
DAY_LOW10 = float(na)

if is_first1 and barstate.isconfirmed
    DAY_HIGH10 := HIGH10
    DAY_LOW10 := LOW10
    DAY_LOW10
else
    DAY_HIGH10 := DAY_HIGH10[1]
    DAY_LOW10 := DAY_LOW10[1]
    DAY_LOW10

if HIGH10 > DAY_HIGH10 
    DAY_HIGH10 := HIGH10
    DAY_HIGH10
    H1 := label.new(x=bar_index, y=high+30, text="", color=color.black, style=label.style_label_down, size = size.tiny)
    //line.new(bar_index + 25, high[0], bar_index, high[0], extend = extend.none, color = color.black, width = 3, style=line.style_solid)
    //alert("AB",alert.freq_once_per_bar_close)

if LOW10 < DAY_LOW10 
    DAY_LOW10 := LOW10
    DAY_LOW10
    H2 := label.new(x=bar_index, y=low-30, text="", color=color.black, style=label.style_label_up, size = size.tiny)
    //line.new(bar_index + 25, low[0], bar_index, low[0], extend = extend.none, color = color.black, width = 3, style=line.style_solid)
    //alert("CD",alert.freq_once_per_bar_close)


[Labels Image link below]
(https://i.sstatic.net/CQqMn.jpg)

Hello Team, I am comparing two stocks and I need to delete balck labels. However I cant find a way to delete black color labels highlighted in the attached image.The black labeles are overlaping white labels.

I tried label.delete

Can soemone please guide me here?

Thanks, Mayur


Solution

  • Your labels have the same name. You should change the name of your black labels to something else, perhaps 'B1' & 'B2' and then use the the label.delete() in this block and the block below it.

    if HIGH10 > DAY_HIGH10 
        B1.delete()
        DAY_HIGH10 := HIGH10
        DAY_HIGH10
        B1 := label.new(x=bar_index, y=high+30, text="", color=color.black, style=label.style_label_down, size = size.tiny)