Multilevel Order Book Imbalance Momentum Backtesting

Hypothesis: When there strong order book imbalance (buy vs sell side liquidity) it is an indicator that the price of the asset is about to move in a certain direction. On a very high level, an imbalance on the bid side is expected to be a bullish indicator and ask side to be a bearish indicator.

The goal is to look at a certain number of price levels away from the top of the book (not just the very top) and calculate a weighted imbalance. If we observe a strong imbalance for a sufficient amount of time, we can execute a taker order with the expectation that the market will move in the direction we want. We exit when the imbalance reverses out of our ideal range.

Using the following metrics:

$n$: Number of price levels to analyze (each price level is on a $0.01 tick)

$t$: Imbalance threshold for entry

$l$: Persistence length: how many consecutive ticks must show imbalance

$w$: Weighting exponent

$I = \frac{\sum_{i=0}^{n-1} W_i \cdot \text{BidSize}i - \sum{i=0}^{n-1} W_i \cdot \text{AskSize}i}{\sum{i=0}^{n-1} W_i \cdot (\text{BidSize}_i + \text{AskSize}_i)}$

$a$: Round trip latency to and from the exchange. The total time it takes from the moment a tick with content inside of it is created on the exchange to the moment where the exchange creates the tick of our order/trade being processed is, in nanoseconds.

Market: The trading pair where this will be happening on

Timeframe: The inclusive timestamps for where we’d backtest this strategy

Assume this trading environment happens in a spot market. Our buy signal will be when we exceed the threshold, $I > t$, and when are NOT in a position.

Our sell signal will be if we are currently in a position and if we fall below $I < 0$. We’d assume only one position per asset at a time. If we see an exist signal but are currently not