首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pine-script安全函数返回的结果不一致

Pine-script安全函数返回的结果不一致
EN

Stack Overflow用户
提问于 2019-09-11 00:35:00
回答 1查看 2.4K关注 0票数 0

为了反向测试其中一个策略,我需要检索过去5天的日高值,这应该在任何图表分辨率下工作。

当图表分辨率为每日时,下面的代码可以很好地工作,但如果我将图表分辨率更改为较低的时间范围,即15分钟或30分钟,我会得到第2、3、4和5天的同一天的最高值。

理想情况下,安全函数输出不应受图表分辨率更改的影响,并且输出应为不同的值。

代码语言:javascript
复制
// @version=4
study("Plot high prices for lat 5 days")

day_high = security(syminfo.tickerid, "D", high, false)
day1 = day_high[1]
day2 = day_high[2]
day3 = day_high[3]
day4 = day_high[4]
day5 = day_high[5]

//Check whether this is the first bar of the day? If yes, display highs for last 5 days
t = time("1440", session.regular)
is_first = na(t[1]) and not na(t) or t[1] < t

if (is_first)  
    label.new(bar_index, na, tostring(day5) + ", " + tostring(day4) + ", " + tostring(day3) + ", " + tostring(day2) + ", " + tostring(day1), style=label.style_cross, yloc=yloc.abovebar)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-09-11 01:36:06

您需要为每个变量调用security()函数。

您可以阅读How to avoid repainting when using security() - PineCoders FAQ了解更多详细信息。

代码语言:javascript
复制
// @version=4
study("Plot high prices for lat 5 days")

day1 = security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on)
day2 = security(syminfo.tickerid, "D", high[2], lookahead = barmerge.lookahead_on)
day3 = security(syminfo.tickerid, "D", high[3], lookahead = barmerge.lookahead_on)
day4 = security(syminfo.tickerid, "D", high[4], lookahead = barmerge.lookahead_on)
day5 = security(syminfo.tickerid, "D", high[5], lookahead = barmerge.lookahead_on)

//Check whether this is the first bar of the day? If yes, display highs for last 5 days
t = time("1440", session.regular)
is_first = na(t[1]) and not na(t) or t[1] < t

if (is_first)  
    label.new(bar_index, na, tostring(day5) + ", " + tostring(day4) + ", " + tostring(day3) + ", " + tostring(day2) + ", " + tostring(day1), style=label.style_cross, yloc=yloc.abovebar)

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

https://stackoverflow.com/questions/57874992

复制
相关文章

相似问题

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