OPEN-SOURCE SCRIPT

Dissonance Ledger [JOAT]

12 304
Dissonance Ledger

Introduction

Dissonance Ledger is an advanced open-source divergence intelligence system that simultaneously monitors four independent oscillators — RSI, MACD histogram, Money Flow Index (MFI), and Momentum — for both regular and hidden divergences against price. Rather than relying on a single oscillator (which produces frequent false divergences), this indicator uses a confluence scoring system that requires multiple oscillators to confirm the same divergence before generating a signal. The result is a divergence detection engine with substantially fewer false positives than any single-oscillator approach.

The fundamental problem with traditional divergence trading is reliability. A bearish RSI divergence (price making higher highs while RSI makes lower highs) fails more often than it succeeds when used in isolation. This is because a single oscillator can diverge from price for structural reasons unrelated to an impending reversal. Dissonance Ledger solves this by requiring a minimum number of oscillators (configurable, default 2 out of 4) to independently confirm the same divergence pattern. When RSI, MACD, MFI, and Momentum all agree that momentum is weakening despite price advancing, the probability of a genuine reversal increases substantially.

snapshot

Core Concepts

1. Multi-Oscillator Divergence Architecture

The indicator calculates four oscillators at global scope to ensure proper history tracking:

  • RSI (Relative Strength Index): Measures the ratio of average gains to average losses. Divergences in RSI indicate that the magnitude of price moves is changing relative to the trend
  • MACD Histogram: The difference between the MACD line and its signal line. Divergences in the histogram indicate that the rate of momentum change is shifting
  • MFI (Money Flow Index): A volume-weighted RSI that incorporates buying and selling pressure. MFI divergences indicate that volume is not confirming the price move
  • Momentum: Raw rate of change (close minus close N bars ago). Momentum divergences indicate that the absolute speed of price movement is declining


Each oscillator provides a different lens on momentum. RSI measures relative strength, MACD measures momentum acceleration, MFI measures volume-confirmed pressure, and Momentum measures raw speed. When multiple lenses agree, the signal is more reliable.

2. Fractal Pivot Anchoring

Divergences are anchored to fractal pivot points rather than arbitrary lookback windows. The indicator uses `ta.pivothigh()` and `ta.pivotlow()` with configurable left and right bar counts to identify genuine swing highs and lows. Each pivot's price and all four oscillator values are stored in arrays:

Pine Script®
if not na(pivHigh) array.unshift(phPrices, pivHigh) array.unshift(phBars, bar_index - pivotRight) array.unshift(phRSI, rsiAtBar) array.unshift(phMACD, macdAtBar) // ... MFI, MOM stored similarly


When a new pivot forms, the indicator compares it against the previous pivot. If price made a higher high but one or more oscillators made a lower high, that oscillator registers a bearish divergence vote. The confluence count is the total number of oscillators that agree.

3. Regular vs Hidden Divergences

The indicator detects both types:

  • Regular Divergence (Reversal): Price makes a higher high / lower low while oscillators make a lower high / higher low. This suggests the current trend is losing momentum and a reversal may follow
  • Hidden Divergence (Continuation): Price makes a lower high / higher low while oscillators make a higher high / lower low. This suggests the underlying trend remains strong despite a surface-level pullback, and continuation is likely


Regular divergences are drawn with solid lines; hidden divergences use dashed lines in distinct colors (arctic cyan for hidden bull, amber for hidden bear) to differentiate them visually.

4. Divergence Strength Scoring

Each detected divergence receives a strength score (0-100) based on three factors:

  • Confluence Weight (50%): More oscillators confirming = higher score. 4/4 confluence scores maximum
  • Price Divergence Magnitude (25%): Larger percentage difference between the two pivot prices = stronger divergence
  • Oscillator Divergence Magnitude (25%): Larger absolute difference in oscillator readings between pivots = stronger signal


This scoring system helps traders prioritize high-conviction divergences over marginal ones.

5. ATR Target Projections

When a divergence is confirmed, the indicator projects a target level using a configurable ATR multiple from the pivot point. For bullish divergences, the target is projected above the pivot low; for bearish, below the pivot high. These targets provide a measured-move expectation for the potential reversal.

6. Oscillator Aggregate Bias

Beyond divergence detection, the indicator calculates an aggregate bias across all four oscillators. Each oscillator's reading is normalized to a -1 to +1 scale, and the average is smoothed with an EMA. This provides a continuous measure of overall momentum direction and strength, independent of divergence signals.

Features

  • Confluence-Scored Divergence Labels: Each divergence signal shows its confluence count (e.g., "3/4 REG" for a regular divergence confirmed by 3 of 4 oscillators) and whether it is regular or hidden
  • Divergence Lines: Solid lines for regular divergences, dashed lines for hidden divergences, connecting the two pivot points that form the divergence pattern
  • ATR Target Projections: Dashed horizontal lines with price labels showing the projected target for each divergence
  • Oscillator Momentum Ribbon: An EMA-based ribbon on the price chart that fills bullish or bearish based on the aggregate oscillator bias, providing continuous momentum context
  • Divergence Decay Tracking: After a divergence signal, a fading background zone tracks the "decay" period — the window during which the divergence is still considered active. The zone fades progressively over the configurable decay duration
  • Confluence-Weighted Bar Coloring: Candle colors shift on a gradient based on how many oscillators agree on direction. Full agreement produces vivid colors; mixed signals produce muted colors
  • Divergence History Chain: The dashboard tracks the last three divergence signals in sequence (e.g., "BULL > BEAR > H-BULL"), revealing the pattern of momentum shifts
  • Pivot Markers: Small circles mark fractal pivots that did not produce divergences, maintaining structural awareness
  • 16-Row Dashboard: Displays all four oscillator values, agreement count, aggregate bias, last bull/bear divergence details, strength scores, hidden divergence tracking, history chain, decay status, and total divergence counts


Input Parameters

Pivot Detection:
  • Left/Right Bars: Fractal pivot detection sensitivity (default: 5/5)
  • Lookback Window: Maximum bars between pivots for divergence comparison (default: 60)


Oscillators:
  • RSI Length (default: 14), MACD Fast/Slow/Signal (default: 12/26/9), MFI Length (default: 14), Momentum Length (default: 14)


Confluence:
  • Min Confluence: Minimum oscillators required to confirm a divergence (default: 2, range: 1-4)


Target Projection:
  • ATR Target Multiple: Multiplier for target distance (default: 1.5)
  • Target ATR Length: ATR period for projection calculation (default: 14)


Visuals:
  • Toggles for divergence lines, hidden divergences, target projections, oscillator ribbon, bar coloring, signal background, decay zones, and dashboard
  • Decay Duration: Number of bars the divergence decay zone persists (default: 20)


snapshot

How to Use This Indicator

Step 1: Set Your Confluence Threshold
Start with the default minimum confluence of 2. If you want fewer but higher-conviction signals, increase to 3 or 4. A 4/4 confluence divergence is rare but highly significant.

Step 2: Watch for Divergence Labels
When a label appears (e.g., "3/4 REG" below a pivot low), it means 3 of 4 oscillators confirmed a regular bullish divergence at that pivot. The higher the confluence, the more attention the signal deserves.

Step 3: Check the Strength Score
In the dashboard, review the divergence strength percentage. Scores above 60 indicate strong divergences with large price and oscillator magnitude differences. Scores below 30 are marginal.

Step 4: Use Target Projections for Planning
The dashed target line shows where a measured-move reversal might reach. Use this for take-profit planning, not as a guaranteed level.

Step 5: Monitor the Decay Zone
The fading background after a divergence signal shows the active window. If price hasn't responded by the time the decay zone expires, the divergence has likely failed.

Step 6: Read the History Chain
A sequence like "BEAR > BEAR > BEAR" in the history chain suggests persistent bearish momentum divergences — the trend may be weakening structurally. Alternating "BULL > BEAR > BULL" suggests choppy, unreliable conditions.

Close-up showing a 4/4 confluence bearish divergence with all four oscillator divergence lines visible, the strength score in the dashboard reading 78%, and the ATR target projection line below

Indicator Limitations

  • Divergences are identified at fractal pivots, which require right-bar confirmation. This means divergences are detected with a delay equal to the right-bar count (default 5 bars after the actual pivot)
  • Even with multi-oscillator confluence, divergences can fail. Strong trends can produce multiple consecutive divergences before any reversal occurs — this is known as "divergence stacking" and is a well-known limitation of divergence trading
  • The four oscillators used (RSI, MACD, MFI, Momentum) are all derived from price and volume. They are not truly independent — they share common inputs and can produce correlated false signals during certain market conditions
  • MFI requires reliable volume data. On forex pairs or instruments with synthetic/tick volume, MFI-based confluence may be less meaningful
  • Target projections use ATR as a distance measure, which is backward-looking. In rapidly changing volatility environments, projected targets may overshoot or undershoot
  • Hidden divergences are continuation signals, not reversal signals. Confusing the two types leads to trading against the trend


Originality Statement

This indicator is original in its multi-oscillator confluence approach to divergence detection. While divergence indicators exist for individual oscillators, this indicator is justified because:

  • The four-oscillator confluence system (RSI + MACD + MFI + Momentum) provides a reliability filter not available in single-oscillator divergence detectors. Each oscillator measures a different aspect of momentum, and their agreement substantially reduces false positives
  • The divergence strength scoring system quantifies signal quality using confluence weight, price magnitude, and oscillator magnitude — providing an objective measure for prioritizing signals
  • Fractal pivot anchoring ensures divergences are measured between genuine swing points rather than arbitrary lookback windows
  • The divergence decay tracking system provides a visual time-window for signal validity, addressing the common question of "how long is this divergence still relevant?"
  • The aggregate oscillator bias ribbon provides continuous momentum context independent of divergence signals
  • The history chain tracking reveals patterns in divergence sequences that can indicate structural trend weakening or choppy conditions


Disclaimer

This indicator is provided for educational and informational purposes only. It is not financial advice or a recommendation to buy or sell any financial instrument. Trading involves substantial risk of loss. Divergences are probabilistic patterns, not certainties — even high-confluence divergences can and do fail. Past divergence patterns do not guarantee future reversals. Target projections are mathematical estimates, not price predictions. Always use proper risk management including stop losses and position sizing. The author is not responsible for any losses incurred from using this indicator.

-Made with passion by officialjackofalltrades

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.