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

为何RSI高值有时低于RSI低值?TradingView指标编写疑问

TradingView RSI高低值指标交叉问题修复

问题原因

不是TradingView的RSI计算有缺陷,是你的代码逻辑出错了。你当前的写法是分别对K线的最高价(high)和最低价(low)计算独立的RSI序列,再取1周期的最高/最低值——这本质是两个完全不相关的RSI数据,它们的数值自然会交叉,和你预期的「单根K线周期内RSI的最高/最低值」完全不是一回事。

修复方案

正确的逻辑是:先基于统一的价格序列(比如收盘价)计算标准RSI,再在指定周期内取该RSI序列的最高、最低值。

修正后的代码:

//@version=5
indicator(title='RSI high and low', shorttitle='RSI high and low', overlay=false)

rsiLength = input(14, title="RSI Length")
lookbackPeriod = input(1, title="Lookback Period for High/Low") // 可自定义取高低值的回溯周期

rsiUpperBand = hline(70, 'RSI Upper Band', color=#ffffff)
midline = hline(50, 'RSI Middle Band', color=color.new(#ffffff, 0))
rsiLowerBand = hline(30, 'RSI Lower Band', color=#ffffff)
fill(rsiUpperBand, rsiLowerBand, color=color.rgb(110, 6, 238, 82), title="RSI Background Fill")

// 先计算标准RSI,再取该RSI在回溯周期内的最高/最低值
standardRsi = ta.rsi(close, rsiLength)
rsiHigh = ta.highest(standardRsi, lookbackPeriod)
rsiLow = ta.lowest(standardRsi, lookbackPeriod)

plot(rsiHigh, color=color.rgb(243, 245, 246), title='RSI High')
plot(rsiLow, color=color.rgb(69, 94, 230), title='RSI Low')

关键修改说明

  • 先计算基于收盘价的standardRsi,确保是单一一组RSI序列
  • 再对该序列取lookbackPeriod周期内的最高/最低值,你可以根据需求调整回溯周期(比如改成5,代表取最近5根K线的RSI高低值)
  • 这样得到的rsiHigh和rsiLow是同一RSI序列的极值,自然不会出现交叉情况

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 03:37:37