无法关闭策略

时间:2021-04-07 18:32:03

标签: pine-script

无法关闭策略。只是想在SMA 21交叉SMA 50时做多并在交叉时关闭。

strategy("Strategy1", overlay=true)

longCondition = crossover(sma(close, 21), sma(close, 50))
if (longCondition)  
    strategy.entry("My Long Entry Id", strategy.long)  

strategy.close("Exit", crossunder(sma(close, 21), sma(close, 50)))

1 个答案:

答案 0 :(得分:0)

在使用 strategy.close() 函数时,您需要指定要退出的条目 id。使用与 strategy.entry() 函数中相同的“My Long Entry Id”:

strategy.close("My Long Entry Id", crossunder(sma(close, 21), sma(close, 50)))