微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

交易视图上时间戳的 Pine 脚本代码不会过滤我希望它查看的日期我该如何调整?

如何解决交易视图上时间戳的 Pine 脚本代码不会过滤我希望它查看的日期我该如何调整?

我正在尝试在交易视图中的 Pinescript 上运行此脚本。但是,当我尝试添加时间戳时,它不起作用。有人可以帮忙吗?

//@version=4
strategy("My Strategy",overlay=true)

start = timestamp(2007,1,0)
end = timestamp(2009,3,31,0)

// Indicators
SMA50 = sma(close,50)
SMA100 = sma(close,100)
rsi = rsi(close,14)
atr = atr(14)

// Crossover conditions 
longCondition = crossover(SMA50,SMA100)

if (longCondition)
    stopLoss = low - atr * 2
    takeProfit = high + atr * 6
    strategy.entry("long",strategy.long,100,when = rsi > 30)
    strategy.exit ("exit","long",stop=stopLoss,limit=takeProfit)
    
    
// Plotting SMAs in the chart.
plot(SMA50)
plot(SMA100,color=color.black)

解决方法

给你:

//@version=4
strategy("My Strategy",overlay=true)

start = input(timestamp("2007-01-01T00:00"),type = input.time)
end = input(timestamp("2009-03-31T00:00"),type = input.time)

// Indicators
SMA50 = sma(close,50)
SMA100 = sma(close,100)
rsi = rsi(close,14)
atr = atr(14)

// Crossover conditions 
longCondition = crossover(SMA50,SMA100)

if (longCondition and time >= start and time <= end)
    stopLoss = low - atr * 2
    takeProfit = high + atr * 6
    strategy.entry("long",strategy.long,100,when = rsi > 30)
    strategy.exit ("exit","long",stop=stopLoss,limit=takeProfit)
    
    
// Plotting SMAs in the chart.
plot(SMA50)
plot(SMA100,color=color.black)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。