OPEN-SOURCE SCRIPT
Order Block Intelligence - Mitigation Probability AI [Dots3Red]

🧱 ORDER BLOCK INTELLIGENCE - MITIGATION PROBABILITY AI [Dots3Red]
This script tracks every order block to its first test and grades the outcome — respected or violated — then reports the measured probability the moment a new zone forms.
✨ WHY THIS MATTERS
An order block is a bet: the market left an imbalance here, and price might react when it returns. That bet is treated as equally good everywhere, regardless of how the zone actually formed. This script checks that assumption directly, on your own chart:
📊 Respect 68% | N=27
That means the 27 most similar order blocks this chart has produced — matched by size, the strength of the move that created them, and volume — were respected 68% of the time when price returned. Measured, not assumed, and specific to this instrument and timeframe.
⚙️ HOW IT WORKS
🧱 Detection — an order block is the last opposite-colored candle before a genuine displacement move: the next candle's body must exceed a configurable multiple of ATR, and by default must also close beyond the base candle's high or low, confirming a real structural break rather than just one large candle.
🎯 Displacement candle highlight — the exact candle that creates the zone is recolored and given a background highlight the moment it qualifies, so you can see precisely which move triggered the block without hunting for it.
📊 The KNN engine — every order block is stored as five measurements at the moment it forms: zone size relative to ATR, the strength of the displacement that created it, volume behavior, volatility context, and trend position. When the zone resolves — respected or violated on its first test — that outcome trains the engine. Every new zone is immediately compared against the K most similar historical zones on this chart, and their measured outcome becomes the probability shown on the label.
🔒 First-touch grading — only the first test of each zone is graded, matching how order blocks are actually used in practice. Respected means price moved away by a meaningful distance (or never closed back through); violated means price closed through the far edge.
🔒 Non-repainting — detection and grading both happen strictly on confirmed bars.
🧭 HOW TO USE
1️⃣ Check the sample size before trusting the percentage. "Respect 68% | N=27" reflects real history; a fresh chart will show "Training…" until enough zones have resolved to say anything meaningful.
2️⃣ Use the displacement highlight to understand why a zone exists. If the highlighted candle was a modest, unconvincing move, that context is worth factoring in even before checking the probability label.
3️⃣ Watch the near edge vs. the far edge differently. The near edge (solid, thinner) is where price is expected to react first; the far edge (dashed, thicker by default) is the zone's origin — a close beyond that line is what defines a violation.
4️⃣ Check the global Respect Rate for chart-level context. Beyond any single zone, the dashboard tracks what percentage of every order block on this chart has been respected overall — useful for judging whether this instrument tends to honor these zones or run through them.
5️⃣ Use "Keep Tested Zones Visible" if you want a visual history of what held and what didn't, rather than a clean chart showing only what's currently active.
⏱️ WHICH TIMEFRAMES WORK BEST
Order blocks require a genuine displacement move to qualify, which makes 15-minute through 4-hour the most effective range — the same window that tends to work best across structure-based tools in general. Fast enough that zones form regularly and the KNN engine builds a real sample; slow enough that the displacement candles represent meaningful moves rather than noise.
On very short timeframes (1-3 minute), lower the Displacement Strength setting somewhat, since ATR-relative moves are naturally smaller and more frequent there — otherwise very few candles will qualify. On daily or higher timeframes, genuine order blocks are rarer by nature, so expect longer waits between zones and a slower-growing sample size; this is expected, not a malfunction.
🛠️ SETTINGS
🧱 Order Block Detection
• Displacement Strength (×ATR) — how large the impulse candle's body must be to qualify. Lower this on fast timeframes, raise it on slow ones or if too many weak zones are forming.
• Require Structure Break — toggle whether the displacement candle must also close beyond the base candle's range
• Max Order Blocks Shown, Zone Extension — chart management
📊 KNN Engine
• ATR Baseline Period, Trend MA Length — context windows used in matching
• K Neighbors, Max/Min Training Samples — how the probability engine is tuned
🎯 Mitigation Grading
• Respect Distance, Outcome Window — define what counts as a genuine respect versus a violation
🎨 Visualization
• Independent bullish/bearish zone line and fill colors, plus a separate Tested Zone color
• Independent near-edge and far-edge (base) line widths — the base edge is thicker by default to visually anchor the zone
• Displacement candle highlight with independent bullish/bearish colors, plus an optional plain-bar mode for the rest of the chart that never overrides the highlight
🖥️ Dashboard — show/hide, position — untested zone count by direction, global respect rate, KNN training progress, and the active outcome window

📝 NOTES
Only one active zone per direction accumulates statistics from the moment it's created; a fresh, stricter, or looser Displacement Strength setting will naturally change how many zones qualify and therefore how quickly the sample size builds. Zone size and displacement strength are measured relative to ATR, so the same settings adapt reasonably across different instruments without manual retuning.
⚠️ DISCLAIMER
This is an analytical and visualization tool. It does not generate trade signals and does not constitute financial advice. Historical mitigation rates do not guarantee how any specific future order block will resolve.
This script tracks every order block to its first test and grades the outcome — respected or violated — then reports the measured probability the moment a new zone forms.
✨ WHY THIS MATTERS
An order block is a bet: the market left an imbalance here, and price might react when it returns. That bet is treated as equally good everywhere, regardless of how the zone actually formed. This script checks that assumption directly, on your own chart:
📊 Respect 68% | N=27
That means the 27 most similar order blocks this chart has produced — matched by size, the strength of the move that created them, and volume — were respected 68% of the time when price returned. Measured, not assumed, and specific to this instrument and timeframe.
⚙️ HOW IT WORKS
🧱 Detection — an order block is the last opposite-colored candle before a genuine displacement move: the next candle's body must exceed a configurable multiple of ATR, and by default must also close beyond the base candle's high or low, confirming a real structural break rather than just one large candle.
🎯 Displacement candle highlight — the exact candle that creates the zone is recolored and given a background highlight the moment it qualifies, so you can see precisely which move triggered the block without hunting for it.
📊 The KNN engine — every order block is stored as five measurements at the moment it forms: zone size relative to ATR, the strength of the displacement that created it, volume behavior, volatility context, and trend position. When the zone resolves — respected or violated on its first test — that outcome trains the engine. Every new zone is immediately compared against the K most similar historical zones on this chart, and their measured outcome becomes the probability shown on the label.
🔒 First-touch grading — only the first test of each zone is graded, matching how order blocks are actually used in practice. Respected means price moved away by a meaningful distance (or never closed back through); violated means price closed through the far edge.
🔒 Non-repainting — detection and grading both happen strictly on confirmed bars.
🧭 HOW TO USE
1️⃣ Check the sample size before trusting the percentage. "Respect 68% | N=27" reflects real history; a fresh chart will show "Training…" until enough zones have resolved to say anything meaningful.
2️⃣ Use the displacement highlight to understand why a zone exists. If the highlighted candle was a modest, unconvincing move, that context is worth factoring in even before checking the probability label.
3️⃣ Watch the near edge vs. the far edge differently. The near edge (solid, thinner) is where price is expected to react first; the far edge (dashed, thicker by default) is the zone's origin — a close beyond that line is what defines a violation.
4️⃣ Check the global Respect Rate for chart-level context. Beyond any single zone, the dashboard tracks what percentage of every order block on this chart has been respected overall — useful for judging whether this instrument tends to honor these zones or run through them.
5️⃣ Use "Keep Tested Zones Visible" if you want a visual history of what held and what didn't, rather than a clean chart showing only what's currently active.
⏱️ WHICH TIMEFRAMES WORK BEST
Order blocks require a genuine displacement move to qualify, which makes 15-minute through 4-hour the most effective range — the same window that tends to work best across structure-based tools in general. Fast enough that zones form regularly and the KNN engine builds a real sample; slow enough that the displacement candles represent meaningful moves rather than noise.
On very short timeframes (1-3 minute), lower the Displacement Strength setting somewhat, since ATR-relative moves are naturally smaller and more frequent there — otherwise very few candles will qualify. On daily or higher timeframes, genuine order blocks are rarer by nature, so expect longer waits between zones and a slower-growing sample size; this is expected, not a malfunction.
🛠️ SETTINGS
🧱 Order Block Detection
• Displacement Strength (×ATR) — how large the impulse candle's body must be to qualify. Lower this on fast timeframes, raise it on slow ones or if too many weak zones are forming.
• Require Structure Break — toggle whether the displacement candle must also close beyond the base candle's range
• Max Order Blocks Shown, Zone Extension — chart management
📊 KNN Engine
• ATR Baseline Period, Trend MA Length — context windows used in matching
• K Neighbors, Max/Min Training Samples — how the probability engine is tuned
🎯 Mitigation Grading
• Respect Distance, Outcome Window — define what counts as a genuine respect versus a violation
🎨 Visualization
• Independent bullish/bearish zone line and fill colors, plus a separate Tested Zone color
• Independent near-edge and far-edge (base) line widths — the base edge is thicker by default to visually anchor the zone
• Displacement candle highlight with independent bullish/bearish colors, plus an optional plain-bar mode for the rest of the chart that never overrides the highlight
🖥️ Dashboard — show/hide, position — untested zone count by direction, global respect rate, KNN training progress, and the active outcome window
📝 NOTES
Only one active zone per direction accumulates statistics from the moment it's created; a fresh, stricter, or looser Displacement Strength setting will naturally change how many zones qualify and therefore how quickly the sample size builds. Zone size and displacement strength are measured relative to ATR, so the same settings adapt reasonably across different instruments without manual retuning.
⚠️ DISCLAIMER
This is an analytical and visualization tool. It does not generate trade signals and does not constitute financial advice. Historical mitigation rates do not guarantee how any specific future order block will resolve.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
Connect the dots to elevate your trading.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.
نص برمجي مفتوح المصدر
بروح TradingView الحقيقية، قام مبتكر هذا النص البرمجي بجعله مفتوح المصدر، بحيث يمكن للمتداولين مراجعة وظائفه والتحقق منها. شكرا للمؤلف! بينما يمكنك استخدامه مجانًا، تذكر أن إعادة نشر الكود يخضع لقواعد الموقع الخاصة بنا.
Connect the dots to elevate your trading.
إخلاء المسؤولية
لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.