[英]TradingView Pinescript, why isn't the ternary operator working in this plot example?
我在 pinescript 中有一个非常简单的策略。
//@version=4
strategy("My Strategy", overlay=true)
longCondition = crossover(sma(close, 14), sma(close, 28))
if (longCondition)
strategy.entry("My Long Entry Id", strategy.long)
shortCondition = crossunder(sma(close, 14), sma(close, 28))
if (shortCondition)
strategy.entry("My Short Entry Id", strategy.short)
...
我想 plot 一行值为 0 或 1,具体取决于 position 大小是否为 0。
...
x = strategy.position_size == 0 ? 0 : 1
plot(x)
然而,绘制 x 的结果是一条仅在值 1 处的线。在图表上它清楚地显示在某些点上没有开仓。 因此,变量position_size
在某些时候应该为 0,但它似乎只有 1。为什么会这样?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.