TradingView 三种退出策略的冲突

Conflict among three exit strategies in TradingView

我设置了三种退出策略,如下所述。第一个是要使用的主要退出策略。二是突破后利润最大化。第三个仅用于止损。

1.    strategy.close( "Long",when = Close_Condition == true and is_breakthrough == false)  // main exit strategy
2.    strategy.exit("CP","Long", stop = Cut_Profit, when = is_breakthrough == true)  // maximize profit strategy
3.    strategy.exit("CL","Long", stop = Stop_Price)  // cut loss strategy

但是,当整个策略执行时,**止损策略**始终被视为唯一的退出策略。即使满足策略1或策略2的条件,程序也会忽略这两个策略并且程序不会采取任何行动(不能卖出股票)。

如果止损策略被删除,策略1和策略2正常运行并显示预期结果。

那么如何让三种退出策略发挥作用呢?任何帮助,将不胜感激。谢谢。

发生这种情况是因为您的 CL 退出总是在市场上,所以您不能再发送一个订单来平仓。你应该怎么做所以使用strategy.cancel函数取消之前的订单:

// ...some script's logic...
if is_breakthrough
    strategy.cancel("CL") // cancel sent order
    strategy.exit("CP","Long", stop = Cut_Profit) opened a new order on position's close
strategy.exit("CL","Long", stop = Stop_Price)

那么它应该可以工作