首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在strategy.exit之后等待

在strategy.exit之后等待
EN

Stack Overflow用户
提问于 2019-05-17 03:40:56
回答 1查看 833关注 0票数 1

在策略停止(退出)后,我想在进入新交易之前等待。

我试着使用but,但是我找不到一个满足最后一个退出的条件。

我希望在退出发生后等待4个小时才能进入一个新的交易。

代码语言:javascript
复制
//@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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-05-18 00:05:00

尝尝这个。

代码语言:javascript
复制
//@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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56175557

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档