簡體   English   中英

自上次策略退出訂單以來的 PineScript 時間暫停訂單

[英]PineScript time pause from orders since last strategy exit order

我想在我的策略達到止損或獲利后延遲 1 小時。 這是一個不起作用的例子,你能解釋一下為什么或者弄清楚嗎? 交易視圖上的 PineScript v5



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()

我試過 function barssince 或 strategy.closedtrades

要暫停 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 ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM