简体   繁体   English

Pine-script SECURITY 函数不会返回一致的结果

[英]Pine-script SECURITY function doesn't return consistent result

In order to backtest one of the strategy, I need to retrieve day HIGH value for last 5 days and this should work under any chart resolution.为了回测其中一个策略,我需要检索过去 5 天的日高值,这应该适用于任何图表分辨率。

Below code works fine when the chart resolution is DAILY, but if I change the chart resolution to a lower timeframe ie 15mins or 30 mins I get same day high values for Day-2,3,4 & 5.当图表分辨率为 DAILY 时,下面的代码工作正常,但如果我将图表分辨率更改为较低的时间范围,即 15 分钟或 30 分钟,我会在第 2、3、4 和 5 天获得同一天的高值。

Ideally, Security functions output should not be impacted by change in chart resolution and output should be distinct values.理想情况下,安全功能输出不应受到图表分辨率变化的影响,并且输出应该是不同的值。

// @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)

You need to call security() function for each of your variables.您需要为每个变量调用security()函数。

You can read How to avoid repainting when using security() - PineCoders FAQ for more details.您可以阅读如何在使用 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)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM