Skip to content
Wildflower
Join free
Automated trading and AI

Free Trading School · Level 7 · Course 7.11

Bugs and runaway orders

Lesson 6 of 19 in Automated trading and AIModule 2: What can go wrong

Advanced · Automated trading and AI

Bugs and runaway orders

Wildflower Trading School · Lesson 7.11.2.2

Wildflower

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

  1. Read the rules you wrote for Turning rules into exact logic.
  2. For each order your rules send, write the condition that stops it being sent twice, such as “only if there's no open trade”.

Next: Kill switches and limits.

Quick check

  1. 1. A rule says “if price is above the line, buy 1” and nothing else. What can happen?

  2. 2. A 10-tick stop is coded as 10 points on the Micro S&P 500. How much wider is the stop?

  3. 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

Make a free account and we'll remember where you are, so “Kill switches and limits” is waiting next time.

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.

  • 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 stops it.
  • Common bugs: units (ticks meant, points coded: on the a point is 4 ); direction swapped; the wrong contract (, full-size instead of ) 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 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 () paused E-mini trading for 5 seconds at 2:45:28 pm. See .
  • 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 numbers

A small runaway

Made-up numbers · Micro S&P 500 · $5 a point · 1 contract every 5 seconds

  1. Runs for 2 minutes: 120 ÷ 5 = 24 contracts.
  2. Price falls 4 points.
  3. 24 × 4 × $5 = $480.

A $480 loss where the plan’s 1 contract would have lost $20.

Your turn

Drill

Made-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.