Pine script TradingView Pinescript,为什么不是';在这个绘图示例中,三元运算符是否工作?
我在pinescript中有一个非常简单的策略Pine script TradingView Pinescript,为什么不是';在这个绘图示例中,三元运算符是否工作?,pine-script,Pine Script,我在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 = cross
//@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)
...
我想画一条值为0或1的线,这取决于位置大小是否为0
...
x = strategy.position_size == 0 ? 0 : 1
plot(x)
但是,打印x的结果是一条仅为值1的线。在图表上
这清楚地表明,在某些情况下,没有位置是开放的。因此
变量position\u size
在某些点应为0,但它似乎只有1。
为什么会这样?你的策略从多头转向空头,并在第一次交易后一直处于有利位置。请参阅附带的屏幕截图。
您应该使用策略。退出
或策略。关闭
功能在相反方向信号出现之前退出位置
例如:
// Exit long after 2 candles from the entry
exitLong = nz(longCondition[2])
if exitLong
strategy.close("My Long Entry Id", exitLong)
你的策略从多头转向空头,并在第一次交易后一直处于有利位置。请参阅附带的屏幕截图。
您应该使用策略。退出
或策略。关闭
功能在相反方向信号出现之前退出位置
例如:
// Exit long after 2 candles from the entry
exitLong = nz(longCondition[2])
if exitLong
strategy.close("My Long Entry Id", exitLong)
非常感谢。真不敢相信我错过了这个。谢谢,非常感谢。真不敢相信我错过了这个。非常感谢。