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

Pine Script入门:如何让plotshape绑定Stochastic RSI的K线

解决Stochastic RSI中plotshape图形绑定K线的问题

原代码里plotshape使用location.bottom/location.top会将图形固定在指标面板的上下边缘,而非K线的实际数值位置。要实现图形与K线绑定,只需修改plotshape的参数,去掉location,改用price指定K线的数值即可。

修改后的完整代码:

//@version=5
indicator(title="Stochastic RSI", shorttitle="Stoch RSI", format=format.price, precision=2, timeframe="", timeframe_gaps=true)
smoothK = input.int(3, "K", minval=1)
smoothD = input.int(3, "D", minval=1)
lengthRSI = input.int(14, "RSI Length", minval=1)
lengthStoch = input.int(14, "Stochastic Length", minval=1)
src = input(close, title="RSI Source")
rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)
plot(k, "K", color=#2962FF)
plot(d, "D", color=#FF6D00)
h0 = hline(80, "Upper Band", color=#787B86)
hline(50, "Middle Band", color=color.new(#787B86, 50))
h1 = hline(20, "Lower Band", color=#787B86)
fill(h0, h1, color=color.rgb(33, 150, 243, 90), title="Background")

Cross1 = k < 20
Cross2 = k > 80
// 修改此处:去掉location参数,用price绑定K线数值
plotshape(Cross1, "dots", style=shape.circle, price=k, color=color.green)
plotshape(Cross2, "dots", style=shape.circle, price=k, color=color.red)

关键修改说明:

  • 移除location = location.bottom和location = location.top,避免图形固定在面板边缘
  • 添加price=k,让圆形标记精准绘制在K线的对应数值位置,随K线同步移动
  • 可选添加颜色参数,区分超买/超卖信号,提升视觉辨识度

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.06 08:45:38