Pine 脚本 - 无法用我的逻辑编写 Strategy.exit

Pine Script - Unable to write a Strategy.exit with my logic

我尝试在 Pine 编辑器中编写策略脚本。

我是 Pine 新手。下面是我的代码。有人可以指出什么是错的吗?

    Short = ( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) )
    if ( Short )
        Target = high[1] - low[1]
        Loss = high[1] - low[1]
        strategy.entry("Enter Short", strategy.short, 1, when = window() )
        strategy.exit("Enter Short", "Enter Short", stop=Loss, limit=Target, when = window())

根据 pine 脚本手册: when (bool) 可选参数。订单状况。如果条件为 'true',则下订单。如果条件为'false',则什么也不会发生(先前下的具有相同ID的订单不会被取消)。默认值为 'true'。 所以我认为你还没有满足条件window()。请改用 strategy.close()。

回答

Target = valuewhen(( ( close[1] > open[1] ) and ( high < high[1] ) and ( close < low[1] ) ), high[1] - low[1], 0 )

strategy.exit("Enter Short", "Enter Short", stop=strategy.position_avg_price+Target, limit=strategy.position_avg_price-Target, when = window())