为了回测其中一种策略,我需要检索最近5天的日高值,并且该值应该在任何图表分辨率下都可以工作。
当图表分辨率为每日时,下面的代码可以正常工作,但是如果我将图表分辨率更改为较低的时间范围(即15分钟或30分钟),则可以获得Day-2、3、4和5的当天最高值。
理想情况下,安全功能输出不应受到图表分辨率更改的影响,并且输出应为不同的值。
// @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)
答案 0 :(得分:0)
您需要为每个变量调用security()
函数。
您可以阅读How to avoid repainting when using security() - PineCoders FAQ了解更多详细信息。
// @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)