OPEN-SOURCE SCRIPT
VPIN Flow Regime [OutOfSampleLab]

VPIN Flow Regime visualises order-flow toxicity and buy/sell pressure directly on your chart, with non-repainting flow-price divergence. It describes the current state of the tape. It does not give buy or sell signals.
How it works
- Each bar's volume is split into buy and sell parts using Bulk Volume Classification: the buy fraction is the CDF of the standardised close-to-close change. Two paper-faithful variants are selectable: the standard-normal CDF (Easley, Lopez de Prado & O'Hara, 2012) or the fat-tailed Student-t CDF with 0.25 degrees of freedom (their 2016 paper). To our knowledge no other public script offers both.
- VPIN toxicity = sum |buy - sell| / sum volume over N bars. An unsigned measure of how one-sided flow has been. It is coloured by its own rolling percentile into a regime light: Quiet, Normal, Elevated, Burst.
- Buy pressure = net flow rescaled to 0-100 (50 = balanced).
- Divergence: when price makes a higher high (or lower low) that net flow does not confirm. Confirmed on pivots a few bars later, so it never repaints. By default the divergence lines and labels are drawn directly on the price chart.
Alerts
- Toxicity crossing into Elevated / Burst / back to calm.
- Bullish / bearish flow-price divergence.
All alerts are state-change events, not trade instructions.
Honest limitations (please read)
- This is a bar-based approximation of VPIN, not tick-level VPIN on a true volume clock. Read relative levels and percentiles, not absolute values.
- TradingView volume is feed-dependent; on many FX/index/CFD symbols it is tick count, not traded volume, and the reading is weak there. Prefer symbols with real volume.
- Aggressor classification is imperfect and depends on the window settings.
This is an impersonal educational tool that runs the same for everyone. Not financial advice, no performance claims.
References: Easley, Lopez de Prado & O'Hara (2012), Review of Financial Studies 25(5); (2016), Journal of Financial Economics 120(2); Lee & Ready (1991), Journal of Finance 46(2).
How it works
- Each bar's volume is split into buy and sell parts using Bulk Volume Classification: the buy fraction is the CDF of the standardised close-to-close change. Two paper-faithful variants are selectable: the standard-normal CDF (Easley, Lopez de Prado & O'Hara, 2012) or the fat-tailed Student-t CDF with 0.25 degrees of freedom (their 2016 paper). To our knowledge no other public script offers both.
- VPIN toxicity = sum |buy - sell| / sum volume over N bars. An unsigned measure of how one-sided flow has been. It is coloured by its own rolling percentile into a regime light: Quiet, Normal, Elevated, Burst.
- Buy pressure = net flow rescaled to 0-100 (50 = balanced).
- Divergence: when price makes a higher high (or lower low) that net flow does not confirm. Confirmed on pivots a few bars later, so it never repaints. By default the divergence lines and labels are drawn directly on the price chart.
Alerts
- Toxicity crossing into Elevated / Burst / back to calm.
- Bullish / bearish flow-price divergence.
All alerts are state-change events, not trade instructions.
Honest limitations (please read)
- This is a bar-based approximation of VPIN, not tick-level VPIN on a true volume clock. Read relative levels and percentiles, not absolute values.
- TradingView volume is feed-dependent; on many FX/index/CFD symbols it is tick count, not traded volume, and the reading is weak there. Prefer symbols with real volume.
- Aggressor classification is imperfect and depends on the window settings.
This is an impersonal educational tool that runs the same for everyone. Not financial advice, no performance claims.
References: Easley, Lopez de Prado & O'Hara (2012), Review of Financial Studies 25(5); (2016), Journal of Financial Economics 120(2); Lee & Ready (1991), Journal of Finance 46(2).
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.