简体   繁体   中英

TradingView Pine-Script: Plot a line only if a input is true

I want to plot some EMAs only if a input is true.. however when i use the if functions, it says "Cannot use 'plot' in local scope."

 //@version=4 study(title = "Todos os indicadores", overlay = true) showemas = input(false, title = "Show EMAs") if showemas == true plot(ema(close, length1), color=#F44336, linewidth=2, title="EMA 1") plot(ema(close, length2), color=#4CAF50, linewidth=2, title="EMA 1") plot(ema(close, length3), color=#673AB7, linewidth=2, title="EMA 1") plot(ema(close, length4), color=#2196F3, linewidth=2, title="EMA 1") plot(ema(close, length5), color=color.white, linewidth=2, title="EMA 1") plot(sma(close, length6), color=color.orange, linewidth=2, title="EMA 1")

You need to put the condition in the plot() calls:

plot(showemas ? ema(close, length1) : na, color=#F44336, linewidth=2, title="EMA 1")
plot(showemas ? ema(close, length2) : na, color=#4CAF50, linewidth=2, title="EMA 1")
plot(showemas ? ema(close, length3) : na, color=#673AB7, linewidth=2, title="EMA 1")
plot(showemas ? ema(close, length4) : na, color=#2196F3, linewidth=2, title="EMA 1")
plot(showemas ? ema(close, length5) : na, color=color.white, linewidth=2, title="EMA 1")
plot(showemas ? sma(close, length6) : na, color=color.orange, linewidth=2, title="EMA 1")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM