OPEN-SOURCE SCRIPT
Updated

Order Flow Criticality Hawkes Branching Ratio

554
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.
Release Notes
v1.2 — Fragility velocity: is criticality building or easing? An early warning, before the critical line is crossed.

The original tool tells you how fragile the tape is right now — the Hawkes branching ratio n, where n→1 means order flow is becoming self-sustaining and a cascade is more likely. What it didn't tell you was the direction of travel: a branching ratio of 0.65 that is climbing fast is a very different situation from a 0.65 that is subsiding, yet both read as "ELEVATED." This update adds that missing dimension.

What's new

Fragility velocity. The change in the smoothed branching ratio over a short, adjustable window (default 10 bars). Positive = criticality building; negative = easing. Because it moves before n reaches the critical threshold, a rising velocity while the tape is merely ELEVATED is an early warning that it is heading toward CRITICAL — visible ahead of the SIZE-DOWN tag, not after it.
FRAGILITY TREND row on the dashboard: ▲ building (red — risk rising), ▼ easing (green — risk subsiding), or • steady, with the signed velocity value. It sits directly under the branching-ratio and suggested-size rows, so the trend is read right next to the level.
"Fragility accelerating" alert — fires once when the branching ratio starts rising fast while the tape is elevated but not yet critical. This is the actionable moment: the tape is tightening but hasn't cascaded, so there is still time to reduce size before the critical print.
New export EXP_CriticalityVelocity in the Data Window, for other scripts.

How to use it

Treat the trend as a lead on the level. ELEVATED + ▲ building is the caution state — the branching ratio is climbing and the accelerating alert is designed to catch exactly this. ELEVATED + ▼ easing is the tape stepping back from the edge. The suggested-size factor (1 − n) still scales your risk off the level; the trend tells you which way that number is about to move.

What is unchanged. The branching-ratio moment estimator (Hardiman-Bouchaud), the de-seasonalization by time of day, the flow-burst event definition, the minimum-dwell state debounce, the multi-timeframe stack and every existing export and alert are exactly as in v1.1. Velocity is a pure read of the branching ratio the tool already computes; it feeds nothing back into the estimator.

Still a fragility monitor, not a signal service: it scales risk, it never picks a side. The branching ratio is a descriptive proxy of past flow on this chart, computed on confirmed bars (non-repainting), not a prediction. Concept credits are unchanged (Hawkes 1971; Filimonov & Sornette; Hardiman & Bouchaud 2014; Bacry-Muzy). Research/education only — not financial 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.