等待 strategy.exit
Wait after strategy.exit
在策略被止损出局(退出)后,我想在进入新交易之前等待。
我尝试使用 barssince 但我找不到满足最后一个退出的条件。
我希望在出场后等待 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)
在策略被止损出局(退出)后,我想在进入新交易之前等待。
我尝试使用 barssince 但我找不到满足最后一个退出的条件。
我希望在出场后等待 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)