← All lessons

Lesson 2 of 17Understand markets1 min read

What is a trading algorithm?

Write a rule a computer could follow.

The idea

An algorithm is a set of instructions. A trading algorithm uses instructions to decide when to buy, sell, or do nothing.

The computer needs an exact rule. “Buy when things look good” leaves too much to guess.

A small example

Here is a rule for our learning project:

  1. Read the latest three prices.
  2. Calculate their average.
  3. If the latest price is above that average, record above average.
  4. Otherwise, record not above average.

That is only a measurement so far. Later, you will decide how a paper-trading program might use it.

Try it

The prices are 10, 11, and 12.

Add them and divide by three. Then compare the latest price, 12, with your answer.

Check your answer

The average is 11. The latest price is above average.

The program has followed a clear rule. It has not shown that the next price will rise. That is a separate question to test.