Getting started with an SMA crossover strategy

Overview

SMA crossover strategies are a great way to get started and understand the potential of algorithmic trading. Using two prices lines of the SMA indicator, this strategy creates a buy or sell signal when the lines cross.

Buy - A slow SMA and a fast SMA (Meaning the lookback periods are different). When the fast SMA crosses above the slower SMA from bottom to top (or from down to up), there is a buy signal as the trend is up.

Sell - When the fast SMA crosses from top to bottom (from up to down), there is a sell signal as the trend is down.

Adding logic blocks

Blocks are small pieces of logic that can be connected to other blocks. At its core, they include small code snippets that, when combined, will generate your strategy code. Blocks can be added through our finder. To open the finder, click the + button in the top right corner or just start typing.

Learning exercise: 1. Search for an indicator and add it to your strategy 2. Delete it using the cross icon 3. Duplicate using the copy icon.

Adding technical indicators

The SMA crossover strategy consists of two lines: A fast-moving average and a slow-moving average. Use the 'Period' field to set the time frame. Set the slow as 20 and the fast as 10.

The circle on either side of the blocks are the inputs (left side) and outputs (right side), which should be used to connect to other blocks. The fields on the bottom of the block are called control fields and can be used to configure the block settings.

Learning exercise: 1. Replace the SMA with a MA of your choice 2. Click on the output and drag a connection line 3. Test out the control fields with different parameters

Trading Logic blocks

Trading logic is required to transform the SMA data feeds into trading signals.

  1. Crosses Below will send a signal if a line crosses from top to bottom

  2. Crosses Above will send a signal if a line crosses from bottom to top

Our two new logic blocks have two inputs and two outputs, these are required to have connections to work correctly.

  1. The fast (10) SMA is the first input of "Crosses above", the slow (20) SMA is the second input. This means this block will emit a signal when the fast SMA crosses the slow SMA from bottom to top (Buy)

  2. The fast (10) SMA is the first input of "Crosses Below", the slow (20) SMA is the second input. This means this block will emit a signal when the fast SMA crosses the slow SMA from top to bottom (Sell)

A good cross-over strategy usually also makes use of Momentum. Consider adding a "Momentum" technical indicator block to your strategy to further improve performance.

Find out more

If you have any questions or need any further technical support or assistance feel free to reach out to our team and we will get back to you as soon as we can.

Last updated