Drixx Academy/Trading with Moving Averages Explained/

Trading with Moving Averages Explained

Lawrence Zhou
Drixx Quant
March 2, 2021

Trading with Moving Averages (MA)

Moving averages are one of the most widely used technical indicators.In fact, this indicator is often shown by default on many trading charts. The Drixx exchange, for example, includes moving averages in its default layout. Moving averages are not only used for smoothing out trading data, but also for identifying potential trends (or trend changes). In this article, we will take an in-depth look at moving averages, how they are calculated, and some simple strategies that might be employed.

How do we use the Moving Average Technical Indicator?

First and foremost, the moving average indicator is considered a "lagged" filter in statistics. This means that it considers previous values (in addition to the current one) to smooth out the data. Because price data can be very volatile, moving averages can be used to look at the underlying trend.

moving-average-drixx.png

20, 100 and 200-day-moving averages for BTCUSD - Source: Trading View

We draw the 20-, 100-, and 200-day moving averages for BTC/USD. Daily moving averages are often referred to the DMA

  • 20 DMA -- Blue
  • 100 DMA -- Teal
  • 200 DMA -- Yellow

We see that while the price series of crypto like BTC can be highly volatile, the moving average lines are much smoother. Longer time-period moving averages tend to lag more and might not detect changes in overall trend quickly. Shorter time-period moving averages lag less and detect sudden trend changes. However, they are prone to giving false positives.

We see this effect better in the below chart, which is a snapshot of BTCUSD in 2019:

DMA-comparison-drixx.png

20-DMA, 100-DMA and 200 DMA comparison for BTCUSD - Source: TradingView

We see that the slower, longer-term 200 DMA (in yellow) only bottomed in mid-May 2019 (after the rally was in full force). It topped out in December 2019 (after the market had already dropped).

We see that the 100 DMA (teal) detected the upwards trend earlier (bottoming out in March 2019) before topping out in October 2019 (after the first substantial drop).

Finally, we see that the 20 DMA is much more volatile,making multiple peaks and troughs between June and September of 2019 (resulting in many false positives!).

Note that while we are using daily closes to generate the moving averages, any time interval can be used. For example, you could generate100 data-point moving averages on hourly data.

In a later section, we will look at some simple moving-average based strategies that a long-term trader can employ. But before that, let us go over how moving averages are calculated.

How is the Moving Average Technical Indicator Calculated?

The moving average technical indicator essentially takes a rolling "average" of some data points over some fixed period. There are two main moving averages that market practitioners normally look at: the simple moving average (also known as the SMA) and the exponential moving average(known as the EMA).

Simple Moving Average (SMA)

  • The simple moving average is basically the arithmetic average over a series of N data points. The N is typically called the period. As we talked about above, these can be any data points. So daily, hourly, etc. intervals all work.
  • Let Pt = price at some fixed period t (this is typically the closing price).
    Let N = the number of periods

sma-formula-drixx.jpg

SMA formula

  • We see that the weight given to any data point within the period is 1/N (or the arithmetic average). So,if the period is 50, then the weight given any data point within the period is 1/50= 2%
  • Common values for N are 7,20, 100, and 200 periods.
  • Example -- 5-Period SMA

5-period-sma-drixx.jpg

Example -- 5-Period SMA

The 5-Period SMA on Feb 28 is (45,137 + 46,188 + 46,339 + 47,093 + 49,705)/ 5 = 46,892.4

Exponential Moving Average (EMA)

  • Unlike the simple moving average, the exponential moving average gives more weight to recent data points. Assets tend to grow exponentially (by compounding percentages) instead of linearly. Consequently, the SMA might be too "slow" for faster moving assets like BTC.
  • Let Pt = price at some fixed period t (this is typically the closing price).
    Let N = the number of periods

smoothing-factor-ema-drixx.jpg

EMA Smoothing Factor formula

For the first data point, we can just use the closing price P0.

Unlike the SMA, the weights of the EMA are exponential. If we expand out the recursive relation, we see that the weight on each term is α (1-α)^n, where n = the number of periods before the current period at t.

For example, we can see that with an α = 0.5. The weighting at t (current period)is 0.5 * (1-0.5)^0 = 0.5. The weight of the 5th data point 0.5 *(1-0.5)^5 = 0.015625 (approximately 1.6%)

  • Typically, on many charting programs, the smoothing factor α is calculated as 2/(n+1). This is largely convention to connect the SMA to EMA (since using this will make the SMA and EMA weights have similar centers of mass). However, any value of α between 0and 1 can be chosen (with higher α being more weight towards more recent data points).
  • Common choices for EMA might be 7, 26, 100, 200 periods.
  • Example -- 5-Period EMA

Using the formula above, we have α = 1/3.

example-5-period-ema.jpg

Example -- 5-Period EMA

Because our short data-series starts from Feb 14, the first EMA (5) is just the closing price on Feb 14. The last EMA (5) on Feb 28 is 1/3 * 45,138 + 2/3 * 46,188 = 47034.86

We illustrate the differences between the EMA and SMA in the chart below. Specifically, we see that for a SMA (100) in red versus a EMA (100) in blue, the EMA adjusted to the increases in price much quicker as the price went up (and vice versa).

ema-sma-differences-drixx.png

Differences between the EMA and SMA Illustration - Source: Trading View

Overall, though, depending on the time frame and period you are using, either the SMA or MA can be used. There is no "best" moving average or period parameter. A trader should experiment with the period and type of moving average that is best suited for their trading style.

A Simple Moving Average Crossover Indicator Strategy

Often, combinations of moving averages are used as indicators for entering and exiting trades. One such indicator is the moving average crossover.

Essentially, the moving average crossover indicator can be built from two moving averages with different periods.

  • Let A = the period of a shorter moving average (smaller N)
    Let B = the period of a longer moving average (larger N)

    SMA Crossover (A, B) = SMA (A) -- SMA (B),which we will call SMAC (A, B)

    EMA Crossover (A, B) = EMA (A) -- EMA (B), which we will call EMAC (A, B)

  • Effectively, we are taking the results of a shorter period moving average and subtracting out the longer period moving average. Let us say, for example, that the current SMA (5) is 40,000 and the SMA (20) is 53,000. Then the SMA Crossover (5, 20) is -13,000

We can interpret this indicator as checking whether the short-term MA is above or below the longer-term MA. If the shorter-term MA is above the longer-term one, then that indicates a potential upwards reversal in the trend. On the other hand, if the short-term MA is below (or crosses below)the long-term MA, that indicates a negative trend. This indicator is a decent way to detect bottoms or tops in the trends systemically (without needing to look at the chart visually).

One simple strategy with this indicator is to be long when the trend is positive and short when the trend is negative. To determine if a trend is positive or negative, we can look at the SMA Crossover Indicator.

For example, if we use a SMAC (7, 20), we will choose to belong when SMA (7) is above SMA (20).

How have different combinations of SMAC parameters performed over time? We test 6 different variations (using BTC data starting from April 2015).

smac-strategy-drixx.jpg

Returns - Buy and Hold and SMAC Strategy

smac-strategy-returns-drixx.jpg

Drixx Example - Returns - Buy and Hold and SMAC Strategy

We see that relative to simply buying and holding, most SMAC-based strategies using a 7 DMA as the shorter moving average out-performed buy and hold. Specifically, the SMAC (7, 100) not only returned nearly 52% more over 6 years than buy and hold, but it also suffered significantly smaller draw downs. The smaller drawdowns could mean that a trader of this strategy could slightly lever up their position without being wiped out.

Summary

Moving averages are a powerful tool for both discretionary and systematic traders. They filter incoming noisy data and can be used to determine trends. The two most common forms of moving averages are the simple moving average and the exponential moving average. These averages (with different period parameters) can be used to build the crossover indicator.

To make the most out of derivatives trading platforms like Drixx, you might also want to check out our article on exchange order types and learn more about leverage trading.

Disclaimer: The information presented here is for educational purposes only and should not be construed as investment advice. Cryptocurrency trading involves high risk. Drixx will always strive to do it’s best in educating customers and providing high quality products but will not be held responsible for their trading and investment decisions, losses or profits.