How to hide label.new in PineScript?

Viewed 34

Please tell me how to make i_offsetLabel input working? I want to be able to enable/disable this label(Dashboard) in the indicator settings. I mean when i_offsetLabel (false) ->label is not displayed

i_offsetLabel = input(true, "Show Dashboard")

title = "Overview", splitter = "____________", nl = "\n"
string dynamicText = title + nl + splitter + nl
var label id = na
var color Dashboard = #131620
label.delete (id)  // Delete last label .
id := label.new (x=bar_index, y=low + 75, color=Dashboard, style=label.style_label_center, textcolor=color.white)
i_showSignal = input (true , "Show Signals")


//Signals
sigTitle = nl 
trend = ema(close, 200) > ema(close, 34) ? ": ‍ Bearish" : " :  Bullish" 
sigs = i_showSignal ? sigTitle + "Trend" + trend + nl : na


dynamicText := dynamicText + sigs 
label.set_text(id, text=dynamicText)

When I try to build "if construct", pine script gives syntax error.

1 Answers

Just add an if check and don't do anything label related if it is disabled.

i_offsetLabel = input(true, "Show Dashboard")

var label id = na

if (i_offsetLabel)
    label.delete (id)  // Delete last label .
    id := label.new (x=bar_index, y=low + 75, color=Dashboard, style=label.style_label_center, textcolor=color.white)
Related