Institutional Order Flow Signals [PMT]Institutional Order Flow Signals applies a Gaussian Naive Bayes classifier — trained entirely within Pine Script® v6 — to cumulative volume delta divergence in order to surface, in real time, three mutually exclusive market regime states: bullish re-alignment, bearish re-alignment, and order flow divergence.
The core question this indicator addresses is distinct from threshold-crossover approaches: given the current statistical pattern of delta momentum, price/CVD divergence, and delta slope, what is the posterior probability that the market is entering — or exiting — a directional institutional order flow regime?
――――――――――――――――――――――――――――――――――――――
🔷 WHAT IT MEASURES
🔸 Cumulative Volume Delta (CVD)
CVD is the running sum of intrabar net order flow — buy volume minus sell volume — estimated via the close-position formula: bull_vol = volume × (close − low) / (high − low). The cumulative series tracks persistent institutional buying or selling pressure independently of price direction, making it a first-order proxy for directional order flow without requiring exchange-level bid/ask data.
🔸 Three Z-Score Normalised Features
Each bar, the classifier receives three inputs derived from CVD and z-score normalised for cross-instrument compatibility:
F1 — CVD Momentum : rate of change of CVD over N bars, normalised by its rolling mean and standard deviation. Encodes how rapidly buying or selling pressure is accelerating relative to its own recent baseline.
F2 — Price/CVD Divergence : price rate of change minus CVD rate of change. A large positive value signals price rising while order flow is falling — the classic institutional distribution pattern. Near-zero values indicate price and flow agreement.
F3 — CVD Slope : linear regression slope of CVD over a short window, z-score normalised. Provides a direction-of-flow signal independent of F1's momentum measure, satisfying the Naive Bayes conditional independence assumption as closely as CVD-derived features can.
🔸 Market Regime Labels
Three mutually exclusive regimes are recognised. A bullish re-alignment bar is one where both price ROC and CVD ROC are positive — institutional flow and price confirm each other to the upside. A bearish re-alignment bar is the symmetric case. A divergence bar occurs when price and order flow point in opposite directions — historically associated with regime transitions and distribution/accumulation activity.
――――――――――――――――――――――――――――――――――――――
🔷 THE CLASSIFIER
🔸 Welford Online Learning
The classifier accumulates running sufficient statistics — count, mean, and variance — for each of the nine (feature × regime) combinations using Welford's numerically stable online update. No historical arrays are stored. The model's parameters shift gradually with each new bar, making it adaptive to changing market microstructure conditions without a fixed lookback window.
🔸 Gaussian Likelihood + Bayesian Posterior
Each feature is modelled as a Gaussian distribution under each class. The joint likelihood of the current feature vector is computed by multiplying the three per-feature probability densities under the Naive Bayes independence assumption. A class prior — updated empirically from observed regime frequencies — is combined with the joint likelihood via Bayes' theorem to produce posterior probabilities P(Bull | F1,F2,F3) and P(Bear | F1,F2,F3) for the current bar. A warmup gate suppresses signals until the classifier has accumulated statistically meaningful training observations.
――――――――――――――――――――――――――――――――――――――
🔷 SIGNALS AND DISPLAY
🔸 High-Conviction Buy — P(Bull) > 85%
A long signal fires when the bull posterior clears the configurable threshold, CVD momentum confirms, and price is above the trend EMA. The threshold is surfaced on the label itself, making the confidence level explicit at every entry rather than hidden inside an opaque signal.
🔸 Bear Signal — CVD Divergence
A short signal fires when the bear posterior clears threshold and F2 is in active divergence territory — price moving up while order flow is declining, or the symmetric distribution case. CVD divergence without posterior confirmation does not produce a signal; both conditions are required simultaneously.
🔸 Bull Regime Band — CVD Aligned
A fill band anchored to the trend EMA expands when the classifier assigns high posterior probability to a sustained bullish re-alignment regime. The opacity of the band scales with the posterior — faint during low-confidence periods, saturated when the classifier considers the regime firmly established.
🔸 Info Table
Live readout displays current bull and bear posteriors, CVD direction, and training bar count. The Trained N counter confirms the classifier has completed warmup before acting on any signal.
――――――――――――――――――――――――――――――――――――――
🔷 INPUTS
Classifier Lookback — minimum training bars before signals activate. Default 100.
Entry Posterior Threshold — minimum posterior required. 0.60 permissive; 0.70 default; 0.80 high-conviction only.
CVD Momentum Period — lookback for F1 and F2 rate of change.
CVD Slope Period — regression window for F3.
Z-Score Period — normalisation window applied across all three features.
Trend EMA Period — macro filter; long signals only fire above EMA, short signals below.
――――――――――――――――――――――――――――――――――――――
🔷 REQUIREMENTS AND LIMITATIONS
The classifier requires a warmup period before signals are valid. The CVD estimator is synthetic — derived from intrabar price position, not actual bid/ask data — and introduces noise on instruments with low liquidity or wide spreads. The Naive Bayes independence assumption is partially violated because all three features are CVD-derived; the posteriors function as relative confidence scores rather than calibrated frequentist probabilities.
――――――――――――――――――――――――――――――――――――――
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 bar history using Welford's online algorithm. Open source — Mozilla Public License 2.0.
Pine Script® インジケーター






















