Ждите после стратегии. Выход - PullRequest
1 голос
/ 16 мая 2019

После того, как стратегия была остановлена ​​(выход), я хотел бы подождать, прежде чем заключить новую сделку.

Я пытался использовать 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)

1 Ответ

0 голосов
/ 17 мая 2019

Попробуйте это.

//@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)
...