0 plot if-statement pine-script
我只想在输入为真时绘制一些 EMA。但是,当我使用 if 函数时,它显示“无法在本地范围内使用‘plot’”。
//@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")Run Code Online (Sandbox Code Playgroud)
您需要将条件放入调用中plot():
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")
Run Code Online (Sandbox Code Playgroud)