Spiralman
Spiralman

Reputation: 5

Can't apply Label.delete function

I tried using label.delete function:

if (longsignal and showpos)
l3 = label.new(time + 10*dt, low, xloc=xloc.bar_time, text = 'SL='+tostring(longsl), color=#02ad09, style=label.style_labelup, textcolor=color.white, size=size.normal)
label.delete(l3[1])

But i have this error:

Undeclared identifier 'l3'

I even tried to add ":= "after "l3" instead of a "=" but stil get different error:

Mismatched input 'l3' expecting 'end of line without line continuation'.

I suspect it has to do with IF condition i used before label creation.... :(

Upvotes: 0

Views: 170

Answers (2)

e2e4
e2e4

Reputation: 3828

You are declaring the variable in the local scope, this could cause the issue.

In the example below the label variable is declared in the global scope, then use := to re-assign the value in the local scope.

var label l3 = na
if (longsignal and showpos)
    l3 := label.new(time + 10*dt, low, xloc=xloc.bar_time, text = 'SL='+tostring(longsl), color=#02ad09, style=label.style_labelup, textcolor=color.white, size=size.normal)
    label.delete(l3[1])

Upvotes: 0

AnyDozer
AnyDozer

Reputation: 2568

lines inside the condition must be shifted by 4 spaces or 1 shift

if (longsignal and showpos)
    l3 = label.new(time + 10*dt, low, xloc=xloc.bar_time, text = 'SL='+tostring(longsl), color=#02ad09, style=label.style_labelup, textcolor=color.white, size=size.normal)
    label.delete(l3[1])

when the condition is met for the first time there is no label l3[1]

Upvotes: 0

Related Questions