Pine script 在'之后关闭位置;x';天

Pine script 在'之后关闭位置;x';天,pine-script,back-testing,Pine Script,Back Testing,我在pinescript上有一个基本策略,它基于2条移动平均线的交叉进入一个位置。我要做的是: 当交叉发生时,输入长/短交叉(天气为公牛或熊交叉) 3蜡烛后退出位置。 我尝试过函数“barssince”,但我不太擅长编码。 这是我的策略: strategy("MovingAvg2Line Cross", overlay=true, initial_capital=10000) fastLength = input(50) slowLength = input(200) price = close

我在pinescript上有一个基本策略,它基于2条移动平均线的交叉进入一个位置。我要做的是: 当交叉发生时,输入长/短交叉(天气为公牛或熊交叉) 3蜡烛后退出位置。 我尝试过函数“barssince”,但我不太擅长编码。 这是我的策略:

strategy("MovingAvg2Line Cross", overlay=true, initial_capital=10000)
fastLength = input(50)
slowLength = input(200)
price = close

mafast = sma(price, fastLength)
maslow = sma(price, slowLength)

if (crossover(mafast, maslow))
    strategy.entry("MA2CrossLE", strategy.long, comment="MA2CrossLE")

if (crossunder(mafast, maslow))
    strategy.entry("MA2CrossSE", strategy.short, comment="MA2CrossSE") ```

在末尾加上这个。它检测未平仓交易数量的变化,并从那时开始计算交易条数:

strategy.close_all(when = barssince(change(strategy.opentrades)) == 2)

谢谢你,它工作正常,我也注意到交叉进入位置发生1烛光延迟从真正的移动平均线触摸。你知道如何预测它吗请参见
处理订单\u on\u close=true