自上次策略退出订单以来订单的 PineScript 时间暂停

问题描述 投票:0回答:1

我想在我的策略达到止损或获利后延迟 1 小时。这是一个不起作用的例子,你能解释一下为什么或者弄清楚吗?

xSMA = ta.sma(close, Length)
xHighBand = xSMA + (xSMA * PercentShift / 100)
xLowBand = xSMA - (xSMA * PercentShift / 100)

entershort = close > xHighBand
enterlong = close < xLowBand
//reopenPositionAfter(timeSec) =>
   // if strategy.closedtrades > 0
        //if time - strategy.closedtrades.exit_time(strategy.closedtrades - 1) >= timeSec * 100000
           // strategy.entry("Long", strategy.long)

conditionFilter =  not ta.barssince(ta.change(strategy.closedtrades)) == 5
//barsSinceClosed = strategy.closedtrades > 0 ? bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades - 1) : na
//barsSinceClosed = bar_index - strategy.closedtrades.exit_bar_index(strategy.closedtrades - 1)

isFlat = (strategy.position_size == 0)
    
if (  isFlat and enterlong and  inDateRange and conditionFilter )
    strategy.entry("Long", strategy.long)
if (  isFlat and entershort and  inDateRange and conditionFilter)
    strategy.entry("Short", strategy.short)  

strategy.exit("Long Exit", "Long", profit = close * 0.01 / syminfo.mintick, loss = close * 0.005 / syminfo.mintick)
strategy.exit("Short Exit", "Short", profit = close * 0.01 / syminfo.mintick, loss = close * 0.005 / syminfo.mintick)

plot(xSMA, color=color.green, title="SMA")
plot(xHighBand, color=color.blue, title="High Band")
plot(xLowBand, color=color.blue, title="Low Band")

if (not inDateRange)
    strategy.close_all()

我尝试了函数 Barsince 或 Strategy.Closedtrades

pine-script delay pine-script-v5
1个回答
0
投票

要暂停我的 X 柱策略,我使用以下代码:

var tradesperdus = 0
var tradesgagnes = 0

var index_bar_echec = 0
var cooldown = 8 // Here I want to pause for 8 bars

if strategy.losstrades > tradesperdus // A new LOSS
    tradesperdus := strategy.losstrades
    index_bar_echec := bar_index // I record the position (in bars) of my loss
        
if strategy.wintrades > tradesgagnes // A new WIN
    tradesgagnes := strategy.wintrades
    index_bar_echec := 0

// I can now delay my strategy below if I get a loss before
if bar_index > index_bar_echec + cooldown
    // my strategy here ...
© www.soinside.com 2019 - 2024. All rights reserved.