如何使条件取决于交易执行

How to make condition dependent on trade execution

我想让我的脚本依赖于正在执行的 strategy.entry。有人知道怎么做吗?

我的代码:

buy = crossover(delta, 0)

milliseconds_in_xdays = 1000 * 60 * 60 * 24 * 15

lastTrade = na
closetrd = time >= (lastTrade[15] + milliseconds_in_xdays)

if (buy)
    strategy.entry("Long", strategy.long, comment="Long")
    ***if( strategy.long = true)*** NEED HELP HERE
        lastTrade := time

if (closetrd)
    strategy.close("Long")
    lastTrade := na

正如您在我的第一个 if 中看到的那样,我正在设置时间并尝试在 15 天后平仓。我希望仅在输入我的 "long" 策略时设置时间。现在它在满足任何买入条件后 15 天关闭交易。我不想要这个,因为我的传销已关闭。

有什么想法吗?

谢谢!

万一有人想知道这还不存在,交易视图正在努力实现一个函数,该函数将 return 自上次输入以来的天数。

使用:

barssince(change(strategy.position_size) > 0) == 15

作为条件。