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).
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.