Backtrader Simple Moving Average Crossover Review

A series of 349 tests have been performed across 4 markets over a 12 year period to determine how well a simple moving average crossover strategy performs longterm. Generally, the best-performing settings across all markets had longer look back periods for the slower moving average in the pair. Conversely, the best settings for faster SMA was approximately 4 times shorter. Finally, the crossover strategy was largely profitable even under sub optimal parameter combinations. The only exception to this was in the GBPUSD. Read on for the full review.


Moving averages are probably one of the most wildly known indicators around. Both simple and informative, they form the basis of many trend following strategies. Furthermore, when price approaches a key moving average level, it often commands the attention of many traders. Although simple in nature, moving averages do come in a couple of flavors. Additionally, interpreting them in a stategy ruleset also often differs. With that in mind, this post is going to focus on the simple moving average when applied in a crossover strategy.

The review also forms part of my series to test and compare Backtrader’s library of built-in indicators. For the series introduction, some notes on the test methodology and results summary table see here:

Note: Results below do not reflect real world performance. As mentioned in the introduction and overview post (linked above), no commissions, leverage or margin are used during testing. The purpose of these tests are to compare the indicators to one and another where all other factors are equal.  For more information on how all indicator reviews will be performed, please click on the link above. 

Understanding The Simple Moving Average

Simple Moving Averages (SMA’s) are one of the easiest technical indicators to wrap our heads around. If you remember enough math to calculate a basic average, then you understand the SMA. In a nutshell, for every single closed bar we calculate the average closing price for a fixed number of bars in the past (otherwise known as the look back period). The moving part comes in to play because we limit the number of bars in the calculation and new bars are being formed all the time. I.e When a new candle is closed, the candle at the end of the range is pushed out and the newly closed candle goes in. Thus making the average move with price.

Test Strategy

In this review, we will be looking using two simple moving averages, one of which has a longer look back period than the other. A longer the look back period means that each new value (candle) does not have as much of an effect on the calculated average. This causes the SMA value to appear to move slower as the look back period increases. Consequently, it is this difference in speed that we will use to generate crossover signals for the strategy (when one SMA value crossover up or down through the other.

Using crossover signals means the test strategy will be very simple:

  • Enter short when the faster SMA crosses down through the slower SMA
  • Enter long when the faster SMA crosses up through the slower SMA
  • Close a short when the faster SMA crosses up through the slower SMA
  • Close a long when the faster SMA crosses down through the slower SMA

In addition to the entry criteria, it is worth mentioning that the strategy aims to always be in the market. Therefore, when we close a long or short, we will immediately open another position.


Optimization was performed for the following ranges:

Fast SMA(s)Slow SMA
5, 6, 7, 814
5, 6, 7, 8, 9, 10, 11, 12, 13, 1421
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 1930
5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 35, 40, 4550
10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 90100
20, 25, 30, 35, 40, 45, 50, 60, 70, 80, 100, 120, 140, 160, 180200
50, 60, 70, 80, 100, 120, 140, 160, 180, 200300

Initially, I performed optimization of both SMA’s independently and simply optimized them with a large range each. However, I quickly noticed that if I do that some tests would never take a trade. Since Backtrader loops through each and every combination of values, some optimization tests would result in both SMA values being the same. Another issue is that half of the tests performed would effectively reverse the strategy. This is because at some point, what was once the fast SMA would become the slow SMA and vice versa causing the entry/exit criteria to reverse. All this would amount to a set of results where the zero’s skew the averages and the worst settings are simply the opposite of the best settings. Therefore I decided to forcibly keep one SMA’s look back period higher than the other during testing. It results in fewer tests, but I think overall it will provide better insights.

Simple Moving Average Review Results

Overall 349 tests were performed across all four markets and look back periods. Drawdowns ranged from 1.75% to 4.6% with an average drawdown across all tests at 1.96%. Strike rates, on the other hand, were more spread out (18% – 64%). Interestingly, at 2.2%, the test with a strike rate of just 18% did not have the largest drawdown. This is because it took significantly fewer trades over the test period. Perhaps this was to be expected with some of the longer look back periods used.

A summary, gallery of charts and series of statistic tables for each test method are below. The tables give an overview of the best parameter settings for each market along with the best / worst settings across all markets.

Overall winner and loser

MarketPnL12 Year Return (%)Total TradesTotal WonTotal LostStrike RateBiggest WinnerBiggest LoserAvg WinnerAvg LoserMax Drawdown (%)2005 (% gain/loss)2006 (% gain/loss)2007 (% gain/loss)2008 (% gain/loss)2009 (% gain/loss)2010 (% gain/loss)2011 (% gain/loss)2012 (% gain/loss)2013 (% gain/loss)2014 (% gain/loss)2015 (% gain/loss)2016 (% gain/loss)
NZDUSD 70, 100360.943.6142231954.76148.97-47.2327.61-14.431.750.340.89-
NZDUSD 12, 21-442.56-4.432086913933.1755.37-34.8912.95-9.614.6-0.60.53-0.66-0.27-0.52-0.45-0.870.2-0.63-0.37-0.15-0.73

You will see shortly that the best overall parameter settings in the most favorable market (NZDUSD) used fairly similar settings to the best overall parameters by average in all markets.

PnL Curves, 12-Year returns and Stike Rates

The gallery below shows 3 different charts:

  1. The 12-year annual returns of the best and worst performing tests
  2. The PnL when altering the fast SMA against the Slow SMA
  3. The best, worst and average strike rates across all tests.

This slideshow requires JavaScript.

Almost amazingly when looking at the PnL curves for the fast SMA periods vs the 200 MA, you could have had almost any setting (except in the GBPUSD) and still not lost money! Having said that, the general performance does drop as the period for the fast SMA’s lengthen. This is to be expected in my view because when you have 2 long SMA periods, you have very little current market information. Consequently, this leads me to believe some of the profitable results where both SMA’s had a large look back period (e.g 160 and 200 period test) may have been lucky.

A full copy of the test results in CSV format can be found here: SMA Review results CSV

Best Settings for Each Market

MarketSMA 1 (Fast)SMA 2 (Slow)PnL

Interestingly here the absolute best settings for the AUDUSD were 16 and 30. This goes against the general trend. Furthermore, reducing the fast SMA by just 2 to 14/30 reduced the profit by almost half which suggests those settings may have hit a sweet spot for that particular market rather than a good general choice.

The GBPUSD also faired a little better to quicker settings and at 17 / 50. However, these are closer to the popular 20/50 combination. Another point worth mentioning is that the actual PnL achieved was not high in comparison to other indicators.

Default Settings Performance

Usually this section would contain defaults settings performance. However, since this strategy requires two indicators and crossover signals, the default settings would be the same for each SMA! Therefore, we would see a crossover. As such, I decided to use the 50 and 200 SMA’s to represent a “default”  since this is one of the most common combinations for trend followers

MarketPnLStrike Rate

Best / Worst Settings On Average Across All Markets

This table shows the performance of the best and worst settings when the performance was averaged over all the markets under test.

 PnLParam 1Param 2

As we can see, longer look back periods for the slower moving average (200) tend to provide more consistent results when coupled with a faster SMA period of 40. This is not far off the popular 50/200 setting (which in itself performed well). The worst settings have a slow moving average period of 21. This is actually quite fast and suggests the SMA’s may have been prone to whipsawing. (ranging markets where the moving averages are crossing over frequently)

Until next time

Thats all for now, I will try to follow this up with another review soon.

Reference: Best Forex Indicators Comparison

Find This Post Useful?

If this post saved you time and effort, please consider support the site! There are many ways to support us and some won’t even cost you a penny.