为什么在 Tradingview pine script 中策略交易和绘图之间会出现滑动?

Why is there a slip between strategic trading and drawing in Tradingview pine script?

我正在 Tradingview 中编写策略。

回测开仓时,背景色设置为绿色

但是,测试结果和背景位置相差一格。 为什么栏位置不匹配?

这是一个简单的策略,当阳线连续时开仓,当阴线出现时平仓。

//@version=4
strategy("My Strategy", overlay=true)

var isOpenedLong = false

// if continuous positive line
longCondition = open[1] < close[1] and open < close
if (longCondition)
    isOpenedLong := true
    strategy.entry("Long", strategy.long, comment="Open")

// if negative line
closeCondition = open < close
if (closeCondition)
    isOpenedLong := false
    strategy.close("Long", comment="Close")

// Change the background color when the position is open or already open
color currentColor = longCondition or isOpenedLong ? color.green : na
bgcolor(currentColor, transp=80)

结果是这样的。

strategy("My Strategy", overlay=true)替换为strategy("My Strategy", overlay=true,process_orders_on_close = true)