Order flow trading is based on a simple premise: the imbalance between aggressive buying and selling predicts short-term price direction. It requires tick data — OHLCV candles do not contain aggressor information.
The Core Metric: Delta
import polars as pl
df = pl.read_parquet("BTC_trades.parquet")
delta = (
df.with_columns([
pl.when(~pl.col("is_buyer_maker"))
.then(pl.col("qty")).otherwise(-pl.col("qty"))
.alias("delta_qty")
])
.group_by_dynamic("time", every="1m")
.agg([
pl.col("delta_qty").sum().alias("delta"),
pl.col("qty").sum().alias("total_volume"),
pl.col("price").last().alias("close"),
])
.sort("time")
.with_columns(pl.col("delta").cum_sum().alias("cum_delta"))
)
print(delta.tail(10))
Delta Divergence: The Key Signal
When price makes a new high but cumulative delta does not, buying pressure is not behind the move — a warning the rally may not sustain. The reverse (new low, flat delta) suggests sellers are exhausted. These divergences are invisible in candlestick charts.
Practical Limitations
Order flow signals decay within minutes to hours — most useful for intraday strategies. They require high-quality tick data: timestamp errors or incorrect aggressor labels corrupt the signal completely. Always verify data quality before building on top of it.
Summary
Delta, cumulative delta, and volume profile are the three core order flow metrics — all computable from tick data in a few lines of Polars. The signals are real but short-lived, requiring high data quality and careful validation.