[英]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.