OPEN-SOURCE SCRIPT

RSI Divergence + Hidden

55
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.

Aviso legal

As informações e publicações não devem ser e não constituem conselhos ou recomendações financeiras, de investimento, de negociação ou de qualquer outro tipo, fornecidas ou endossadas pela TradingView. Leia mais em Termos de uso.