sammyp
sammyp

Reputation: 21

How can a label be deleted if the condition becomes false

If my condition is true and plot a label to the chart but it should become false if the next bars high is higher then the high of the bar where the condition is true.

the condtion should plot a label if bear is true, but when the next bar is higher it should delete the label. Also I want that the label, if its true it will be true for 5 candles and in this period it shouldn't plot another label. the (for i = 1 to 4) is working but it calculates from the wrong bar because the script didn't delete the false bar label that became untrue.

bearlabel = if bear == true
    myLabel1 = label.new(x=bar_index, y=high, color=color.rgb(255, 82, 82, 49), text= "S", textcolor=color.white, style=label.style_label_down, size=size.tiny) 

if bear[1] == true and high[1] < high
    label.delete(bearlabel)

for i = 1 to 4
    if bear[i] == true
        label.delete(bearlabel)

If I use bear1 I think it takes the wrong label. So how can I get the high of the conditions Bar to check if the new high is higher?

if bear[1] == true and high[1] < high
    label.delete(bearlabel)

enter image description here

Upvotes: 2

Views: 1460

Answers (1)

G.Lebret
G.Lebret

Reputation: 3108

To delete a label, you must use the name of this label.
here in your code the label name is myLabel1 :

myLabel1 = label.new(x=bar_index, y=high, color=color.rgb(255, 82, 82, 49), text= "S", textcolor=color.white, style=label.style_label_down, size=size.tiny) 

So you must use myLabel1 to delete it :

label.delete(myLabel1)

Upvotes: 2

Related Questions