OPEN-SOURCE SCRIPT
Aktualisiert Keltner Position Divergence with Reliability Scoring

Overview
Keltner-Position Divergence with Reliability Scoring turns where price sits inside its Keltner channel into a bounded oscillator, reads it for divergence against price, and then scores — in real time — whether those divergences have actually been worth acting on for the symbol on your chart, and which direction is carrying the edge. It is a context / research read, not a standalone buy or sell signal.
The idea
A Keltner channel frames price with an ATR envelope around a moving average. Where price sits inside that envelope — pinned to the upper band, mid, or pinned to the lower band — is a bounded read of stretch. When price makes a new high but its Keltner position does not confirm (a lower band-position high), that non-confirmation can precede a turn. This script measures the divergence between price and its Keltner position, then keeps a self-updating track record of whether such divergences pay.
Why these parts are combined (mashup rationale)
Three components form one pipeline, not three separate signals:
A Keltner-position oscillator — price's location within the ATR envelope (0 centre, +1 upper band, −1 lower band), z-scored so the bands and zones mean the same on every asset.
Confirmed-pivot divergence — regular and hidden, between that position line and price, with an optional triple-pivot mode for rarer, stronger disagreements.
A reliability harness — a binomial-proportion confidence test that asks whether each class of divergence has preceded a favourable move (a k×ATR travel over a fixed horizon) more often than a same-zone baseline, reported per direction with a Wilson confidence bound.
Part 1 builds the bounded stretch read, part 2 fires only where price and position disagree, part 3 decides whether that disagreement has actually paid on this instrument. Remove any one and the tool can no longer answer "is this Keltner divergence worth trading here?"
How to use it
Read the verdict panel first. GREEN = these divergences have beaten a same-spot baseline here; RED = they've lost to it (skip, or change the band width / timeframe); AMBER = not statistically established yet; GREY = still gathering data. "Best signal" names the direction with the strongest measured edge; "Reward : risk" is the average best-vs-worst move after a signal, in ATR. A divergence is price making a higher high / lower low while the Keltner-position line does the opposite — marked in the pane and, optionally, on the price chart. It is context, never a standalone trigger.
Settings worth knowing
The regime filter ("Only count signals in regime") restricts the track record to signals that fired in a chosen regime — reverting markets suit divergence, strong trends punish it — so you can measure the edge where it's supposed to work. Costs subtracted (×ATR) raises the bar a signal must clear so the score is net of costs. Band width, MA length and the z-score window adapt the read to any instrument.
Universality & non-repainting
It reads only the chart's own price (configurable source), so it runs on any symbol, any timeframe, with no external data. Pivots confirm a fixed number of bars after the fact, and the track-record harness logs, updates and resolves only on confirmed (closed) bars, so its statistics never inflate or shift intrabar. The live oscillator updates each bar like any oscillator. All figures are in-sample and past-only.
Outputs for other scripts
Generic EXP_* plots — oscillator, signal, probability, edge, edge lower-bound, sample count, regime, band position — are published to the Data Window for use from other scripts via input.source().
Originality
Standard Keltner tools just plot the channel. This one turns band-position into a divergence oscillator and keeps a self-updating, confidence-scored, per-class track record against a same-zone baseline — so you see not just that a divergence printed, but whether and how it has paid on the current market. Clean-room implementation; no third-party Pine code reused.
Concept credits
Keltner channel — Chester Keltner; ATR-band refinement — Linda Raschke
Average True Range — J. Welles Wilder
Binomial score confidence interval — Edwin B. Wilson
Trend-efficiency regime measure — Perry Kaufman
Disclaimer
For research and education only. Not financial advice, not a recommendation, and not a guarantee of future results. All figures are in-sample and past-only. Markets carry risk; do your own research and manage your own risk.
Keltner-Position Divergence with Reliability Scoring turns where price sits inside its Keltner channel into a bounded oscillator, reads it for divergence against price, and then scores — in real time — whether those divergences have actually been worth acting on for the symbol on your chart, and which direction is carrying the edge. It is a context / research read, not a standalone buy or sell signal.
The idea
A Keltner channel frames price with an ATR envelope around a moving average. Where price sits inside that envelope — pinned to the upper band, mid, or pinned to the lower band — is a bounded read of stretch. When price makes a new high but its Keltner position does not confirm (a lower band-position high), that non-confirmation can precede a turn. This script measures the divergence between price and its Keltner position, then keeps a self-updating track record of whether such divergences pay.
Why these parts are combined (mashup rationale)
Three components form one pipeline, not three separate signals:
A Keltner-position oscillator — price's location within the ATR envelope (0 centre, +1 upper band, −1 lower band), z-scored so the bands and zones mean the same on every asset.
Confirmed-pivot divergence — regular and hidden, between that position line and price, with an optional triple-pivot mode for rarer, stronger disagreements.
A reliability harness — a binomial-proportion confidence test that asks whether each class of divergence has preceded a favourable move (a k×ATR travel over a fixed horizon) more often than a same-zone baseline, reported per direction with a Wilson confidence bound.
Part 1 builds the bounded stretch read, part 2 fires only where price and position disagree, part 3 decides whether that disagreement has actually paid on this instrument. Remove any one and the tool can no longer answer "is this Keltner divergence worth trading here?"
How to use it
Read the verdict panel first. GREEN = these divergences have beaten a same-spot baseline here; RED = they've lost to it (skip, or change the band width / timeframe); AMBER = not statistically established yet; GREY = still gathering data. "Best signal" names the direction with the strongest measured edge; "Reward : risk" is the average best-vs-worst move after a signal, in ATR. A divergence is price making a higher high / lower low while the Keltner-position line does the opposite — marked in the pane and, optionally, on the price chart. It is context, never a standalone trigger.
Settings worth knowing
The regime filter ("Only count signals in regime") restricts the track record to signals that fired in a chosen regime — reverting markets suit divergence, strong trends punish it — so you can measure the edge where it's supposed to work. Costs subtracted (×ATR) raises the bar a signal must clear so the score is net of costs. Band width, MA length and the z-score window adapt the read to any instrument.
Universality & non-repainting
It reads only the chart's own price (configurable source), so it runs on any symbol, any timeframe, with no external data. Pivots confirm a fixed number of bars after the fact, and the track-record harness logs, updates and resolves only on confirmed (closed) bars, so its statistics never inflate or shift intrabar. The live oscillator updates each bar like any oscillator. All figures are in-sample and past-only.
Outputs for other scripts
Generic EXP_* plots — oscillator, signal, probability, edge, edge lower-bound, sample count, regime, band position — are published to the Data Window for use from other scripts via input.source().
Originality
Standard Keltner tools just plot the channel. This one turns band-position into a divergence oscillator and keeps a self-updating, confidence-scored, per-class track record against a same-zone baseline — so you see not just that a divergence printed, but whether and how it has paid on the current market. Clean-room implementation; no third-party Pine code reused.
Concept credits
Keltner channel — Chester Keltner; ATR-band refinement — Linda Raschke
Average True Range — J. Welles Wilder
Binomial score confidence interval — Edwin B. Wilson
Trend-efficiency regime measure — Perry Kaufman
Disclaimer
For research and education only. Not financial advice, not a recommendation, and not a guarantee of future results. All figures are in-sample and past-only. Markets carry risk; do your own research and manage your own risk.
Versionshinweise
UPGRADE WRITE-UPKeltner-Position Divergence v1.1: two corrections to the scoring engine
This update fixes two defects in how the track record was measured. Both affected the Edge, the lower bound, the verdict tier and the alerts, so verdicts on existing charts may change. Where they do, the new reading is the correct one.
BASELINE STATE BUG
The zone-conditional baseline averaged its numerator inside the true branch of a conditional expression. Pine's stateful series functions must be evaluated on every bar; placed in a conditional branch, those averages were skipped on every bar where the denominator was zero, and their rolling windows accumulated over a broken history.
Because the baseline is the yardstick every divergence is scored against, the defect propagated through everything downstream. All four averages are now computed unconditionally and combined afterwards.
THE LOWER BOUND WAS ANTI-CONSERVATIVE
The edge floor was computed as the hit rate minus the interval half-width. The Wilson interval is not symmetric about the observed rate, however — it is centred on a point pulled toward one half. Subtracting only the half-width therefore overstates the floor, and overstates it most on small samples, which is precisely where a floor is meant to protect you. At a hit rate of eighty percent on twenty signals, the old formula reported a floor near sixty-three percent where the correct Wilson bound is roughly fifty-eight.
The proper bound is now used. Since EDGE CONFIRMED and both alerts are gated on it, some setups that previously read confirmed will now read unproven.
ALSO IN THIS UPDATE
The panel shows the interval width beside the Edge, so the size of the uncertainty is visible rather than only its floor.
The Keltner-position oscillator, pivot divergence detection, regime filter, reward-to-risk measurement and non-repaint construction are unchanged.
Unchanged framing: this is a context and research read, not a standalone buy or sell signal. Track-record figures are in-sample.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.