A person who makes a mistake usually makes it once. A program can make the same mistake hundreds of times a minute. By the end of this lesson, you'll know how a small coding slip turns into runaway orders, and the common kinds of bug. And you'll see what two real cases from the past show.
1 of 8
What you'll learn
- Spot how runaways start. A rule stays true and a check like no open trade is missing.
- Check units and direction. Ticks coded as points or a swapped side are common bugs.
- Confirm the contract and account. A wrong one, or old code left on, trades for real.
- Study two real cases. One, from 2012, shows how fast faulty code can do damage.
- Guard every order. Write the condition that stops it being sent twice.
Exercise
- Read the rules you wrote for Turning rules into exact logic.
- For each order your rules send, write the condition that stops it being sent twice, such as “only if there's no open trade”.
Quick check
1. A rule says “if price is above the line, buy 1” and nothing else. What can happen?
2. A 10-tick stop is coded as 10 points on the Micro S&P 500. How much wider is the stop?
3. What did the 6 May 2010 sell program leave out, according to the CFTC and SEC report?
0 of 3 answered.
Finished this lesson?
Tick it off and keep your place
Read the full notes
A small coding slip, such as a missing “no open trade” check, can make a program send the same order again and again; real cases such as Knight Capital in 2012 and the 6 May 2010 sell program show how fast code can do damage when nothing limits it.
- Orders a program keeps sending again and again because of a mistake in its code or settings, far beyond what was meant.More in the glossary usually start with a rule that stays true and a missing condition, such as “and there's no open trade”. Each loop buys again until a person, a limit or the Money kept in a futures account as a deposit to cover losses on open contracts. It isn’t a fee or a down payment, and losses can be bigger than it.More in the glossary stops it.
- Common bugs: units (ticks meant, points coded: on the A small futures contract on the S&P 500, traded at CME Group. Each point is worth $5, and its smallest step of 0.25 is worth $1.25.More in the glossary a point is 4 The smallest step a price can move. On many stock index futures that’s 0.25 of a point.More in the glossary); direction swapped; the wrong contract (Moving from a futures contract that’s about to expire to the next contract month.More in the glossary, full-size instead of A smaller version of a futures contract. It moves in the same steps as the full-size one, but each step is worth less, often a tenth as much.More in the glossary) or the wrong account; old code left switched on. More bugs to look for: Coding mistakes to look for.
- Knight Capital, 1 August 2012 (SEC press release, 2013): in the first 45 minutes after the open, its system sent more than 4 million orders while trying to fill 212 customer orders. Cause: a function left defective by an old code change, set off by new code deployed in July 2012. Loss: more than $460 million.
- 6 May 2010 (joint CFTC and SEC report): a sell program for 75,000 The main size of stock index futures contract at CME Group. The E-mini S&P 500 is worth $50 a point, ten times the Micro S&P 500.More in the glossary S&P 500 contracts (about $4.1 billion) was set to 9% of the previous minute's volume, without regard to price or time, and ran in about 20 minutes. CME's stop logic (A CME Globex safety feature. When price moves a set number of ticks within a set time, matching pauses for a moment, while orders can still be sent, changed and cancelled.More in the glossary) paused E-mini trading for 5 seconds at 2:45:28 pm. See A very fast, deep fall in prices that mostly recovers within minutes. The best-known one hit US markets on 6 May 2010.More in the glossary.
- Made-up: 1 contract every 5 seconds for 2 minutes = 24 contracts; a 4-point fall: 24 × 4 × $5 = −$480 instead of −$20. Answer to the drill: 18 contracts, −$450. More: What can go wrong with automated trading.
Worked example
Made-up numbersA small runaway
Made-up numbers · Micro S&P 500 · $5 a point · 1 contract every 5 seconds
- Runs for 2 minutes: 120 ÷ 5 = 24 contracts.
- Price falls 4 points.
- 24 × 4 × $5 = $480.
A $480 loss where the plan’s 1 contract would have lost $20.
Your turn
DrillMade-up numbers · Micro S&P 500 · $5 a point · the loop buys 1 contract every 10 seconds for 3 minutes · then the price falls 5 points
Trading is risky. You can lose money, and automated trading can lose like any other trading. This lesson explains how things work. It isn’t advice.