我有一个脚本,这应该是每5分钟调用一次。在strategy.entry之后,应该等待30秒,并检查是否可以取消。
我的脚本看起来是这样的,但它并不像我希望的那样工作。
//@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
发布于 2021-01-14 22:58:39
谢谢你的回答,我改变了我的代码,
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秒。
我把我的警报截图发给你,
https://stackoverflow.com/questions/65643772
复制相似问题