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

应在strategy.entry之后等待strategy.exit
EN

Stack Overflow用户
提问于 2021-01-09 22:27:52
回答 1查看 139关注 0票数 0

我有一个脚本,这应该是每5分钟调用一次。在strategy.entry之后,应该等待30秒,并检查是否可以取消。

我的脚本看起来是这样的,但它并不像我希望的那样工作。

代码语言:javascript
复制
//@version=4
strategy("My Strategy", overlay=true)


// create a variable with time of exit
timeLong = 0.0
timeLong := nz(timeLong[1])

msToHours(timeMs) =>
    timeMs / 1000 

isMoreThan() =>
    msToHours(time - timeLong) >= 30

// detect the exit
if strategy.position_size < strategy.position_size[1]
    timeLong := time
    
if (time >  timestamp(2021, 1, 9, 00, 00) )
    strategy.entry("Long Entry", strategy.long, comment="Long")


// === STRATEGY RISK MANAGEMENT EXECUTION ===
// finally, make use of all the earlier values we got prepped
if  isMoreThan()
    strategy.close("Long Entry", comment="Exit")
    timeLong := na

提前感谢

Gül

EN

回答 1

Stack Overflow用户

发布于 2021-01-14 22:58:39

谢谢你的回答,我改变了我的代码,

代码语言:javascript
复制
Thanks for your answer, i changed my code, 
//@version=4
strategy("My Strategy", overlay=true, calc_on_every_tick = true)


// create a variable with time of long start
timeLong = 0.0
timeLong := nz(timeLong[1])

msToSeconds(timeMs) =>
    timeMs / 1000 

isMoreThan() =>
    msToSeconds(timenow - timeLong) >= 30

if (timenow >  timestamp(2021, 1, 9, 00, 00) ) and strategy.position_size == 0
    strategy.entry("Long Entry", strategy.long, comment="Long")
    timeLong := timenow


   
if  isMoreThan() and strategy.position_size > 0
    strategy.close("Long Entry", comment="Exit")
    timeLong := na   

但它并不像我希望的那样工作,它不会在卖和买之间等待30秒。

我把我的警报截图发给你,

screenshot from alert

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65643772

复制
相关文章

相似问题

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