Building a strategy

In this tutorial, we will be building a simple simple moving average based strategy.

The strategy we will build is for demonstration purposes only. We cannot be held liable for any loss if this strategy is used in any way outside of it's intended purpose.

What are we building?

As stated above, we will be building a simple strategy that uses different SMA (simple moving average) periods to define enter and exit points. To read more about moving averages in general, please read this article on investopedia.

What variables will we need?

We will be defining the following variables:

Variable name

Description

SMA10

Simple moving average of the past 10 tickers

SMA10 (PREVIOUS)

Value of SMA10 starting from the previous ticker

SMA50

Simple moving average of the past 50 tickers

SMA50 (PREVIOUS)

Value of SMA50 starting from the previous ticker

How will we know when to enter the market?

We define our long entry point as:

  1. When SMA10 is greater than SMA50

  2. When SMA10 (PREVIOUS) is less than SMA50 (PREVIOUS)

And our short entry point as the opposite of the above

  1. When SMA10 is less than SMA50

  2. When SMA10 (PREVIOUS) is greater than SMA50 (PREVIOUS)

How will we know when to exit?

Our exit point will be the opposite of the conditions above.

If our open position is long:

  1. When SMA10 is less than than SMA50

  2. When SMA10 (PREVIOUS) is greater than SMA50 (PREVIOUS)

And if our open position is short:

  1. When SMA10 is greater than than SMA50

  2. When SMA10 (PREVIOUS) is less than SMA50 (PREVIOUS)

How much capital are we willing to risk?

We will risk a maximum of 1% (often times less) capital on each trade.