【问题标题】:Pine-script SECURITY function doesn't return consistent resultPine-script SECURITY 函数不返回一致的结果
【发布时间】:2019-09-10 16:34:59
【问题描述】:

为了回测其中一个策略,我需要检索过去 5 天的 day HIGH 值,这应该适用于任何图表分辨率。

当图表分辨率为 DAILY 时,以下代码可以正常工作,但如果我将图表分辨率更改为较低的时间范围,即 15 分钟或 30 分钟,我会在第 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)

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    您需要为每个变量调用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)
    

    【讨论】:

    • 由于我需要为每个变量调用安全函数,有没有办法将这些变量的值存储到数组中?
    • pinescript 中没有数组。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多