PINE v5 - 有条件绘图
当有“ Na”值时,我无法在Pine V5上有条件地绘制。
//@version=5
strategy("Discontinuous plots v5", "", true)
atr = ta.atr(7)
longCondition = ta.crossover(ta.sma(close, 100), ta.sma(close, 200))
long_stop_level = float(na)
long_profit_level = float(na)
long_stop_level := longCondition ? low - atr : long_stop_level[1]
long_profit_level := longCondition ? close + atr : long_profit_level[1]
if (longCondition)
strategy.entry("Long Entry", strategy.long)
strategy.exit("TP/SL", "Long Entry", stop= low - atr, limit= close + atr)
shortCondition = ta.crossunder(ta.sma(close, 100), ta.sma(close, 200))
short_stop_level = float(na)
short_profit_level = float(na)
short_stop_level := shortCondition ? high + atr : short_stop_level[1]
short_profit_level := shortCondition ? close - atr : short_profit_level[1]
if (shortCondition)
strategy.entry("Short Entry", strategy.short)
strategy.exit("TP/SL", "Short Entry", stop= high + atr, limit= close - atr)
plot(strategy.position_size <= 0 ? na : long_stop_level, color=color.new(#FF0000, 70), linewidth=2)
plot(strategy.position_size <= 0 ? na : long_profit_level, color=color.new(#008000, 70), linewidth=2)
plot(strategy.position_size >= 0 ? na : short_stop_level, color=color.new(#FF0000, 70), linewidth=2)
plot(strategy.position_size >= 0 ? na : short_profit_level, color=color.new(#008000, 70), linewidth=2)
转换为V3的相同代码结构如下所示:
//@version=3
strategy("Discontinuous plots", "", true)
atr = atr(7)
longCondition = crossover(sma(close, 100), sma(close, 200))
long_stop_level = na
long_profit_level = na
long_stop_level := longCondition ? low - atr : long_stop_level[1]
long_profit_level := longCondition ? close + atr : long_profit_level[1]
if (longCondition)
strategy.entry("Long Entry", strategy.long)
strategy.exit("TP/SL", "Long Entry", stop= low - atr, limit= close + atr)
shortCondition = crossunder(sma(close, 100), sma(close, 200))
short_stop_level = na
short_profit_level = na
short_stop_level := shortCondition ? high + atr : short_stop_level[1]
short_profit_level := shortCondition ? close - atr : short_profit_level[1]
if (shortCondition)
strategy.entry("Short Entry", strategy.short)
strategy.exit("TP/SL", "Short Entry", stop= high + atr, limit= close - atr)
plot(strategy.position_size <= 0 ? na : long_stop_level, color=red, style=linebr, linewidth=2)
plot(strategy.position_size <= 0 ? na : long_profit_level, color=green, style=linebr, linewidth=2)
plot(strategy.position_size >= 0 ? na : short_stop_level, color=red, style=linebr, linewidth=2)
plot(strategy.position_size >= 0 ? na : short_profit_level, color=green, style=linebr, linewidth=2)
我听说已计划的参数列表的扩展名是计划的,但我找不到任何解决方法。
有可解决方法吗?
I'm unable to plot conditionally on Pine v5 when there is a 'na' value.
//@version=5
strategy("Discontinuous plots v5", "", true)
atr = ta.atr(7)
longCondition = ta.crossover(ta.sma(close, 100), ta.sma(close, 200))
long_stop_level = float(na)
long_profit_level = float(na)
long_stop_level := longCondition ? low - atr : long_stop_level[1]
long_profit_level := longCondition ? close + atr : long_profit_level[1]
if (longCondition)
strategy.entry("Long Entry", strategy.long)
strategy.exit("TP/SL", "Long Entry", stop= low - atr, limit= close + atr)
shortCondition = ta.crossunder(ta.sma(close, 100), ta.sma(close, 200))
short_stop_level = float(na)
short_profit_level = float(na)
short_stop_level := shortCondition ? high + atr : short_stop_level[1]
short_profit_level := shortCondition ? close - atr : short_profit_level[1]
if (shortCondition)
strategy.entry("Short Entry", strategy.short)
strategy.exit("TP/SL", "Short Entry", stop= high + atr, limit= close - atr)
plot(strategy.position_size <= 0 ? na : long_stop_level, color=color.new(#FF0000, 70), linewidth=2)
plot(strategy.position_size <= 0 ? na : long_profit_level, color=color.new(#008000, 70), linewidth=2)
plot(strategy.position_size >= 0 ? na : short_stop_level, color=color.new(#FF0000, 70), linewidth=2)
plot(strategy.position_size >= 0 ? na : short_profit_level, color=color.new(#008000, 70), linewidth=2)
Same code structure converted to v3 works like a charm, as follows:
//@version=3
strategy("Discontinuous plots", "", true)
atr = atr(7)
longCondition = crossover(sma(close, 100), sma(close, 200))
long_stop_level = na
long_profit_level = na
long_stop_level := longCondition ? low - atr : long_stop_level[1]
long_profit_level := longCondition ? close + atr : long_profit_level[1]
if (longCondition)
strategy.entry("Long Entry", strategy.long)
strategy.exit("TP/SL", "Long Entry", stop= low - atr, limit= close + atr)
shortCondition = crossunder(sma(close, 100), sma(close, 200))
short_stop_level = na
short_profit_level = na
short_stop_level := shortCondition ? high + atr : short_stop_level[1]
short_profit_level := shortCondition ? close - atr : short_profit_level[1]
if (shortCondition)
strategy.entry("Short Entry", strategy.short)
strategy.exit("TP/SL", "Short Entry", stop= high + atr, limit= close - atr)
plot(strategy.position_size <= 0 ? na : long_stop_level, color=red, style=linebr, linewidth=2)
plot(strategy.position_size <= 0 ? na : long_profit_level, color=green, style=linebr, linewidth=2)
plot(strategy.position_size >= 0 ? na : short_stop_level, color=red, style=linebr, linewidth=2)
plot(strategy.position_size >= 0 ? na : short_profit_level, color=green, style=linebr, linewidth=2)
I heard that an extension to the argument list to plot()'s display parameter is planned, but I could not find any workaround.
Is there a workaround available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)