Introduction to Quant Finance · Lesson 13
Orders: market, limit and stop
How the three basic orders turn into trades, and why the price you planned on isn't always the price you get.
Know the basics? Read the lesson notesWho is waiting to trade
To trade, you send an order: an instruction to buy or sell, sent to the market where buyers and sellers meet. Orders that can't trade straight away wait in a list called the order book.
Here is the book for a made-up share (a small piece of a company) at the start of a day. Above the middle are the asks: people waiting to sell, each at the lowest price they'll accept. Below are the bids: people waiting to buy, each at the highest price they'll pay. The bars show how many shares wait at each price.
The gap between the lowest ask and the highest bid is the spread. The last trade is the price of the most recent deal; it's what a chart shows as "the price".
Tap the best ask, the lowest price anyone is selling at. Then tap the best bid, the highest price anyone is buying at.
The order book of a made-up share (simulated)
Middle column: price in dollars. Bars and numbers: shares waiting at that price.
The best ask is 100.10 and the best bid is 99.90, so the spread is 100.10 − 99.90 = 0.20. The last trade, 100.00, sits between them: right now nobody is offering to trade at it.
Buy now
The simplest order is a market order: buy (or sell) now, at whatever price is on offer. You send a market order to buy 10 shares. The last trade was 100.00. What price do you pay?
The market order fills
When an order turns into a trade, we say it fills. Send the market buy and watch it fill. Then sell the same 10 shares straight back with a market sell.
The same book: your two market orders (simulated)
The row your order trades with lights up, and its shares go down by your 10.
- No trades yet
You bought at 100.10 and sold at 99.90. Nothing moved, yet you got back 0.20 a share less than you paid: the spread. On 10 shares, 0.20 × 10 = $2.00.
A market order buys at the best ask and sells at the best bid. It fills at once as long as someone is waiting on the other side. What it doesn't set is the price: you get whatever the other side is offering. Each of your trades also became the new last trade.
Name your price: the limit order
A limit order names a price, called the limit. A limit buy at 99.50 says: buy, but pay no more than 99.50. Nobody is selling that low right now, so the order waits in the book with the other bids. It fills only if the best ask comes down to 99.50 before the day ends.
Below are 20 made-up days that all start from this same book. Each runs from the open to the close (the day's first and last prices), and on each the price wanders at random, nothing planned. Play day 1, then try others. You can move your limit too.
One made-up day, from the open to the close (simulated)
Black line: the best ask, the price your limit buy waits for. Grey line: the best bid. Dashed: your limit. A dot marks a fill.
On day 1 the price never fell below the open: the lowest ask all day was the opening 100.10, so a limit buy at 99.50 waited all day and never filled. At 99.50 it filled on 12 of the 20 days, each time at 99.50.
Set the limit at 100.10 or higher and it fills at once, at 100.10: a limit is the most you'll pay, and a seller is already asking less. A limit order sets the price. Whether you trade at all is up to the market.
Sell if it falls: the stop order
Now say you hold 10 shares, bought at 100.10. A stop order waits for a price you choose, the stop price, and then becomes a market order. A sell stop at 99.40 says: if the best bid falls to 99.40 or below, sell at once at whatever the best bid is. People use it to try to limit a loss, so it's often called a stop-loss.
Play the same 20 days with a sell stop at 99.40 and watch what it sells at.
The same 20 days, with a sell stop (simulated)
Black line: the best bid, the price that triggers your sell stop. Grey line: the best ask. Dashed: your stop. A dot marks where it sold.
At 99.40 the stop sold on 14 of the 20 days. On 12 it sold at exactly 99.40. On 2 it sold at 99.30: the bid jumped from 99.50 straight to 99.30 (prices move in steps of 0.10), skipping 99.40 but still at or below the stop.
A stop decides when you sell. The price is whatever the best bid is at that moment.
Overnight
Go back to day 1 and picture you still hold the 10 shares at its end. The best bid at the close is 100.10, and you place a sell stop at 99.00.
The market shuts overnight. Bad news comes out while it's shut, and when it opens the next morning, the highest price any buyer offers is 95.00. The price has jumped straight past your stop, with no trades in between. A jump like that is called a gap.
Your stop is at 99.00 and the market opens at 95.00. What happens to it?
The gap
The end of day 1, the night, and the start of the next morning. Open the market and watch your stop.
Day 1's close, the night, and the next morning (simulated)
Black line: the best bid, the price that triggers your sell stop. Grey line: the best ask. Dashed: your sell stop at 99.00. A dot marks your sale; the bid kept falling after it.
The difference between the price you planned on and the price you got has a name: slippage. Here it's 95.00 − 99.00 = −4.00 a share, or $40 less on your 10 shares. A stop gives no promise about the price. After a gap it sells wherever the market opens.
The three fill rules
A market order, a limit order and a stop order are each a rule for when the order fills (turns into a trade) and at what price. Below, "the other side's best price" means the best ask when you buy and the best bid when you sell. As rules, checked at every moment until the order fills:
market order: fill now, at the other side's best price limit order at L: if the other side's best price is L or better: fill, at L or better else: wait (it may never fill) stop order at S: if the price has reached S: become a market order else: wait
- the other side's best price
- for a buy, the best ask; for a sell, the best bid
- L
- the limit price. "L or better" means L or lower for a buy, L or higher for a sell
- S
- the stop price. "Reached S" here means the best bid falls to S or below for a sell stop, or the best ask rises to S or above for a buy stop
Market buy: filled now at the best ask, 100.10. Limit buy at 99.50 on day 1: the best ask never got to 99.50 or lower, so it waited all day: no fill. A sell limit at 100.50 (sell, but only at 100.50 or better) sent at the open: the best bid, 99.90, is below 100.50, so it waits, and fills only if the bid rises to 100.50 or higher. Sell stop at 99.00 overnight: the bid opened at 95.00, already below 99.00, so the stop was reached and it became a market sell and filled at the best bid, 95.00.
- your order is small enough to fill at one price (yours were 10 shares, and at least 20 waited at every price);
- a waiting limit buy fills only when the best ask reaches L. In a real market it can also fill when a seller sells straight to your bid;
- stops trigger on the best bid or ask. Many brokers trigger them on the last trade instead.
A big order uses up the shares at the best price and fills at worse ones (lesson D14, The order book).
Try the rules on new numbers. The best bid is 49.80 and the best ask is 50.00. You send a limit buy at 50.20. What happens?
Slippage: planned price against filled price
The difference between the price you got and the price you planned on is called slippage. Write down the planned price before you send the order, then measure:
- fill
- the price your order actually traded at
- intended
- the price you planned on: for a stop, the stop price; for a limit, the limit; for a market order, the best price on offer (the ask for a buy, the bid for a sell) when you decided
- shares
- how many shares the order traded
For a buy, slippage above 0 means you paid more than planned; for a sell, below 0 means you got less. For a buy, a negative number is better than planned; for a sell, a positive one is. A limit can fill better than its limit, which is slippage in your favour: a buy limit at 25.00 that fills at 24.80 has 24.80 − 25.00 = −0.20.
For a market order we measure from the ask or bid, not from the chart's last trade, because that last trade was not a price you could buy at. The spread covers that gap: it is a cost too, but it is not slippage. Your market buy at 100.10 had no slippage, and still paid the spread.
A sell stop at 99.00 filled at 95.00: 95.00 − 99.00 = −4.00 a share, so you got 4.00 a share less than planned. Total: −4.00 × 10 shares = −$40.
- the order fills at one price;
- the intended price is fixed before the order is sent, not picked afterwards.
A limit that never fills has no fill, so no slippage, yet the missed trade can cost more than slippage would have.
Try it on new numbers. A buy stop at 50.00 buys once the best ask rises to 50.00 or above; traders use one to buy only after the price has risen past a level. Overnight news, and the next morning the best ask opens at 52.40. What is the slippage, per share?
What this means for a backtest
A backtest runs a trading rule over past prices to see what it would have made. It has to decide, for every order, whether it filled and at what price. Three things follow. Turn them over one at a time.
- Every backtest uses a fill rule, stated or not.
Filling at the last trade, the price on the chart, leaves out the spread, a cost separate from slippage: a real market order buys at the ask and sells at the bid. Look for the fill rule in the backtest's settings or notes.
- A limit that never filled is a trade that never happened.
A signal is the moment the rule decides to place an order. The backtest has to check that the price really reached the limit, and leave the other signals out. Counting every signal as filled at its limit counts trades that never took place.
- A stop fills at the first price after it triggers.
After a gap that is the open, not the stop. A backtest that fills every stop at its stop price makes its worst mornings look smaller than they were.
Your own stop, gapped
How many dollars less than planned do the 200 shares bring in?
Hint: the stop becomes a market sell at the open. Slippage per share = fill − intended. Then multiply by the shares.
A course's backtest
What is wrong with how it counts?
Stops in your own backtest
What does that do to its results on those mornings?
Selling with a limit
What is the slippage, per share? (Use a minus sign if it's below 0.)
Hint: for a sell, the other side's best price is the best bid. Is it already 62.00 or better? Then slippage = fill − intended.
Lesson done
An order is a rule for when you trade and at what price. A market order trades now. A limit order sets the price but may never trade. A stop order waits, then trades at whatever price is on offer, which after a gap can be far from the stop. The difference between the price you planned on and the price you got is slippage.
Key ideas
- Order book
- the orders waiting to trade: bids (to buy) and asks (to sell), with prices and sizes
- Best bid / best ask
- the highest price a buyer is offering / the lowest price a seller is asking
- Spread
- best ask − best bid; a cost of trading, separate from slippage
- Fill
- an order turning into a trade, and the price it traded at
- Market order
- fills now, at the other side's best price
- Limit order
- fills only at its limit price or better; may never fill
- Stop order (stop-loss)
- waits until the price reaches the stop, then becomes a market order
- Gap
- a jump in price with no trades in between, often from one day's close to the next open
- Slippage
- fill − intended price
Formulas
slippage = fill − intended · total = slippage × shares · spread = best ask − best bid
Market: fill now at the other side's best price. Limit at L: if the other side's best price is L or better, fill at L or better, else wait. Stop at S: if the price has reached S, become a market order, else wait.