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

与RSI同屏时,如何将Wave Trend Oscillator偏移至50线而非0线

修改WaveTrend指标:平移至50线并添加RSI(Pine Script)

直接上修改后的完整代码,适配当前Pine Script v5版本,同时满足你的需求:

//@version=5
indicator(title="WaveTrend + RSI [Modified]", shorttitle="WT+RSI", overlay=false)

// WaveTrend参数(保留原LazyBear逻辑,新增平移配置)
n1 = input.int(10, "Channel Length")
n2 = input.int(21, "Average Length")
// 超买超卖线:原数值基于0轴,平移到50轴后同步加50,保持相对位置不变
obLevel1 = input.int(60 + 50, "Over Bought Level 1")
obLevel2 = input.int(53 + 50, "Over Bought Level 2")
osLevel1 = input.int(-60 + 50, "Over Sold Level 1")
osLevel2 = input.int(-53 + 50, "Over Sold Level 2")
shift_offset = input.int(50, "WaveTrend 中轴线偏移", tooltip="设置为50即可将WT定位在50线")

// RSI参数(可自定义调整)
rsi_length = input.int(14, "RSI Length")
rsi_source = input(close, "RSI Source")

// WaveTrend核心计算(原逻辑不变,最后叠加偏移量实现中轴线平移)
ap = hlc3
esa = ta.ema(ap, n1)
d = ta.ema(math.abs(ap - esa), n1)
ci = (ap - esa) / (0.015 * d)
tci = ta.ema(ci, n2)

// 平移WaveTrend到指定中轴线
wt1 = tci + shift_offset
wt2 = ta.sma(wt1, 4)

// 绘制WaveTrend相关线条
plot(shift_offset, color=color.gray, title="WT中轴线")
plot(obLevel1, color=color.red, title="WT超买线1")
plot(osLevel1, color=color.green, title="WT超卖线1")
plot(obLevel2, color=color.red, style=plot.style_dashed, title="WT超买线2")
plot(osLevel2, color=color.green, style=plot.style_dashed, title="WT超卖线2")

plot(wt1, color=color.new(color.green, 0), title="WT1")
plot(wt2, color=color.new(color.red, 0), style=plot.style_dashed, title="WT2")
plot(wt1 - wt2, color=color.new(color.blue, 80), style=plot.style_area, title="WT差值区域")

// 绘制RSI指标
rsi_val = ta.rsi(rsi_source, rsi_length)
hline(70, "RSI超买", color=color.red)
hline(30, "RSI超卖", color=color.green)
hline(50, "RSI中轴线", color=color.gray)
plot(rsi_val, color=color.purple, title="RSI")

关键改动说明

  • WaveTrend平移到50线:给原始WT计算结果tci加上50(通过shift_offset参数可灵活调整中轴线位置),同时同步调整超买超卖线的数值,保证其相对中轴线的位置不变。
  • 新增RSI指标:调用Pine Script内置的ta.rsi()函数,配置了可自定义的长度和数据源,同时绘制了RSI标准的超买(70)、超卖(30)和中轴线(50)。
  • 版本升级:将原代码从过时的v3版本升级到当前稳定的v5版本,语法更规范,兼容性更好。

使用方法

直接复制代码到TradingView的Pine Script编辑器,点击「添加到图表」即可。所有参数都可通过编辑器左侧的输入框调整,无需修改代码。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 19:35:19