OPEN-SOURCE SCRIPT
Stochastic Divergence (live) AA

What it does:
This script detects live regular bullish and bearish divergence between price and a smoothed Stochastic D line. It uses confirmed fractal swing highs and lows on price to define the first anchor point of the divergence, and those pivot settings can be adjusted in the UI. The first pivot is confirmed, but the second pivot is live, so the script can identify divergence as it is forming rather than waiting for a second confirmed swing.
A bullish divergence is found when price makes a lower low while the Stochastic D makes a higher low. A bearish divergence is found when price makes a higher high while the Stochastic D makes a lower high.
The oscillator used here is a double-smoothed Stochastic D built from TradingView’s built-in stochastic calculation. Instead of using the close as the source, it uses ohlc4, which helps reduce some of the wick-driven noise that can make divergence readings less consistent. If you want to compare or debug the signals against TradingView’s built-in Stochastic, make sure to change its source from close to ohlc4 so the readings line up properly.
This script uses a double invalidation model. A divergence setup is cleared not only when the Stochastic D loses its side of the 50 line, but also when price breaks the structure of the latest anchor pivot bar in the opposite direction. That combination helps reset the setup faster, keeps stale divergence from lingering, and makes the active signals more structurally relevant.
How to use:
Use this script as a price-action context tool, not as a blind entry or exit trigger. Bullish divergences tend to matter most when they appear after an extended move down and line up with support, liquidity sweeps, equal lows, demand zones, or other signs of downside exhaustion. Bearish divergences tend to matter most when they appear after an extended move up and line up with resistance, equal highs, trapped breakouts, supply zones, or other signs of upside exhaustion. The Pivot Left and Pivot Right settings control how strict the first anchor pivot is, with higher values giving fewer but more confirmed structures and lower values making the script more reactive. The Min and Max Bar Distance settings control how far apart the anchor point and the live opposing price extreme can be, which helps filter out weak or overly stretched divergence structures. It works best when combined with structure, location, and real price behavior around an important level, rather than used in isolation.
These are my own takes on widely used market calculations and are not meant to be a standalone trading system. If you found this useful, leave a like 🚀 and follow for more.
Thanks, and good luck on your trading journey.
This script detects live regular bullish and bearish divergence between price and a smoothed Stochastic D line. It uses confirmed fractal swing highs and lows on price to define the first anchor point of the divergence, and those pivot settings can be adjusted in the UI. The first pivot is confirmed, but the second pivot is live, so the script can identify divergence as it is forming rather than waiting for a second confirmed swing.
A bullish divergence is found when price makes a lower low while the Stochastic D makes a higher low. A bearish divergence is found when price makes a higher high while the Stochastic D makes a lower high.
The oscillator used here is a double-smoothed Stochastic D built from TradingView’s built-in stochastic calculation. Instead of using the close as the source, it uses ohlc4, which helps reduce some of the wick-driven noise that can make divergence readings less consistent. If you want to compare or debug the signals against TradingView’s built-in Stochastic, make sure to change its source from close to ohlc4 so the readings line up properly.
This script uses a double invalidation model. A divergence setup is cleared not only when the Stochastic D loses its side of the 50 line, but also when price breaks the structure of the latest anchor pivot bar in the opposite direction. That combination helps reset the setup faster, keeps stale divergence from lingering, and makes the active signals more structurally relevant.
How to use:
Use this script as a price-action context tool, not as a blind entry or exit trigger. Bullish divergences tend to matter most when they appear after an extended move down and line up with support, liquidity sweeps, equal lows, demand zones, or other signs of downside exhaustion. Bearish divergences tend to matter most when they appear after an extended move up and line up with resistance, equal highs, trapped breakouts, supply zones, or other signs of upside exhaustion. The Pivot Left and Pivot Right settings control how strict the first anchor pivot is, with higher values giving fewer but more confirmed structures and lower values making the script more reactive. The Min and Max Bar Distance settings control how far apart the anchor point and the live opposing price extreme can be, which helps filter out weak or overly stretched divergence structures. It works best when combined with structure, location, and real price behavior around an important level, rather than used in isolation.
These are my own takes on widely used market calculations and are not meant to be a standalone trading system. If you found this useful, leave a like 🚀 and follow for more.
Thanks, and good luck on your trading journey.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.