Fair Value Gap Fill Probability [PickMyTrade]Fair Value Gap Fill Probability applies a Gaussian Naive Bayes classifier — trained entirely within Pine Script® v6 — to every Fair Value Gap it detects, in order to estimate the posterior probability that each gap will be filled before it expires. Instead of treating all FVGs as equal, it asks a different question: given this gap's order-flow signature, geometry, and the time price has already spent nearby, how likely is it to actually fill?
――――――――――――――――――――――――――――――――――――――
🔷 WHAT IT MEASURES
🔸 Fair Value Gaps
A Fair Value Gap is the three-candle imbalance where an impulsive move leaves a price range untraded. A bullish FVG forms when the high of two bars ago sits below the current low; a bearish FVG forms when the low of two bars ago sits above the current high. Each gap is detected only on confirmed bar closes and is filtered by a minimum size relative to ATR, so noise gaps are ignored.
🔸 Three classifier features
When a gap forms, the classifier records three z-score normalised features that describe its context:
F1 — CVD Momentum : the rate of change of Cumulative Volume Delta at the moment the gap is created, normalised by its rolling mean and standard deviation. This encodes whether aggressive order flow was accelerating or fading as the imbalance formed.
F2 — Gap Geometry : the size of the gap expressed as a multiple of ATR. Larger relative gaps behave differently from small ones, and this feature lets the model separate the two.
F3 — Time-at-Price : the fraction of recent bars whose close fell inside the gap's price band. A zone the market has already revisited carries different fill odds than fresh, untested space.
🔸 Fill vs no-fill outcomes
Every gap is followed until one of two things happens: price trades to the gap's midpoint (a fill ), or the gap survives past the expiry window untouched (a no-fill ). Each resolved gap becomes a labelled training example, so the model learns continuously from the chart's own history.
――――――――――――――――――――――――――――――――――――――
🔷 THE CLASSIFIER
🔸 Welford online learning
Rather than storing arrays of past gaps, the classifier keeps running sufficient statistics — count, mean and variance — for each (feature × outcome) pair using Welford's numerically stable online update. Parameters shift gradually as market conditions change, with no fixed lookback buffer.
🔸 Gaussian likelihood + Bayesian posterior
Each feature is modelled as a Gaussian distribution under both the fill and no-fill classes. The three per-feature likelihoods are multiplied under the Naive Bayes independence assumption, combined with an empirically updated class prior, and normalised via Bayes' theorem to produce P(fill | F1, F2, F3) for the live gap. A warmup gate suppresses probabilities until enough fill and no-fill samples have accumulated, at which point the info table switches to LIVE.
――――――――――――――――――――――――――――――――――――――
🔷 SIGNALS AND DISPLAY
🔸 Probability-shaded zones
Each active FVG is drawn as a translucent zone with a crisp coloured border — blue for bullish, orange for bearish. The fill intensity scales with the posterior across three tiers, so a high-conviction gap reads instantly against a faint, low-probability one. Filled gaps turn grey so mitigation is obvious.
🔸 Live probability labels
Every open gap carries a running " X% fill " label that updates each bar as the classifier re-evaluates it. When a gap clears the high-probability threshold, a bold callout (" Bullish FVG · 81% fill prob ") marks it directly on the chart.
🔸 Info table
The corner table reports the live state — fill samples, no-fill samples, active gaps, CVD flow direction, and a LIVE / WARMUP status flag so you always know whether the model has enough data to be trusted.
――――――――――――――――――――――――――――――――――――――
🔷 INPUTS
ATR Period — basis for the minimum gap-size filter.
Min Gap Size (ATR ×) — gaps smaller than this multiple of ATR are ignored.
Max Active FVGs — cap on simultaneously tracked gaps.
Expire after N bars — unfilled gaps retire as no-fill samples after this many bars.
CVD Momentum Period — lookback for feature F1.
Z-Score Window — normalisation window for all three features.
Warmup Samples Per Class — minimum fill and no-fill samples before probabilities display.
High-Prob Threshold — posterior level that marks a gap as high-conviction.
――――――――――――――――――――――――――――――――――――――
🔷 REQUIREMENTS AND LIMITATIONS
The classifier requires a warmup period before probabilities are valid; on instruments with little history the table will read WARMUP until enough gaps have resolved. The CVD estimator is synthetic — derived from intrabar price position, not true bid/ask data — and is noisier on illiquid symbols. Because all three features are CVD- and geometry-derived, the Naive Bayes independence assumption is only approximately satisfied, so the posteriors are best read as relative confidence scores rather than calibrated frequentist probabilities. Fill rates are also regime- and timeframe-dependent and are historically associated with, not predictive of, future behaviour.
――――――――――――――――――――――――――――――――――――――
Built natively in Pine Script® v6. No external libraries, no data feeds, no fixed lookback arrays. The Gaussian Naive Bayes classifier trains continuously from the chart's own gap history using Welford's online algorithm. Open source — Mozilla Public License 2.0.
אינדיקטור Pine Script®






















