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

如何调整Pine Script中plotshape绘制的RSI信号在图表y轴的显示位置

Pine Script RSI信号显示位置调整方法

当然可以修改plotshape配置调整信号位置,原代码中使用的location.abovebar/location.belowbar参数会让信号紧贴K线上下沿,遇到K线波动大、同屏指标多的场景就容易出现遮挡、辨识度低的问题,以下是两种常用的调整方案:

方案1:自定义K线相对偏移位置(推荐)

该方案可以让信号和K线保持固定比例的距离,既不会和K线重叠,也能直观对应信号触发的K线位置:

  • 新增偏移比例输入参数,可灵活调整信号和K线的距离
  • 将plotshape的location参数改为location.absolute,自定义y轴坐标值

修改的核心代码片段如下:

// 新增偏移参数
offset_pct = input(0.8, title="信号偏移K线比例(%)", minval=0.1, step=0.1, group="显示设置")

// 卖出信号:放在K线最高价上方偏移对应比例位置
plotshape(isup(), y=high*(1 + offset_pct/100), color=#FF0000, style=shape.triangledown, text="RSI Sell", textcolor=#FF0000, location=location.absolute, size=size.tiny)
// 买入信号:放在K线最低价下方偏移对应比例位置
plotshape(isdown(), y=low*(1 - offset_pct/100), color=#009900, style=shape.triangleup, text="RSI Buy", textcolor=#009900, location=location.absolute, size=size.tiny)

方案2:固定显示在图表上下边缘(完全无遮挡)

如果完全不需要信号和K线对齐,追求最高辨识度,可以直接修改location参数为固定边缘值,信号会始终贴在图表的上下边框位置:

// 卖出信号固定在图表顶部
plotshape(isup(), color=#FF0000, style=shape.triangledown, text="RSI Sell", textcolor=#FF0000, location=location.top, size=size.tiny)
// 买入信号固定在图表底部
plotshape(isdown(), color=#009900, style=shape.triangleup, text="RSI Buy", textcolor=#009900, location=location.bottom, size=size.tiny)

完整可运行修改版代码(方案1实现)

//@version=4
study(title="Relative Strength Index", overlay=true, shorttitle="RSI Signals")

srcRSI = close
lenRSI = input(14, minval=1, title="Length")

lenRSI1 = input(70, minval=1, title="RSI Up Standard")
lenRSI2 = input(30, minval=1, title="RSI Down Standard")
// 新增显示偏移设置
offset_pct = input(0.8, title="信号偏移K线比例(%)", minval=0.1, step=0.1, group="显示设置")

upRSI = rma(max(change(srcRSI), 0), lenRSI)
downRSI = rma(-min(change(srcRSI), 0), lenRSI)

rsiRSI = downRSI == 0 ? 100 : upRSI == 0 ? 0 : 100 - 100 / (1 + upRSI / downRSI)

isup() =>
    rsiRSI[1] > lenRSI1 and rsiRSI <= lenRSI1
isdown() =>
    rsiRSI[1] < lenRSI2 and rsiRSI >= lenRSI2

plotshape(isup(), y=high*(1 + offset_pct/100), color=#FF0000, style=shape.triangledown, text="RSI Sell", textcolor=#FF0000, location=location.absolute, size=size.tiny)
plotshape(isdown(), y=low*(1 - offset_pct/100), color=#009900, style=shape.triangleup, text="RSI Buy", textcolor=#009900, location=location.absolute, size=size.tiny)

调整说明

  • 方案1的offset_pct数值越大,信号离K线越远,可根据自身看盘习惯调整
  • 若需要信号和K线完全不重叠,直接切换为方案2的固定边缘模式即可

内容的提问来源于stack exchange,提问作者Özgür Konuşlu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.11 12:24:01