OPEN-SOURCE SCRIPT

Order-Flow Profile Microstructure & Calibrated Sweeps

1 834
Order-Flow Profile — Footprint, Microstructure & Calibrated Sweeps

A single-pane volume profile that reconstructs intrabar buy/sell activity, renders it as a footprint / delta heatmap with Point of Control and a 70% Value Area, layers a stack of market-microstructure factors over the same price bins, and then forward-tests every reversal signal it emits against realized outcomes. The dashboard reports measured edge with confidence intervals — not asserted edge.

It runs on any liquid symbol and any intraday timeframe. Defaults are tuned for index futures (e.g. NIFTY / BANKNIFTY); a few inputs adapt it to other instruments.


What it plots

Order-flow profile drawn to the right of price: each price bin colored by who controlled it (delta) with brightness scaled to volume, or a classic split footprint. The peak-volume row is the POC; a 70% Value Area is built outward from the POC.
Low-volume nodes / voids and four quadrant deltas that localize where buying and selling concentrated within the range.

A VPIN heat-glow background whose brightness rises with flow toxicity.
Sweep tags (ABS / EXH / DIV / REJ) at liquidity extremes, and a ⚡ reclaim-confirmed liquidity-sweep marker for the high-conviction stop-run-and-reclaim subset.
A calibration / key-reads dashboard (Compact by default, Pro on demand) that adapts its colors to your chart's background luminance.


Why these components belong in one script (component rationale)

This is not a bundle of unrelated indicators stacked together. Every component describes one object — the order-flow auction taking place inside the price profile — and each measures a different facet of it. They share one substrate (the price bins) and one validation spine (the calibration engine):


The profile says WHERE volume traded. POC, Value Area and voids are the structural skeleton — the price levels that matter.

Trade classification splits that volume into buy vs sell, giving every bin a delta. Bulk Volume Classification (a Student-t CDF on the standardized intrabar move) is used by default; on Premium plans, native bid/ask footprint can replace it, feeding the same bins. A tick rule classifies the same intrabars in parallel and the agreement % is reported, so you know when the trade-side read is fragile.

The microstructure factors qualify HOW that flow behaves at those levels. VPIN (informed vs balanced), multi-level OFI (depth-weighted imbalance across the bins), Kyle's λ and Amihud (price impact / illiquidity), and √-law absorption (flow soaked up vs fragile) each answer a question the raw profile cannot. They are computed over the very bins the profile draws.
The sweep layers detect reversals AT those levels — an order-flow taxonomy (absorption / exhaustion / divergence / rejection) plus a structural stop-run-and-reclaim. A Hawkes self-exciting intensity flags when sweeps are clustering (cascade risk).

A correlation-aware fusion (Kish design-effect shrinkage) combines the firing sweep's realized edge with the concurrent absorption and toxicity tells into a single reversal probability — shrinking redundant, correlated evidence so agreement among related signals cannot masquerade as independent confirmation.

The calibration spine forward-resolves every sweep and reports its hit rate versus base rate with a Wilson confidence interval. This is what ties the stack together: a factor only earns trust if the resolved outcomes say it does.

Remove any one layer and the others lose context: the profile without classification is just a volume histogram; the microstructure factors without the profile have no levels to attach to; the sweeps without calibration are unverified claims. Together they are a single, self-checking read of the auction.


How it works (mechanics)

Intrabar data. Lower-timeframe OHLCV is pulled with request.security_lower_tf (no lookahead). The lower timeframe is auto-derived from the chart timeframe or set manually.
Trade side. Bulk Volume Classification assigns each intrabar a buy fraction from a Student-t CDF of its standardized price change; delta = buy − sell. Where a Premium/Ultimate plan allows it, native request.footprint() real bid/ask volume per price replaces the reconstruction and feeds the identical bins.

Profile build. On the last bar, the chosen lookback of confirmed bars is accumulated into price bins; POC and the 70% Value Area are derived, voids and quadrant deltas computed.
VPIN. Volume is partitioned into equal-volume buckets; the average order imbalance across the last N buckets is the 0–1 toxicity read (with a percentile and background glow).
Impact factors. Stationarized (log-compressed, z-scored) OFI; depth-weighted multi-level OFI across the bins; Kyle's λ as the regression slope of return on signed flow; Amihud illiquidity as |return| per traded value.

Absorption. A displacement-normalized form and a √-law form (realized impact vs Y·ATR·√(|Δ|/V)): below the prediction = passive absorption / reversal candidate; above = fragile expansion.

Sweeps & fusion. At a swept extreme the bar is classified ABS / EXH / DIV / REJ; a Hawkes intensity tracks clustering; a Kish-decorrelated log-odds fusion outputs one reversal probability. Separately, a reclaim-confirmed liquidity sweep fires when price runs a confirmed swing pivot, closes back inside recovering a minimum fraction of the run, on a volume spike.

Calibration. Each sweep is queued and resolved a fixed horizon later against a moveATR·ATR threshold, recorded in R-multiples (MFE / MAE). The dashboard shows, per class: sample count, Hit% ± Wilson interval, Base% (the unconditional reversal rate over the same horizon), Edge (Hit − Base, starred at 95% significance), and average MFE / MAE.


Non-repaint: all detection is on confirmed bars, lower-timeframe arrays are confirmed intrabars, no dynamic-length built-ins are used, and the profile is drawn on the last bar from confirmed history. Pivots used by the liquidity sweep are confirmed before they can be swept.

What makes it original

It is built around calibration, not assertion. Most order-flow tools print a delta, a "confidence," or a footprint and leave it there. Here every reversal signal is forward-resolved against realized price and reported with a base rate and a Wilson interval, so the dashboard distinguishes a real edge from a small-sample illusion.

The agreement between Bulk Volume Classification and a tick rule is surfaced openly — a known weakness of reconstructed order flow is shown rather than hidden.
The microstructure factors are computed over the profile's own bins and decorrelated before fusion, so correlated flow signals don't inflate confidence.

It degrades gracefully from native exchange footprint (Premium) to reconstruction (every plan) with no change to the visual or the workflow.

All factor implementations are original Pine re-derivations of published methods; no code from other scripts is used.

How to use it

Apply to a liquid symbol on an intraday timeframe. Read the profile to see where volume concentrated (POC, Value Area, voids).

Watch the sweep tags and ⚡ liquidity-sweep markers at the edges of the range — these are reversal hypotheses, not guarantees.

Before trusting a sweep class, check its row in the calibration panel (switch the dashboard to Pro): is its Hit% above Base%, is the edge starred (significant), and is the Wilson interval tight enough to mean something?

Use the VPIN glow and fused reversal probability as context: bright background = one-sided / informed flow, which leans toward continuation and makes fades riskier.

The Compact dashboard summarizes the key reads (POC, VPIN, best calibrated edge, fused probability, liquidity-sweep status, auction efficiency); Pro expands the full per-class calibration table and every microstructure row.

Hidden EXP_* data-window series are provided for chaining into other scripts via input.source().

Data & markets

Works on whatever symbol the chart shows — nothing is hard-coded to an exchange or instrument. Defaults suit index futures on an intraday chart. For other instruments, adjust the Profile & Data Source group (lower-timeframe division, profile lookback) and, on a supporting plan, the native footprint settings. Reconstructed order flow is most reliable on liquid instruments with continuous volume.

Concept credits

This script operationalizes published methods; all implementations are original re-derivations.


Tick rule / trade sign — Lee & Ready (1991)
Bulk Volume Classification & flow toxicity (VPIN) — Easley, López de Prado & O'Hara (2012)
Order-Flow Imbalance — Cont, Kukanov & Stoikov (2014)
Multi-level / integrated OFI — Xu, Gould & Howison (2018)
Price impact (λ) — Kyle (1985)
Illiquidity ratio — Amihud (2002)
Self-exciting intensity — Hawkes (1971); Bacry, Muzy et al.
Square-root impact law — Almgren et al.; Tóth, Bouchaud et al.
Effective-sample decorrelation — Kish design effect
Market / auction profile (POC, Value Area) — Steidlmayer
Confidence interval — Wilson score interval (1927)

Disclaimer

For educational and informational purposes only. This is an analytical tool, not financial advice and not a solicitation to trade, and it is not a guarantee of future results. Order-flow classification from OHLCV is an estimate, not the true tape — without a Level-2 order book every delta here is a proxy (native footprint excepted). Always do your own research and manage risk; paper-trade before committing real capital.

免責聲明

這些資訊和出版物並非旨在提供,也不構成TradingView提供或認可的任何形式的財務、投資、交易或其他類型的建議或推薦。請閱讀使用條款以了解更多資訊。