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

Pine Script随机指标看涨背离不显示问题求助

背离指标切换Stochastic后看涨背离不显示的原因及修复

问题根源

你的代码里,看涨背离的判断条件包含osc[lbR] < 0,但Stochastic(随机指标)的取值范围是0到100,永远不会小于0。这个条件对Stochastic来说永远不成立,直接导致整个看涨背离的判断逻辑失效,所以无法显示标记。

而看跌背离的条件osc[lbR] > 0,对Stochastic来说始终满足(因为指标值最小是0),所以看跌背离能正常显示。

修复步骤

  1. 针对Stochastic的特性,把看涨背离中的指标区间判断从<0改成超卖区间阈值(通常用20,可根据交易策略调整)。
  2. 可选优化:看跌背离的指标区间判断可以从>0改成超买区间阈值(比如80),让背离判断更符合随机指标的常规逻辑。

修改后的代码片段

// Regular Bullish
// Osc: Higher Low
oscHL = osc[lbR] > ta.valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) and 
osc[lbR] < 20  // 替换原有的<0,适配Stochastic超卖区间
// Price: Lower Low
priceLL = low[lbR] < ta.valuewhen(plFound, low[lbR], 1)
bullCond = plotBull and priceLL and oscHL and plFound
plot(plFound ? osc[lbR] : na, offset=-lbR, title='Regular Bullish', linewidth=2, 
color=bullCond ? bullColor : color.new(color.white, 100))

//------------------------------------------------------------------------------
// Regular Bearish
// Osc: Lower High
oscLH = osc[lbR] < ta.valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) and osc[lbR] > 80  // 可选优化:替换原有的>0,适配Stochastic超买区间
// Price: Higher High
priceHH = high[lbR] > ta.valuewhen(phFound, high[lbR], 1)
bearCond = plotBear and priceHH and oscLH and phFound
plot(phFound ? osc[lbR] : na, offset=-lbR, title='Regular Bearish', linewidth=2, 
color=bearCond ? bearColor : color.new(color.white, 100))

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 20:06:19