繁体   English   中英

我对 Pine Script v5 中的“简单”IF 语句有疑问

[英]I have an Issue with "simple" a IF statemente in Pine Script v5

这行代码怎么能正常工作? 我可以在没有 If 语句的情况下使用 plot ,但我希望它只有在满足两个条件时才能使用 plot 。

感谢您的时间!

showMA = input.string(group="GENERAL SETTINGS", title="Moving Averages:", defval="EMA", options=["EMA", "VWAP", "Both", "None"])
show_threeEma = input.bool(group="EMA - Exponensial Moving Average", title="233-EMA", defval=true, inline="ema")

threeEma = 233
ema_space = 4 // Dash Spacing

threeEmaLength = ta.ema(close, threeEma) //233-EMA

If (showMA == "EMA" and show_threeEma or showMA == "Both" and show_threeEma == "Show")
plot(bar_index % ema_space != 0 ? threeEmaLength : na, style=plot.style_linebr, linewidth=2, color=color.new(color.silver, 25), editable=false, title="233-EMA")

您不能在本地 scope 中使用plot()函数。

但是,您可以在plot()调用中将您的条件用作series参数的一部分。 就像你用bar_index % ema_space != 0的那样。

can_show = (showMA == "EMA" and show_threeEma or showMA == "Both" and show_threeEma == "Show")

plot((can_show and (bar_index % ema_space != 0)) ? threeEmaLength : na, style=plot.style_linebr, linewidth=2, color=color.new(color.silver, 25), editable=false, title="233-EMA")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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