You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用TradingView复盘时request.security_lower_tf()函数异常问题咨询

TradingView复盘时request.security_lower_tf()仅获取低时间框架最后一根K线数据的解决办法

复盘模式下,TradingView的request.security_lower_tf()默认仅同步当前主时间框架K线对应的低时间框架最后一根数据,无法自动回溯完整的历史低时间框架序列,这是由复盘时的数据流机制限制导致的。以下是几种可行的解决思路:

  • 启用前瞻合并并手动回溯历史数据
    在调用函数时添加barmerge.lookahead_on参数,结合循环或数组来收集历史低时间框架数据。示例代码:

    // 定义目标低时间框架(示例:主框架为1小时,低框架为15分钟)
    targetLowerTf = "15"
    // 获取当前低框架收盘价,启用前瞻合并
    currentLowerClose = request.security_lower_tf(syminfo.tickerid, targetLowerTf, close, barmerge.lookahead_on)
    
    // 收集过去10根低框架K线的收盘价数据
    var float[] lowerCloseHistory = array.new_float()
    if barstate.islast
        for i = 0 to 10
            array.push(lowerCloseHistory, request.security_lower_tf(syminfo.tickerid, targetLowerTf, close[i], barmerge.lookahead_on))
    

    注意:barmerge.lookahead_on会引入前瞻数据,需确认是否符合你的复盘分析逻辑,避免未来函数干扰结果。

  • 直接切换到低时间框架复盘
    如果无需同时查看主时间框架数据,直接切换到目标低时间框架进行复盘操作,这样能完整查看该框架下的所有历史K线,彻底规避跨时间框架的数据同步限制。

  • 改用request.security()函数
    部分场景下,request.security()在复盘时的历史数据获取表现更稳定,只需明确指定低时间框架即可:

    targetLowerTf = "15"
    lowerClose = request.security(syminfo.tickerid, targetLowerTf, close)
    
    // 复盘模式下针对性收集历史数据
    if barstate.isreplay
        var float[] replayLowerData = array.new_float()
        // 基于已确认K线的数量回溯
        for i = 0 to ta.barssince(barstate.isconfirmed)
            array.push(replayLowerData, request.security(syminfo.tickerid, targetLowerTf, close[i]))
    

内容的提问来源于stack exchange,提问作者ocbvanelle

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.22 13:03:08