如何知道在 strategy.entry 的时间将止损设置在激活柱低位?

How to know the time at strategy.entry to set stop loss at the activation bar LOW?

我正在尝试使用 strategy.entrystrategy.exit 编写策略。我想将买入头寸的止损设置在激活我的 ENTRY 的柱线的低点。为此,我认为最好的方法是获取入场时间,然后用它来获取当时柱线的最低价。 目前我写的代码是这个:


start = timestamp(2018, 01, 01, 0, 0, 0)

entrada_long = elder_bulls and time > start // and (close >= high[1]*1.0015)
entrada_short = elder_bears and time > start

strategy.entry("buy", true, comment = tostring(high[0]*1.0015), stop = high[0]*1.0015,  when = entrada_long)
strategy.cancel("buy", when = not entrada_long) 

take_level = strategy.position_avg_price * 1.1
strategy.exit("exit_buy", "buy", limit = take_level, stop = low[0]*0.9985, qty_percent = 100, comment = tostring(low[0]*0.9985))

使用内置变量 strategy.position.avg_price 我能够知道入场价格并用它来计算我在 strategy.exit 的获利,我想我需要类似的东西来知道时间在 ENTRY,但我找不到它。我的代码是止损的方式就像一个追踪止损,总是移动到下一个柱线的低点,我想将止损固定在激活我的策略的柱线的低点。

非常感谢

您已经有一个布尔值可以触发您的输入。
您可以使用 valuewhen() 函数来获取输入栏的 low
可以看到使用此函数的示例 here

或者,您可以在激活触发器时将柱线的低点保存在 var 变量中。
来自 manual:

The var keyword is a special modifier that instructs the compiler to create and initialize the variable only once. This behavior is very useful in cases where a variable’s value must persist through the iterations of a script across successive bars.