[英]Wait after strategy.exit
在策略停止(退出)后,我想在进入新交易之前等待。
我尝试使用 barsince 但我找不到满足最后一个出口的条件。
我希望在退出发生后等待 4 小时,然后再进入新交易。
//@version=3
strategy("ABC", shorttitle="ABC", initial_capital=1000, commission_type = strategy.commission.percent, commission_value = 0.075, overlay = true, linktoseries = true)
nominal = 1000/close
SL = 0.0
SLold = nz(SL[1])
SL := max(max(max(strategy.position_avg_price,ohlc4)-atr(10)*3, strategy.position_avg_price * 0.96), SLold)
buy = cci(close,40)<50
testPeriodStart = timestamp(2018,2,1,0,0)
if time >= testPeriodStart
strategy.entry("Long", strategy.long, nominal, when = buy)
strategy.exit("Exit", "Long", stop = SL)
plot(SL, color = #006400)
尝试这个。
//@version=3
strategy("ABC", shorttitle="ABC", initial_capital=1000, commission_type = strategy.commission.percent, commission_value = 0.075, overlay = true, linktoseries = true)
nominal = 1000/close
// create a variable with time of exit
timeExit = 0.0
timeExit := nz(timeExit[1])
msToHours(timeMs) =>
timeMs / 1000 / 60 / 60
isMoreThan4H() =>
msToHours(time - timeExit) >= 4
// detect the exit
if strategy.position_size < strategy.position_size[1]
timeExit := time
SL = 0.0
SLold = nz(SL[1])
SL := max(max(max(strategy.position_avg_price,ohlc4)-atr(10)*3, strategy.position_avg_price * 0.96), SLold)
buy = cci(close,40)<50
testPeriodStart = timestamp(2018,2,1,0,0)
if time >= testPeriodStart
strategy.entry("Long", strategy.long, nominal, when = buy and isMoreThan4H()) // Here added a check that is more than 4h since last exit
strategy.exit("Exit", "Long", stop = SL)
plot(SL, color = #006400)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.