首页 > 解决方案 > Pine 回测,如果已经打开了一个新交易,则不会打开一个新交易

问题描述

标题说明了一切,这是我的代码。

strategy.entry("Short", strategy.short, comment="InsBarSE")
        strategy.exit("Short", loss=200, profit=200, when=exit_long)

strategy.entry("Long", strategy.long, comment="InsBarLE")
        strategy.exit("Long", loss=200, profit=200, when=exit_short)

很多时候,空头交易会自动关闭多头交易,我不希望这种情况发生,我希望他们一直走下去,直到达到盈利或亏损,请帮助。

标签: pine-script

解决方案


您没有使用该from_entry=参数进行strategy.exit()调用,因此他们正在退出任何未平仓交易。有关详细信息,请参阅裁判员。您的代码应如下所示:

strategy.entry("Short", strategy.short, comment="InsBarSE")
        strategy.exit("Exit Short", "Short", loss=200, profit=200, when=exit_long)

strategy.entry("Long", strategy.long, comment="InsBarLE")
        strategy.exit("Exit Long", "Long", loss=200, profit=200, when=exit_short)

推荐阅读