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

为何Pine Script指标在不同数据源的SPX代码上表现不一致?

Pine Script开盘区间指标在不同SPX数据源上显示异常

我编写了一个Pine Script开盘区间指标,该指标在SP:SPX代码上显示正常,但在CBOE:SPX代码上显示异常——这两个标的指向同一指数,但来自不同的数据feed。

正确指标显示
错误指标显示

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © 2023, Vincent Dentice

//@version=5
indicator("Opening Range", "OpeningRange", overlay = true)

bool showOnlyCurrentDay = input.bool(true, "Show only current day")
color defaultColor = color.new(color.yellow, 30)
color lineColorInput = input.color(defaultColor, "Color")
string sessionInput = input.session("0930-1000", "Session")
string timeframeInput = input.timeframe("D", "Timeframe")

sessionBegins(sess) =>
    t = time("", sess)
    timeframe.isintraday and (not barstate.isfirst) and na(t[1]) and not na(t)

isInSession(sess) =>
    t = time("", sess)
    timeframe.isintraday and (not barstate.isfirst) and not na(t)

var float hi = na
var float mid = na
var float lo = na
var line hiLine = na
var line midLine = na
var line loLine = na

if sessionBegins(sessionInput)
    hi := high
    lo := low
    mid := (hi + lo) / 2.0

if isInSession(sessionInput)
    hi := math.max(hi, high)
    lo := math.min(lo, low)
    mid := (hi + lo) / 2.0

if ta.change(time(timeframeInput))
    if showOnlyCurrentDay
        if na(hiLine)
            hiLine := line.new(bar_index - 1, hi, bar_index, hi, color = lineColorInput, width = 2, extend = extend.right)
            int(na)
        else
            line.set_x1(hiLine, bar_index - 1)
            line.set_y1(hiLine, hi)
            line.set_x2(hiLine, bar_index)
            line.set_y2(hiLine, hi)
            int(na)

        if na(midLine)
            midLine := line.new(bar_index - 1, mid, bar_index, mid, color = lineColorInput, width = 1, extend = extend.right, style = line.style_dashed)
            int(na)
        else
            line.set_x1(midLine, bar_index - 1)
            line.set_y1(midLine, mid)
            line.set_x2(midLine, bar_index)
            line.set_y2(midLine, mid)
            int(na)

        if na(loLine)
            loLine := line.new(bar_index - 1, lo, bar_index, lo, color = lineColorInput, width = 2, extend = extend.right)
            int(na)
        else
            line.set_x1(loLine, bar_index - 1)
            line.set_y1(loLine, lo)
            line.set_x2(loLine, bar_index)
            line.set_y2(loLine, lo)
            int(na)
    else
        line.set_extend(hiLine, extend.none)
        line.set_extend(midLine, extend.none)
        line.set_extend(loLine, extend.none)
        hiLine := line.new(bar_index - 1, hi, bar_index, hi, color = lineColorInput, width = 2, extend = extend.right)
        midLine := line.new(bar_index - 1, mid, bar_index, mid, color = lineColorInput, width = 1, extend = extend.right, style = line.style_dashed)
        loLine := line.new(bar_index - 1, lo, bar_index, lo, color = lineColorInput, width = 2, extend = extend.right)
        int(na)
else
    line.set_y1(hiLine, hi)
    line.set_y1(midLine, mid)
    line.set_y1(loLine, lo)
    line.set_x2(hiLine, bar_index)
    line.set_x2(midLine, bar_index)
    line.set_x2(loLine, bar_index)
    line.set_y2(hiLine, hi)
    line.set_y2(midLine, mid)
    line.set_y2(loLine, lo)
    int(na)

xUp = close > hiLine.get_y1() and close[1] <= hiLine.get_y1()
xDn = close < loLine.get_y1() and close[1] >= loLine.get_y1()

alertcondition(xUp, "Above Opening Range", "Current price is above opening range.")
alertcondition(xDn, "Below Opening Range", "Current price is below opening range.")

我怀疑问题出在脚本顶部的时间帧调用相关逻辑,但无法定位具体原因,希望该指标能在两个数据源上显示一致的结果。

内容的提问来源于stack exchange,提问作者V. Dentice

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 21:40:11