OPEN-SOURCE SCRIPT
Updated

Order Flow Criticality Hawkes Branching Ratio

358
Order-Flow Criticality — Hawkes Branching Ratio


What it is

Most order-flow tools ask how strong flow is. This one asks how fragile it is — how close the tape is to a self-sustaining cascade, where each burst of aggressive flow tends to trigger the next. That property is the branching ratio (n) of a self-exciting (Hawkes) process: n ≈ 0 means bursts are independent and the tape is stable (exogenous); n → 1 means flow is nearly self-sustaining — endogenous, reflexive, fragile. The output is a state read that says size down as criticality rises. It never issues a buy or sell.

How it works (and why this method)


Event — a bar whose absolute signed volume-delta is unusually large for its time of day. Delta is built from finest-available lower-timeframe signed volume, with an automatic bar-shape fallback.
Branching ratio — fitting a Hawkes kernel by maximum likelihood is heavy and fragile, so this uses the model-independent moment estimator of Hardiman & Bouchaud (2014): for a self-exciting process the variance-to-mean ratio of the event count (the Fano factor) grows as 1/(1−n)², so n ≈ 1 − √(mean_count / var_count) over recent non-overlapping counting bins. Only a mean and a variance of counts are needed. A random (Poisson) tape gives n ≈ 0; a clustered tape gives n → 1.
De-seasonalization (the key honesty step) — this estimator is known to be biased upward by intraday seasonality: opens and closes have naturally higher flow, which can masquerade as criticality (a Poisson process with a changing rate can show a spurious n ≈ 1). So an event is judged against the typical flow for its hour, removing the daily rhythm so what remains is genuine self-excitation.
Output — a background tint that intensifies as n rises, ● event marks, a SIZE-DOWN tag on crossing the critical zone, and a dashboard stating STABLE / ELEVATED / CRITICAL with a suggested size factor (1 − n).


Everything advances only on confirmed bars; the lower-timeframe delta is read on closed bars. No hindsight.

The stability & multi-timeframe layer


States are dwell-filtered (standard anti-chattering): a new STABLE/ELEVATED/CRITICAL is announced only after surviving a set number of confirmed bars. STABILITY shows how settled the read is; PENDING shows a forming state with a countdown. Cost: a few bars of lag — stated and adjustable.
The criticality lane — a thin strip at the pane bottom — gives the glance-read: green = stable, amber = elevated, red = critical. Risk colors (safe/danger), never direction.
The HTF STACK row shows the raw criticality state on three higher timeframes derived as multiples of the chart (defaults 3×, 5×, 15×). Honesty notes: the HTF slots use the bar-shape delta proxy (lower-timeframe data cannot be nested inside a higher-timeframe request) and the global flow baseline instead of the hourly profile (an HTF bar spans multiple hours, so per-hour bucketing is ill-defined there). ✓ = every timeframe agrees; ⚠ = a higher timeframe is CRITICAL while the chart is not — fragility above your resolution.


Seeing the cascades


Every flow burst prints a dot below its own bar: blue = isolated (arrived independently), warm = chained (within a few bars of the previous burst — likely triggered by it). This is the branching ratio made visible: as the tape approaches critical you can watch chains lengthen at the price action itself.
The EVENTS row shows the recent % chained — the plain-language twin of n — and the branching-ratio row carries a fill gauge so the number reads like a fuel gauge.


How to use it


Add to any liquid symbol/timeframe; defaults suit index futures — change the volume source and lower-timeframe for other markets.
Read the dashboard headline: STABLE / ELEVATED / CRITICAL. As it rises toward CRITICAL, the branching ratio is telling you the tape is increasingly self-referential and prone to cascades.
Use it as a risk overlay on top of your directional tools: when criticality is high, cut size, widen stops, or stand aside — regardless of which way you lean. When it's low and stable, normal sizing is more justified.
Keep de-seasonalization on (default). Turning it off will make opens and closes look critical when they may just be busy.


What makes it original

Retail order-flow tools measure intensity and call it strength. This measures endogeneity — the degree to which flow is feeding on itself — using a published market-reflexivity statistic, computed by a moment estimator that is feasible on a chart, and de-seasonalized so it isn't fooled by the daily rhythm (the exact bias the literature warns about). Reframing order flow from "how strong" to "how fragile," as an explicit size-down gauge, is the contribution.

Concept credits

Self-exciting point processes — A. G. Hawkes (1971). Reflexivity / branching ratio as market endogeneity and flash-crash analysis — V. Filimonov & D. Sornette. Moment (mean/variance) branching-ratio estimator — S. Hardiman & J.-P. Bouchaud (2014). Hawkes models of order flow — E. Bacry, J.-F. Muzy and co-authors. Implementation and charting design are the author's own.

Important disclaimer

Research and education only. Not financial advice, not a signal service, not a guarantee of future results. The branching ratio is a descriptive statistic and a proxy — not a certainty and not a direction. High criticality does not predict which way price will move, only that flow is fragile. Validate independently and manage your own risk.
Release Notes
v1.1 — Finishing pass (no engine change)

- Added a Data Window (EXP_) export bus so the branching ratio, Fano factor and higher-timeframe
fragility flags can feed other scripts via input.source().
- Added the MPL-2.0 licence header.
- No change to the Hawkes branching-ratio engine, the fragility state, the multi-timeframe reads or
the dashboard — everyday behaviour is identical.

Descriptive fragility-monitoring tool, not investment advice.

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.