如何在Pine Script V4中将Wave Trend Oscillator移至50线(替代原0线)?
Wave Trend基准线改为50并与RSI同屏显示的Pine Script实现
核心思路
Wave Trend Oscillator原本的数值围绕0线波动,只需在最终计算结果上加50,就能将基准线偏移至50,同时保留原有波动逻辑,且偏移后数值范围(0-100)与RSI一致,适合同屏对比。
完整代码实现
//@version=5 indicator("Wave Trend (Base 50) + RSI", overlay=false) // Wave Trend Oscillator 计算(基准线调整为50) wt_length = input.int(10, title="Wave Trend周期") wt_mult = input.float(1.0, title="波动乘数") src = input(close, title="数据源") ap = ta.sma((src + ta.highest(src) + ta.lowest(src)) / 3, wt_length) esa = ta.sma(src, wt_length) d = ta.sma(math.abs(src - esa), wt_length) ci = (src - esa) / (0.015 * d) wt = ta.sma(ci, wt_length) * wt_mult // 偏移基准线到50 wt_adjusted = wt + 50 // RSI 计算 rsi_length = input.int(14, title="RSI周期") rsi = ta.rsi(src, rsi_length) // 绘图设置 plot(wt_adjusted, color=color.new(color.blue, 0), title="Wave Trend (基准50)") plot(50, color=color.new(color.gray, 0), title="基准线(50)", style=plot.style_dashed) plot(rsi, color=color.new(color.red, 0), title="RSI") // 可选:Wave Trend与基准线之间填充颜色,增强视觉区分 fill(plot(wt_adjusted), plot(50), color=color.new(color.blue, 90))
关键代码说明
wt_adjusted = wt + 50:这是偏移基准线的核心操作,将原本围绕0波动的Wave Trend数值整体上移50,基准线自然变为50- 保留了Wave Trend的原生计算逻辑,确保指标信号不受影响
- 同时集成RSI指标,通过不同颜色线条区分,方便同屏对比
内容的提问来源于stack exchange,提问作者Gonzalo
相关产品推荐
相关产品推荐

