Create your own
Lesson illustration

How Market Microstructure Affects Algorithmic Execution Prices

Hello. Last lesson compared equities and futures as instruments: their contract structure, leverage, trading hours, and liquidity conditions differ. Now we move one level closer to actual execution. A strategy may correctly forecast that a price will rise, but that is not enough: it must buy from someone willing to sell, at prices and quantities available when the order reaches the market.

This lesson develops the basic language of an order book—bid, ask, spread, depth, and liquidity—and turns it into a practical question for an algorithm: given my side and size, what price can I plausibly attain rather than merely observe on a chart?


The market is a two-sided quotation

At any instant, a tradable instrument typically has two relevant quoted prices:

  • The bid, : the highest currently displayed price at which someone is willing to buy.
  • The ask, : the lowest currently displayed price at which someone is willing to sell.

Since a seller generally wants more than a buyer offers, normally . The difference is the quoted bid-ask spread:

A common reference price is the midpoint:

The midpoint is useful for measuring price movements, signals, and execution quality, but it is usually not immediately tradeable. If the quote is bid , ask , and the midpoint is :

  • an immediately executable buy normally pays ;
  • an immediately executable sell normally receives ;
  • neither gets the midpoint merely by submitting an order.

That distinction is the first correction to a naïve backtest. A price series—often close prices or midpoints—describes a market value. Your algorithm’s P&L depends on an executable price.

A central limit order book records resting instructions to buy and sell at particular prices. The current bid and ask are simply the best prices visible at the top of those two stacks.

Demystifying the Central Limit Order Book (CLOB): Everything You Need to Know | Nasdaq

Read Anthony Clarke’s Nasdaq introduction for the core mechanics of a central limit order book. It establishes why the best bid and offer are not arbitrary numbers: they arise from resting orders and an exchange matching process.

In the section “What is a Central Limit Order Book?”, read the explanation of the book and matching. Focus on the fact that bids and asks are standing commitments at specific price levels, and that a transaction changes the book. Then read the following discussion beginning “CLOBs offer several advantages” through the paragraph on stop orders, focusing on how consolidated liquidity can support tighter spreads and better prices.

The spread is an immediate trading friction

Suppose you buy one share at the ask and immediately sell it at the bid, with no price movement:

So a round trip that crosses the spread costs approximately one full spread per share, before commissions, fees, and any price movement. For a one-way aggressive trade, the cost relative to the midpoint is approximately half the spread:

for a buy, and

for a sell.

“Approximately” matters. Quotes change continuously, and spreads can widen markedly during news, at the open and close, overnight, or when liquidity providers withdraw. The spread is therefore a state-dependent cost, not a fixed property of a ticker.

For a short-horizon strategy, this produces a hard economic constraint. If a signal forecasts an average gross gain of 2 basis points but a realistic entry-and-exit spread cost is 6 basis points, the signal is not tradable in that form—even if its direction is statistically predictive.


Depth: quantity matters as much as the best price

The best ask tells you the price for an immediate small buy. It does not promise that the entire intended order can trade at that price.

Market depth is the displayed quantity available at successive price levels on each side of the book. An ask-side snapshot might look like this:

Ask priceShares offeredCumulative shares available to a buyer
200200
500700
1,0001,700

For an immediate buy of 100 shares, the displayed book suggests a fill at . For 600 shares, it suggests 200 shares at and 400 at . The execution price is then the quantity-weighted average:

This is worse than the best ask. The order has walked the book: it consumed the available liquidity at one level and then traded against the next level.

More generally, let the ask side contain prices and quantities . For a buy order of total size , find enough levels such that their cumulative quantity reaches . The expected book-based average fill is:

where is the amount actually taken at level , satisfying and .

For a sell, the same reasoning applies on the bid side, but larger orders receive progressively lower prices. The relevant fact is asymmetric by side:

  • buys consume ask-side depth;
  • sells consume bid-side depth.

How Markets REALLY Work - Depth of Market (DOM)

Watch “How Markets REALLY Work – Depth of Market (DOM)” from Critical Trading for a compact visual account of how limit-order quantities become executable prices. The examples are deliberately simplified, which makes the mechanism easy to inspect before dealing with live, rapidly changing books.

Watch the DOM basics to distinguish displayed limit orders from incoming market orders. Then watch a market buy, observing how it consumes ask-side quantity and why time priority matters among orders at the same price. Finish with walking and gaps, focusing on why an order may need to trade at several worse price levels when nearby liquidity is exhausted or absent.

A cumulative order-book depth chart: green bid-side quantity lies below the current market, red ask-side quantity lies above it, and the white gap between them represents the bid-ask spread. Steeper or larger nearby areas indicate more displayed quantity at those prices.

The depth chart provides an intuitive picture. The gap between the nearest green and red regions is the spread. Moving outward from that gap shows how much displayed quantity is available as execution moves farther from the current market. Large steps or empty regions mean that a modest increase in order size can cause a disproportionately worse fill.

A crucial qualification: the chart is a snapshot, not a binding forecast. Other traders can cancel, submit, or execute orders between your data observation and your order’s arrival. Displayed depth can therefore be informative without being guaranteed liquidity.


Liquidity is the ability to trade your size with limited damage

It is tempting to call an asset “liquid” merely because it trades a large daily volume. That is incomplete. For an algorithm, liquidity is the capacity to trade a chosen amount, at a chosen time, reasonably quickly, with limited price concession and a sufficiently reliable chance of completion.

It has several connected dimensions:

DimensionWhat the algorithm observesWhy it affects attainable price
SpreadGap between best bid and askDetermines the initial cost of crossing the market
Top-of-book sizeQuantity at best bid and askDetermines whether a small aggressive order stays at one price
DepthQuantity across nearby levelsDetermines how severely a larger order walks the book
ResilienceWhether liquidity replenishes after tradesDetermines whether temporary pressure persists or the book refills
ImmediacyHow rapidly an order can executeDetermines the trade-off between certainty of execution and price control
StabilityHow rapidly quotes and sizes changeDetermines whether observed liquidity will still exist when the order arrives

A tight spread is encouraging, but it is not enough. Consider two instruments, each quoted at a one-cent spread:

  • Instrument A has 50 shares at the ask and little size beyond it.
  • Instrument B has 20,000 shares at the ask and substantial quantity at nearby levels.

For a 10-share trade, they may look similarly liquid. For a 5,000-share trade, they are entirely different execution environments. Liquidity is always conditional on order size, trade urgency, and market conditions.

A useful normalized size measure is a participation rate:

If an algorithm intends to buy 50,000 shares but only 100,000 shares typically trade during its intended ten-minute window, it is attempting to become half of that market’s activity. Treating the last traded price as its expected execution price would be implausible. Later in the course, participation rate will become central to market-impact and execution-schedule models.


From the visible quote to an attainable price

An algorithm’s attainable price is the expected price it can actually receive for its desired quantity, considering the current book, delay, order type, and the market’s response to its own trade.

For an aggressive buy, a simple first-pass estimate is:

For an aggressive sell:

Here, “additional slippage” captures effects that a static book snapshot cannot reliably predict:

  1. Latency and quote change. By the time the order reaches the venue, the best displayed price may be gone.
  2. Insufficient visible depth. The order may need to trade beyond the price levels included in available data.
  3. Your own impact. A large buy consumes sell liquidity; subsequent fills tend to occur at higher prices.
  4. Other participants’ activity. Competing orders can consume the same liquidity first.
  5. Stress conditions. During volatility spikes, both spreads and book instability commonly increase.

The difference between an intended reference price and actual fill price is usually called slippage. The reference must be specified, because “slippage” otherwise has no precise meaning. For example, a buy may be measured relative to the midpoint when the signal was generated, the best ask observed just before submission, or a benchmark such as the interval VWAP. Each answers a different question.

For execution research, one practical decomposition is:

At this stage, treat it as an accounting framework rather than a precise model. It prevents a common conceptual error: calling every unfavorable fill “market impact.” Part of the cost was already unavoidable the moment the strategy chose to buy at the ask or sell at the bid.

The short video below makes the book-walking calculation concrete.

How orders affect the order book

Watch Udacity’s “How orders affect the order book” for a direct numerical example of a sell order filling across several bid levels. It connects displayed depth to a volume-weighted actual execution price.

Watch the multi-level fill. Track the remaining shares after each price level is exhausted, then compare the best bid with the order’s average execution price. Reverse the sides mentally to see the equivalent process for a buy order consuming asks.


What the algorithm should and should not infer from a book

The book gives valuable information, but it does not reveal a complete supply-and-demand curve. Its quantities are orders that are currently displayed, not irrevocable promises about future liquidity.

Three cautions matter from the beginning:

First, displayed depth can disappear. A resting limit order can be canceled before your order reaches it. Therefore, do not use a favorable observed book snapshot as a guarantee of a future fill.

Second, hidden liquidity can exist. Some venue mechanisms allow only part of an order’s total size to be visible. Conversely, a large visible order may not indicate a durable price barrier. The right interpretation is probabilistic: depth changes expected cost and completion risk; it does not determine future direction.

Third, the relevant book may be fragmented. In a centralized futures market, one exchange’s order book can be a close approximation to the market available for that contract. U.S. equities trade across multiple exchanges and other venues, so execution quality depends on the consolidated market, routing, and the broker or execution system’s choices. The simple one-book model remains essential, but a production equity system needs broader market-data and routing awareness.

This leads to a disciplined research principle:

A historical price is not automatically a tradable price. A backtest should use assumptions consistent with the strategy’s side, order size, decision time, and market liquidity.

For a daily strategy trading a small fraction of a highly liquid stock’s typical volume, a conservative spread-and-slippage estimate may be adequate initially. For intraday or high-turnover trading, top-of-book data is often inadequate: you may need depth data, trade data, latency assumptions, and a fill model. The realism required should rise with the strategy’s demand for immediacy and liquidity.


Practical implications for a systematic strategy

Before deciding that a signal is deployable, an algorithmic workflow should ask:

  1. When exactly is the decision made? The relevant bid and ask are those available at the decision and submission time—not a later bar close.
  2. Which side will the strategy trade? A long entry buys at an executable ask-side price; a long exit sells at a bid-side price.
  3. How large is the order relative to available depth and expected volume? This determines whether top-of-book assumptions are credible.
  4. Must the order complete now? Greater urgency generally increases the expected price concession.
  5. Does the signal’s expected edge exceed conservative total trading costs? Gross predictive power is not tradable performance.

There is an inherent trade-off:

  • Seeking an immediate fill gives greater execution certainty but tends to cross the spread and consume depth.
  • Seeking a better price by waiting can reduce explicit spread cost, but introduces non-fill risk and the possibility that the market moves away before the order trades.

The next lesson studies that trade-off explicitly through market, limit, and stop orders, along with time-in-force instructions.


Key takeaways

  • The bid is the best displayed buying price; the ask is the best displayed selling price. The midpoint is a reference, not normally an immediately executable price.
  • The spread is an immediate friction: a buyer pays the ask and a seller receives the bid. Crossing the spread on entry and exit costs roughly one full spread before fees and other effects.
  • Depth is the quantity available across price levels. A sufficiently large order exhausts near prices and receives a volume-weighted average fill that is worse than the best quote.
  • Liquidity is multidimensional: tight spreads, substantial depth, resilience, speed of execution, and stable quotes all matter. It is conditional on your order’s size, time, and urgency.
  • An algorithm’s attainable price must include its side of the market, expected book-walking, fees, latency, and possible market impact—not just the price plotted on a chart.
  • Displayed book quantities are dynamic and incomplete. They inform execution estimates, but do not guarantee a fill or predict direction.

Next, we will examine how market, limit, and stop orders interact with this book, and how time-in-force constraints determine whether an algorithm prioritizes execution certainty, price control, or speed.

Can't find a good explanation? Sign up and we'll make it for you

Sign up