OPEN-SOURCE SCRIPT
Zaktualizowano

Intermarket Divergence with Reliability Scoring

218
Intermarket Divergence with Reliability Scoring

Related markets tend to move together. When your chart pushes to a new high but a market that usually tracks it does not confirm, that non-confirmation can precede a turn. This script measures divergence between your chart and a chosen leader market — but only when the leader is actually correlated to price, because a decoupled market's "divergence" is meaningless — and then scores, in real time, whether those divergences have been worth trading on your symbol.

WHAT IT PLOTS

A normalised oscillator built from a chosen leader market, its stretch bands, divergence markers and connecting pivot lines, plus a plain-language verdict panel. By default the chart stays minimal — the oscillator and the verdict panel — with optional key-info and per-class tables you can switch on in settings.

WHY THESE COMPONENTS ARE COMBINED, AND HOW THEY WORK TOGETHER

Three classical pieces are fused into one pipeline, not stacked as independent signals:

A z-scored leader series — optionally inverted, optionally lead-lag shifted — the cross-market line your price is compared against.
A live correlation gate — the leader only votes when its trailing correlation to price clears a threshold, so non-confirmations from a decoupled market are ignored.
A binomial-proportion confidence test — asks, for each divergence class, whether the expected move followed more often than a same-zone baseline would deliver.

Part 1 builds the comparison, part 2 keeps only the meaningful divergences, part 3 decides whether the survivors have actually paid on this instrument, by direction. The parts are interdependent — remove any one and the script can no longer answer its core question: is this intermarket divergence worth trading here, and which way?

HOW TO READ IT

The verdict panel translates the statistics into four states:

GREEN, edge confirmed: these divergences have beaten a same-spot baseline here. Worth acting on.
RED, no edge here: they have lost to a coin-flip. Skip them, pick a leader that genuinely leads, or change the timeframe.
AMBER, unproven: edge not statistically established yet; treat as low-confidence.
GREY, learning: still collecting completed samples.

It also shows:

Best signal — names a direction only once that direction is individually proven (its edge lower-bound clears zero). Otherwise it says "none confirmed", so you are never lured by a single noisy number.
Leader link — how tightly the leader currently tracks price (strong, moderate or weak). A weak link means the leader has decoupled and its divergences are unreliable.
Reward : risk — the average best move versus the average worst move after a signal, in ATR. Below 1:1 means signals have hurt more than they helped.
Market regime — reverting markets suit divergence; strong trends punish it.

A divergence is simply price making a higher high or lower low while the leader line does the opposite, counted only when the leader is correlated enough to matter.

CHOOSING A LEADER

Pick a market that genuinely leads — a currency, a global risk proxy, a sector index — not one that merely co-moves with your chart. The lead-lag offset lets you test whether it leads. A co-moving index will usually show no edge, which the panel will tell you plainly.

WHAT IS ORIGINAL

Standard intermarket tools just overlay two symbols. This one fuses a live correlation gate into the divergence filter, then keeps a self-updating, confidence-scored, per-class track record against a same-zone baseline — so you see not just that a non-confirmation printed, but whether and how it has paid, and you only trust a direction once it is statistically proven.

UNIVERSAL ACROSS MARKETS

Reads the chart's own price (the source is configurable in settings) plus one leader symbol. Defaults target NIFTY futures with Bank Nifty as the leader. Change the leader to USD/INR (inverse), a sector or overseas index, or any related market for other instruments, in any market.

OUTPUTS FOR OTHER SCRIPTS

Generic EXP_ values — oscillator, signal, probability, edge, edge lower-bound, sample count, regime, leader value and leader correlation — are published to the Data Window so other indicators can read them via input.source().

CONCEPT CREDITS

Average true range — J. W. Wilder. Binomial score confidence interval — E. B. Wilson. Trend-efficiency regime measure — P. Kaufman. Intermarket analysis and divergence — classical technical analysis.

DISCLAIMER

For research and education only. This is not financial advice, not a recommendation to buy or sell, and not a guarantee of future results. All performance shown is in-sample and past-only. Markets carry risk — do your own research and manage your own risk.
Informacje o Wersji
v1.1 — Correctness + licence pass

- Correctness (important): the same-zone baseline that divergences are scored against called ta.sma
from inside a ternary branch, so those rolling averages were skipped on some bars and the baseline
could drift. They now run on every bar as Pine requires, so the reliability score compares each
signal against a correct baseline. Verdicts and per-class win-rates will be more accurate.
- Added the MPL-2.0 licence header.
- No other change: the EXP_ export bus, the cost-aware reliability scoring (costs subtracted in ATR),
the Wilson edge-lower-bound confirmation, and the adaptive theme were already in place and are
untouched.

Descriptive research tooling, in-sample statistics net of costs, not investment advice.
Informacje o Wersji
v1.1 — Correctness + on-price signals + licence pass

- Correctness (important): the same-zone baseline that divergences are scored against called ta.sma
from inside a ternary branch, so those rolling averages were skipped on some bars and the baseline
could drift. They now run on every bar as Pine requires, so the reliability score compares each
signal against a correct baseline. Verdicts and per-class win-rates will be more accurate.
- New: signals now also print on the MAIN PRICE CHART, not just the indicator pane — a bright,
fully-opaque triangle below the bar for bullish, above the bar for bearish, and ✕ for hidden
divergences. Edge-confirmed signals are drawn larger (the colour stays vibrant either way).
Toggle it in "Visuals & Tables".
- Added the MPL-2.0 licence header.
- No other change: the EXP_ export bus, the cost-aware reliability scoring (costs subtracted in ATR),
the Wilson edge-lower-bound confirmation, and the adaptive theme were already in place and are
untouched.

Descriptive research tooling, in-sample statistics net of costs, not investment advice.

Wyłączenie odpowiedzialności

Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.