VPIN Flow Toxicity Meter MT5
- Indicatori
-
Anthony Cooke
Quantitative Systems Architect and C++, Python, MQL5, MQL4, and Pine Script developer specializing in non-repainting mathematical indicators, Expert Advisors, and statistical strategy audits. I combine industrial quality-control engineering and Applied Mathematics with multi-physics market modeling - Versione: 1.0
- Attivazioni: 5
OVERVIEW AND SCIENTIFIC ORIGIN
The VPIN Flow Toxicity Meter is an institutional order-flow and market-microstructure indicator engineered from High-Frequency Market-Making Theory (Volume-Synchronized Probability of Informed Trading, introduced by David Easley, Marcos Lopez de Prado, and Maureen O'Hara). In electronic exchanges and institutional liquidity desks, market makers track order-flow toxicity to measure adverse selection risk—the moments when informed institutional buyers or sellers flood one side of the order book faster than liquidity providers can rebalance, causing spreads to widen and rapid directional sweeps to erupt.
Built with strictly causal, non-repainting calculation and automatic empirical self-calibration, this indicator brings volume-synchronized order-flow analysis to Forex pairs, Gold (XAUUSD), Silver (XAGUSD), and Indices without requiring external Level-2 data feeds.
THREE-STEP VOLUME-SYNCHRONIZED MATHEMATICAL ENGINE
Standard time-based volume oscillators get distorted during quiet sessions because low-activity clock bars receive the same weight as high-volume institutional bursts. This indicator transforms raw chart data into volume-time across three sequential causal steps:
Step 1 - Bulk Volume Classification (BVC):
On every closed bar, the indicator normalizes log-returns against rolling 55-bar return volatility (InpVolPeriod = 55) and passes the standardized return through a causal Standard Normal Cumulative Distribution Function (CDF). This probabilistically splits each bar's tick volume into estimated buyer-initiated volume and seller-initiated volume.
Step 2 - Equal-Volume Bucket Transformation (Volume-Time):
Starting at the current bar and sweeping backward in volume-time, the engine fills N equal-volume buckets (InpNumBuckets = 10 by default), where each bucket size adapts dynamically to InpBucketMult (3.0x) times the rolling 55-bar average bar volume. Quiet low-volume chop merges together inside a single bucket while concentrated institutional order sweeps fill multiple buckets rapidly.
Step 3 - Raw VPIN and Empirical Toxicity CDF Percentile:
Across the N completed buckets, the algorithm calculates Raw VPIN (0.000 to 1.000, the mean absolute buy-minus-sell imbalance per bucket) alongside Net Order Flow percentage (-100% to +100%). It then ranks Raw VPIN against a rolling Empirical CDF window (InpCdfPeriod = 100 bars) to output an intuitive 0% to 100% Toxicity Percentile that self-calibrates automatically across every symbol and timeframe.
SUBWINDOW VISUAL GUIDE
Subwindow Scale (0.0 to 105.0, with dashed horizontal reference levels at 80.0, 50.0, and 20.0):
- DeepSkyBlue Histogram (Flow_Balanced, below 50%): Normal two-sided liquidity and balanced order flow with low adverse-selection risk.
- Gold Histogram (Flow_Elevated, 50% to 80%): Informed institutional order flow clustering and building one-sided directional pressure.
- Crimson Histogram (Flow_Toxic, 80% and above): Critical order-flow toxicity; severe one-sided imbalance where market-maker liquidity thins and rapid price sweeps accelerate.
- WhiteSmoke Smooth Line (VPIN_Toxicity_Curve): 4-bar EMA structural toxicity trend line filtering single-bar noise.
- Magenta Dot (Toxic_Burst_Alert): Hysteresis-locked adverse-selection alert dot plotted on the WhiteSmoke curve when toxicity first crosses 80% or higher. To prevent repetitive dot clutter, the trigger automatically stays locked until toxicity cools back below 50%.
DARK TELEMETRY HUD BOX LINE-BY-LINE GUIDE
Located in the upper-right subwindow inside a solid dark slate panel with a DodgerBlue border so tall bars never cover the text:
- Line 1 (VPIN FLOW TOXICITY): Displays the live empirical toxicity percentile and active regime (BALANCED FLOW in DeepSkyBlue, ELEVATED CLUSTERING in Gold, or TOXIC ALERT in Crimson at 80% and above).
- Line 2 (RAW VPIN and NET FLOW): Displays the unranked Raw VPIN imbalance (0.000 to 1.000) paired with directional Net Flow dominance—BUY DOMINANT in MediumSeaGreen (at or above +5%), SELL DOMINANT in OrangeRed (at or below -5%), or BALANCED in Silver—so you immediately see which side informed order flow is pushing.
- Line 3 (VOL BUCKET): Reports the live adaptive equal-volume bucket threshold in ticks, the active bucket multiplier (x3.0), and the number of buckets N in the rolling window (N=10).
- Line 4 (MARKET MAKER): Translates microstructure readings into a direct institutional liquidity state: NORMAL LIQUIDITY, INFORMED FLOW BUILDING, or ADVERSE SELECTION RISK (highlighted in Magenta during toxic bursts).
PRACTICAL USAGE
Avoiding Adverse-Selection Traps (Mean-Reversion and Grid Protection):
When histogram bars turn Crimson above 80%, a Magenta Toxic_Burst_Alert dot fires, and HUD Line 4 flashes ADVERSE SELECTION RISK, avoid fading the move or running mean-reversion bots against the dominant flow direction shown on HUD Line 2.
Confirming Institutional Breakout Pressure:
Combine rising Gold (50% to 80%) transitioning into Crimson (>=80%) toxicity with the directional tilt on HUD Line 2 (BUY DOMINANT or SELL DOMINANT). High toxicity paired with strong directional net flow confirms one-sided institutional participation behind a breakout rather than thin retail drift.
Normal Liquidity Range Conditions:
When bars remain DeepSkyBlue below 50% and Line 4 reads NORMAL LIQUIDITY, two-sided market making is active and standard support/resistance or pullback structures tend to behave cleanly.
TECHNICAL SPECIFICATIONS AND INPUT PARAMETERS
Calculation Engine:
100 percent causal bar-by-bar execution with zero repainting, zero backpainting, and zero external DLL calls. Subwindow short name: VPIN_Toxicity(10).
Volume-Time Engine Inputs:
- InpVolPeriod (Default: 55): Rolling baseline window for return volatility (BVC) and average bar tick volume.
- InpBucketMult (Default: 3.0): Equal-volume bucket size expressed as a multiple of average bar volume.
- InpNumBuckets (Default: 10, Range 3 to 40): Number of equal-volume buckets averaged per VPIN window.
- InpCdfPeriod (Default: 100): Rolling bar lookback used to rank Raw VPIN into an Empirical CDF Percentile (0% to 100%).
Thresholds and Display Inputs:
- InpWarnLevel (Default: 50.0): Empirical percentile threshold shifting bars from DeepSkyBlue to Gold (also acts as the hysteresis reset level for Magenta burst dots).
- InpToxicLevel (Default: 80.0): Empirical percentile threshold triggering Crimson Flow_Toxic bars, Magenta Toxic_Burst_Alert dots, and ADVERSE SELECTION RISK HUD warnings.
- InpShowHUD (Default: true): Toggles the 4-line dark telemetry panel (automatically bypassed during Strategy Tester optimization).
- InpMaxBars (Default: 2500): Maximum historical bars calculated on initial load for fast multi-chart performance.
Expert Advisor Integration (iCustom Buffer Map):
- Buffer 0: Flow_Balanced (DeepSkyBlue bars below InpWarnLevel)
- Buffer 1: Flow_Elevated (Gold bars between InpWarnLevel and InpToxicLevel)
- Buffer 2: Flow_Toxic (Crimson bars at or above InpToxicLevel)
- Buffer 3: VPIN_Toxicity_Curve (WhiteSmoke 4-bar EMA percentile curve)
- Buffer 4: Toxic_Burst_Alert (Magenta hysteresis-locked toxic alert dot)
- Buffer 5: Raw_VPIN (Hidden continuous unranked 0.000 to 1.000 VPIN value)
- Buffer 6: Net_Order_Flow_Pct (Hidden continuous signed -100% to +100% directional buy/sell flow imbalance)
TIMEFRAME AND VOLATILITY CALIBRATION (CUSTOMIZE TO YOUR CHART)
The default settings (55 volume period, 3.0x bucket size, 10 buckets, 100-bar CDF, 50%/80% levels) adapt automatically across Forex majors, crosses, Gold, and Indices on M15 to H1 charts, and can be tuned to match your execution speed:
- Fast Intraday Order-Flow Monitoring (M5 to M15): Lower InpBucketMult to 1.5 to 2.0 and InpNumBuckets to 6 to 8 so volume buckets fill faster during active London and New York opening surges.
- Smoother Macro Institutional Flow (H1 to H4): Increase InpBucketMult to 4.0 to 5.0, raise InpNumBuckets to 15 to 20, and extend InpCdfPeriod to 150 to 200 to isolate only major multi-session liquidity imbalances.
- Stricter Alert Filtering: Raise InpToxicLevel to 85.0 or 90.0 if you only want Magenta Toxic_Burst_Alert dots to trigger on extreme tail-event order-flow sweeps.
-----Trading on MetaTrader 4 instead of MetaTrader 5?
The identically engineered MetaTrader 4 edition of VPIN Flow Toxicity Meter is published on my MQL5 Seller Profile with the exact same thumbnail, Bulk Volume Classification, volume-synchronized bucket engine, dark telemetry HUD, and parameter set. Visit my seller profile to access the MT4 version.
