OPEN-SOURCE SCRIPT
RSI Divergence + Hidden

RSI Divergence + Hidden (TV-like pairing, final)
What it does
This indicator plots RSI and automatically detects both regular and hidden divergences by pairing RSI pivots with price pivots. It supports a TradingView-like loose pairing (within a user-defined bar tolerance) and a strict same-bar pairing. Detected signals are drawn with lines and optional labels on the RSI pane for quick visual verification.
Divergence logic
Regular Bullish (label: Bull)
Price makes a lower low while RSI makes a higher low → potential upward reversal.
Regular Bearish (label: Bear)
Price makes a higher high while RSI makes a lower high → potential downward reversal.
Hidden Bullish (label: H_Bull)
Price makes a higher low while RSI makes a lower low → trend-continuation bias upward.
Hidden Bearish (label: H_Bear)
Price makes a lower high while RSI makes a higher high → trend-continuation bias downward.
All conditions use pivot-to-pivot comparisons with optional equality tolerance for price and RSI to reduce false “equal” mismatches.
Pairing modes
TV-like
Pairs the latest price and RSI pivots if their pivot bars occur within ±tolBars.
A lightweight “pending” buffer allows pairing a newly detected pivot with a recent opposite pivot that arrived a few bars earlier/later (within tolerance).
Same Bar
Price and RSI pivots must occur on the exact same bar to form a pair.
Key inputs
RSI Source & Length: srcRsi, rsiLen (default 14). RSI line and reference levels (70/50/30) can be shown/hidden.
Pivot Window: leftBars, rightBars for both price and RSI pivots.
Pairing: pairMode = TV-like or Same Bar; tolBars for bar tolerance (TV-like only).
Price Pivot Basis: priceMode = High/Low (default) or Close.
Equality Tolerance:
allowEqual (use >=/<=),
priceEpsTks (ticks) for price equality slack,
rsiEps (points) for RSI equality slack.
Visibility: showRSI, showRegular, showHidden, showLabels.
Visuals
Lines (on RSI):
Regular Bearish: red
Regular Bullish: lime
Hidden Bearish: orange
Hidden Bullish: teal
Labels (optional): "Bear", "Bull", "H_Bear", "H_Bull" placed on the RSI series at the second pivot.
Alerts
Four alert conditions are provided and fire when the corresponding divergence is confirmed:
Bear (Regular)
Bull (Regular)
H_Bear (Hidden)
H_Bull (Hidden)
Notes & tips
Divergences are evaluated only when both price and RSI pivots exist and can be paired under the selected mode.
Pivot sensitivity: smaller leftBars/rightBars → earlier but noisier signals; larger values → fewer, more stable pivots.
Tolerance: If you miss valid setups because pivots land a few bars apart, use TV-like with a small tolBars (e.g., 1–2). If you prefer stricter confirmation, use Same Bar.
Equality slack: Use priceEpsTks and rsiEps to avoid rejecting near-equal highs/lows due to tiny differences.
Works on any symbol/timeframe; as with all divergence tools, treat signals as context—combine with trend, structure, and risk management.
What it does
This indicator plots RSI and automatically detects both regular and hidden divergences by pairing RSI pivots with price pivots. It supports a TradingView-like loose pairing (within a user-defined bar tolerance) and a strict same-bar pairing. Detected signals are drawn with lines and optional labels on the RSI pane for quick visual verification.
Divergence logic
Regular Bullish (label: Bull)
Price makes a lower low while RSI makes a higher low → potential upward reversal.
Regular Bearish (label: Bear)
Price makes a higher high while RSI makes a lower high → potential downward reversal.
Hidden Bullish (label: H_Bull)
Price makes a higher low while RSI makes a lower low → trend-continuation bias upward.
Hidden Bearish (label: H_Bear)
Price makes a lower high while RSI makes a higher high → trend-continuation bias downward.
All conditions use pivot-to-pivot comparisons with optional equality tolerance for price and RSI to reduce false “equal” mismatches.
Pairing modes
TV-like
Pairs the latest price and RSI pivots if their pivot bars occur within ±tolBars.
A lightweight “pending” buffer allows pairing a newly detected pivot with a recent opposite pivot that arrived a few bars earlier/later (within tolerance).
Same Bar
Price and RSI pivots must occur on the exact same bar to form a pair.
Key inputs
RSI Source & Length: srcRsi, rsiLen (default 14). RSI line and reference levels (70/50/30) can be shown/hidden.
Pivot Window: leftBars, rightBars for both price and RSI pivots.
Pairing: pairMode = TV-like or Same Bar; tolBars for bar tolerance (TV-like only).
Price Pivot Basis: priceMode = High/Low (default) or Close.
Equality Tolerance:
allowEqual (use >=/<=),
priceEpsTks (ticks) for price equality slack,
rsiEps (points) for RSI equality slack.
Visibility: showRSI, showRegular, showHidden, showLabels.
Visuals
Lines (on RSI):
Regular Bearish: red
Regular Bullish: lime
Hidden Bearish: orange
Hidden Bullish: teal
Labels (optional): "Bear", "Bull", "H_Bear", "H_Bull" placed on the RSI series at the second pivot.
Alerts
Four alert conditions are provided and fire when the corresponding divergence is confirmed:
Bear (Regular)
Bull (Regular)
H_Bear (Hidden)
H_Bull (Hidden)
Notes & tips
Divergences are evaluated only when both price and RSI pivots exist and can be paired under the selected mode.
Pivot sensitivity: smaller leftBars/rightBars → earlier but noisier signals; larger values → fewer, more stable pivots.
Tolerance: If you miss valid setups because pivots land a few bars apart, use TV-like with a small tolBars (e.g., 1–2). If you prefer stricter confirmation, use Same Bar.
Equality slack: Use priceEpsTks and rsiEps to avoid rejecting near-equal highs/lows due to tiny differences.
Works on any symbol/timeframe; as with all divergence tools, treat signals as context—combine with trend, structure, and risk management.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.
오픈 소스 스크립트
진정한 트레이딩뷰 정신에 따라 이 스크립트 작성자는 트레이더가 기능을 검토하고 검증할 수 있도록 오픈소스로 공개했습니다. 작성자에게 찬사를 보냅니다! 무료로 사용할 수 있지만 코드를 다시 게시할 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.