Z-Score Mean Reversion Probability [Dots3Red]

📊 Z-Score Mean Reversion Probability [Dots3Red]
This script measures how far price has stretched from its own average (z-score), then checks this chart's history to show how often price actually moved back after being that stretched — as a percentage, with the sample size next to it
✨ WHY THIS MATTERS
Standard deviation bands and z-score oscillators all answer the same question — "how stretched is price right now?" — but none of them answer the question that actually matters to a trader: when it's been this stretched before, how often did it actually revert, and how fast? Without that number, a z-score of 2.5 is just a shape on a chart. This script turns it into a measured, bucket-specific probability, built from this chart's own history rather than a rule of thumb borrowed from somewhere else.
📊 Two panes, one idea
The z-score line lives in its own pane, showing how stretched price is. The labels are drawn directly on the price chart, at the candle where a stretch met a bucket with a proven track record — so the reading and the price action it refers to are in the same place.
⚙️ HOW IT WORKS
📐 Rolling z-score — price's distance from its own rolling mean, measured in standard deviations, clamped at both ends so a single freak spike can't create an empty, meaningless bucket.
🗂️ Bucketing — every z-score reading is sorted into a fixed-width bucket by how extreme it was. Each bucket keeps its own independent count of occurrences and reversion hits.
🎯 Rolling, honest grading — a bucket is only updated once its outcome horizon has fully closed, using the z-score exactly as it stood at the time the reading occurred — never recalculated afterward with the benefit of hindsight. A bucket's probability is hidden until it has enough graded samples to mean something.
🔍 The lookup — the current bar's z-score is sorted into its bucket, and that bucket's own measured reversion rate becomes the probability shown on the dashboard and, when it clears your confidence threshold, the label on the price chart.
🧹 One label per stretch — while price stays stretched, a bucket can qualify on many consecutive bars. A configurable cooldown prints one label at the start of the stretch instead of a cluster, and the background tint still shows how long the stretch lasted.
🔒 Non-repainting — bucketing, grading and every permanent label use confirmed bars only. An optional provisional "(live)" label can show on the still-forming bar; it is dimmed, can appear or disappear until the bar closes, and is replaced by a permanent label only if the reading still qualifies at the close. It can be switched off.
🧭 HOW TO USE
1️⃣ Wait for buckets to fill. A fresh chart shows "Collecting…" for a given z-score range until enough occurrences have been graded — the dashboard shows exactly how many samples the current bucket has versus the minimum required.
2️⃣ Check Overall Accuracy before trusting any single reading. It's a scoreboard across every graded bucket on this chart, so a high sample count means the number is worth something.
3️⃣ Use Min Confidence to filter noise. A label only prints when the current bucket's measured reversion rate clears your threshold (60% by default) — a bucket sitting near 50/50 isn't a real edge in either direction.
4️⃣ Tune label density to your style. Lower Min Confidence, Min Samples or widen the bucket to see more labels; raise them to see fewer, better-supported ones. The cooldown setting controls how far apart labels sit.
5️⃣ Treat the probability as a measured lean, not a forecast. It answers "what happened after price got this stretched, on this chart" — not a guarantee about this specific move.
6️⃣ Different buckets can behave very differently. A moderate z-score of 1.5 might revert far more (or less) reliably than an extreme z-score of 3.0 — exactly the nuance a flat "z-score is high, expect reversion" rule misses. On strongly trending charts, rates near or below 50% are the tool telling you a stretch is not worth fading there.
⏱️ WHICH TIMEFRAMES WORK BEST
This method needs enough historical occurrences per bucket to be meaningful, which makes 15-minute through 4-hour the most effective range — short enough to accumulate samples in a reasonable window, long enough that each reading reflects real, settled price behavior rather than noise. Daily charts work with lower sample minimums and wider buckets, at lower confidence.
🛠️ SETTINGS
📐 Statistics — mean/stdev lookback length, max z-score clamp, bucket width
📊 Probability Engine
• Outcome Horizon — how many bars ahead reversion is checked, and the window each bucket is graded on
• Min Samples per Bucket — how many graded occurrences a bucket needs before its probability is shown
• Min Confidence to Signal — how lopsided a bucket's reversion rate must be before a label appears
🎨 Visualization — z-score line color and thickness, background tint, price-chart labels, minimum bars between labels, optional live label
🖥️ Dashboard — show/hide, position — current z-score, current bucket's sample count, its measured reversion probability and direction, overall accuracy with sample size, outcome horizon
🔔 Alerts — bullish and bearish conditions, respecting the same label cooldown
📝 NOTES
The probabilities shown are specific to this chart, this timeframe, and these settings — they do not transfer to other instruments or configurations. A z-score extreme that reverts reliably on one chart may behave completely differently on another; the honest way to know is to let each bucket fill and check its measured rate for the setup you're using.
⚠️ DISCLAIMER
This is an analytical and visualization tool. It does not generate trade signals and does not constitute financial advice. Historical prediction accuracy does not guarantee future performance.
This script measures how far price has stretched from its own average (z-score), then checks this chart's history to show how often price actually moved back after being that stretched — as a percentage, with the sample size next to it
✨ WHY THIS MATTERS
Standard deviation bands and z-score oscillators all answer the same question — "how stretched is price right now?" — but none of them answer the question that actually matters to a trader: when it's been this stretched before, how often did it actually revert, and how fast? Without that number, a z-score of 2.5 is just a shape on a chart. This script turns it into a measured, bucket-specific probability, built from this chart's own history rather than a rule of thumb borrowed from somewhere else.
📊 Two panes, one idea
The z-score line lives in its own pane, showing how stretched price is. The labels are drawn directly on the price chart, at the candle where a stretch met a bucket with a proven track record — so the reading and the price action it refers to are in the same place.
⚙️ HOW IT WORKS
📐 Rolling z-score — price's distance from its own rolling mean, measured in standard deviations, clamped at both ends so a single freak spike can't create an empty, meaningless bucket.
🗂️ Bucketing — every z-score reading is sorted into a fixed-width bucket by how extreme it was. Each bucket keeps its own independent count of occurrences and reversion hits.
🎯 Rolling, honest grading — a bucket is only updated once its outcome horizon has fully closed, using the z-score exactly as it stood at the time the reading occurred — never recalculated afterward with the benefit of hindsight. A bucket's probability is hidden until it has enough graded samples to mean something.
🔍 The lookup — the current bar's z-score is sorted into its bucket, and that bucket's own measured reversion rate becomes the probability shown on the dashboard and, when it clears your confidence threshold, the label on the price chart.
🧹 One label per stretch — while price stays stretched, a bucket can qualify on many consecutive bars. A configurable cooldown prints one label at the start of the stretch instead of a cluster, and the background tint still shows how long the stretch lasted.
🔒 Non-repainting — bucketing, grading and every permanent label use confirmed bars only. An optional provisional "(live)" label can show on the still-forming bar; it is dimmed, can appear or disappear until the bar closes, and is replaced by a permanent label only if the reading still qualifies at the close. It can be switched off.
🧭 HOW TO USE
1️⃣ Wait for buckets to fill. A fresh chart shows "Collecting…" for a given z-score range until enough occurrences have been graded — the dashboard shows exactly how many samples the current bucket has versus the minimum required.
2️⃣ Check Overall Accuracy before trusting any single reading. It's a scoreboard across every graded bucket on this chart, so a high sample count means the number is worth something.
3️⃣ Use Min Confidence to filter noise. A label only prints when the current bucket's measured reversion rate clears your threshold (60% by default) — a bucket sitting near 50/50 isn't a real edge in either direction.
4️⃣ Tune label density to your style. Lower Min Confidence, Min Samples or widen the bucket to see more labels; raise them to see fewer, better-supported ones. The cooldown setting controls how far apart labels sit.
5️⃣ Treat the probability as a measured lean, not a forecast. It answers "what happened after price got this stretched, on this chart" — not a guarantee about this specific move.
6️⃣ Different buckets can behave very differently. A moderate z-score of 1.5 might revert far more (or less) reliably than an extreme z-score of 3.0 — exactly the nuance a flat "z-score is high, expect reversion" rule misses. On strongly trending charts, rates near or below 50% are the tool telling you a stretch is not worth fading there.
⏱️ WHICH TIMEFRAMES WORK BEST
This method needs enough historical occurrences per bucket to be meaningful, which makes 15-minute through 4-hour the most effective range — short enough to accumulate samples in a reasonable window, long enough that each reading reflects real, settled price behavior rather than noise. Daily charts work with lower sample minimums and wider buckets, at lower confidence.
🛠️ SETTINGS
📐 Statistics — mean/stdev lookback length, max z-score clamp, bucket width
📊 Probability Engine
• Outcome Horizon — how many bars ahead reversion is checked, and the window each bucket is graded on
• Min Samples per Bucket — how many graded occurrences a bucket needs before its probability is shown
• Min Confidence to Signal — how lopsided a bucket's reversion rate must be before a label appears
🎨 Visualization — z-score line color and thickness, background tint, price-chart labels, minimum bars between labels, optional live label
🖥️ Dashboard — show/hide, position — current z-score, current bucket's sample count, its measured reversion probability and direction, overall accuracy with sample size, outcome horizon
🔔 Alerts — bullish and bearish conditions, respecting the same label cooldown
📝 NOTES
The probabilities shown are specific to this chart, this timeframe, and these settings — they do not transfer to other instruments or configurations. A z-score extreme that reverts reliably on one chart may behave completely differently on another; the honest way to know is to let each bucket fill and check its measured rate for the setup you're using.
⚠️ DISCLAIMER
This is an analytical and visualization tool. It does not generate trade signals and does not constitute financial advice. Historical prediction accuracy does not guarantee future performance.
Connect the dots to elevate your trading.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
Connect the dots to elevate your trading.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.