OPEN-SOURCE SCRIPT

FVG Intelligence - Fill Probability AI [Dots3Red]

4 872
📦 FVG INTELLIGENCE - FILL PROBABILITY AI [Dots3Red]
Every Fair Value Gap tool draws the gap. None of them tell you what usually happens to it. This script keeps records instead — every gap that appears on your chart is tracked all the way to its resolution, and when a new one forms, the script reports what the most similar past gaps on this chart actually did.

WHY THIS MATTERS
"Gaps get filled" is one of the most repeated assumptions in SMC trading — but it's rarely checked against the actual chart in front of you. Some instruments fill gaps quickly and reliably. Others leave them open for a long time, or never fill them at all. A gap formed on heavy volume during a strong trend behaves differently than one formed on quiet, choppy conditions.

This script doesn't assume any of that. It measures it. Every gap that resolves — filled or expired — becomes a data point: how big it was, what volume looked like when it formed, how volatile the market was, and where price sat relative to trend. When the next gap appears, the script finds the most similar historical gaps and reports their real outcomes.

📊 Fill 74% | ~6 bars | N=52
That reads as: of the 52 most similar gaps this chart has produced, 74% filled, taking about 6 bars on average. Measured history, not an assumption that "gaps always fill."


⚙️ HOW IT WORKS
📦 Detection — the standard 3-bar imbalance definition: a bullish gap exists when the current low sits above the high from two bars back, leaving an untraded price zone between them. Bearish gaps are the mirror. A minimum size filter (in ATR) discards micro-imbalances too small to carry real information.

🧠 The KNN engine — every gap is stored as five measurements the moment it forms: direction, size relative to ATR, volume behavior, volatility context, and position relative to the trend. When the gap resolves, the actual outcome — filled or not, and how many bars it took — is recorded against those five measurements. A brand-new gap is compared against this stored history, and the K most similar past gaps vote on fill probability and expected duration.

🎯 Fill definition — a gap counts as filled when price fully traverses it, reaching the far edge. This is the strictest standard (some traders count a midpoint touch as "filled" too) — deliberately conservative so the statistics mean exactly what they say.

📐 Near edge vs. far edge — each gap is drawn with two distinct boundaries. The edge price actually returns to first (the "near" edge) is shown with a solid line; the origin edge (the "far" edge, the one that defines a full fill) is shown dashed and dimmer. The fill inside fades from strongest near the solid edge to faintest near the dashed one, visually encoding which boundary carries more weight.

🔒 Non-repainting — detection, fill-checking, and outcome grading all happen strictly on confirmed bars. A gap's KNN read is calculated once, at the moment it forms, and its label stays fixed at that spot — it does not shift, recalculate, or repaint as the chart moves forward.


🧭 HOW TO USE
1️⃣ Check the sample count before trusting the percentage. "Fill 74% | N=52" is a real pattern; "Fill 74% | N=6" could easily be noise. The label always shows N so you can judge for yourself — the script won't display a probability at all until enough history exists ("Training…" appears instead).

2️⃣ Use the average bars figure as a timing expectation, not a countdown. "~6 bars" is the mean of gaps that did fill — it tells you the typical pace, not a guaranteed deadline for this specific gap.

3️⃣ Read the near/far edge distinction on the chart itself. The solid line is the boundary price will most likely interact with first; the dashed line is what a genuine full fill requires. A gap that's touched its solid edge but not yet reached the dashed one is still open, by this script's strict definition.

4️⃣ Watch the dashboard's global fill rate for chart-level context. Beyond any single gap, it tracks what percentage of every recorded gap on this chart has filled overall — useful for gauging whether this instrument tends to leave gaps open or close them reliably.

5️⃣ Adjust the fill window to the timeframe. A 30-bar window means something very different on a 1-minute chart versus a daily chart — tune it so "expired unfilled" reflects a genuinely meaningful amount of time for what you're trading.


🛠️ SETTINGS
📦 FVG Detection
• Min Gap Size — smallest imbalance the script will bother tracking
• Fill Window — bars allowed for a gap to fill before it's graded as expired
• Max Gaps Shown — how many open/recent gaps stay on the chart at once

📊 KNN Engine
• K Neighbors — how many similar past gaps vote on the current one
• Max / Min Training Samples — memory cap and the minimum before probabilities display
• ATR Baseline Period, Trend MA Length — the context windows used in matching

🎨 Visualization
• Keep Filled Gaps Visible — leave resolved gaps on the chart as faint gray outlines, or clear them for a cleaner view
• KNN Labels on Gaps — toggle the fill-probability readout
• Box Extension — how far each gap's zone projects forward while still open

🖥️ Dashboard
• Show/hide, position — open gap count by direction, chart-wide fill rate, KNN training progress, and the active fill window


📝 NOTES
Gap frequency and fill behavior vary significantly by instrument, timeframe, and market conditions — a volatile, fast-moving asset will accumulate the sample size needed for meaningful probabilities much faster than a slow, quiet one. On a new chart, expect a number of gaps to pass before the KNN read becomes genuinely informative rather than a placeholder.


⚠️ DISCLAIMER
This is an analytical and visualization tool. It does not generate trade signals and does not constitute financial advice. Historical fill rates do not guarantee how any specific future gap will resolve.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.