While modern traders are spoiled with the ease we have of seeing moving averages on our charting platforms in an instant, older traders had to calculate them for their self and update their own charts by hand drawing them daily before the days of better computing power and software. Many believe this gave them a better feel for price action and trends if they were discretionary traders. 

In this post I am going to review how the calculation of a moving average is done so readers understand more deeply how this technical indicator is created and why the this line on our chart moves as price moves based on its time frame based on whether we are using a simple of exponential moving average. I believe it is good to understand how how technical indicators work. 

In technical trading a simple moving average (SMA) is the unweighted average of the previous price data of the time frame it is defining. The simple moving average is calculated by adding up prices over the specified period being measured and dividing the total by the number of periods in the SMA.

A moving average is calculated by adding up all the prices in the time frame you want the moving average for then dividing the total by the time frame period. The average of prices changes each time new data is added and the oldest data is removed from the calculation causing it to move. 

Example of how to calculate a 5 day simple moving average:

Daily Closing Prices: 11,12,13,14,15,16,17

First day of 5-day SMA: (11 + 12 + 13 + 14 + 15) / 5 = 13

Second day of 5-day SMA: (12 + 13 + 14 + 15 + 16) / 5 = 14

Third day of 5-day SMA: (13 + 14 + 15 + 16 + 17) / 5 = 15

An exponential moving average (EMA) tries to create a faster signal by reducing the time it takes to move by giving more weight to the newest prices in the formula. The magnitude of weighting that is applied to the more recent price data is dependent on the amount of time periods in the exponential moving average. EMAs are different from SMAs because each day’s EMA calculation is dependent on the EMA calculations for the days before that day. Due to the weighting difference of current data over past data you will need more than 10 days of data to calculate an accurate 10 day EMA.

Initial SMA: 10-period sum / 10

Multiplier: (2 / (Time periods + 1) ) = (2 / (10 + 1) ) = 0.1818 (18.18%)

EMA: {Close – EMA(previous day)} x multiplier + EMA(previous day).

A 10 day exponential moving average applies an 18.18% weighting to the most recent price. A 20 day EMA applies a 9.52% weighting to the most recent price data (2/(20+1) = .0952). The weighting for shorter time frames are more than the weighting for the longer time frames. The weighting is reduced by half every time a moving average time frame doubles.

If you want to use a specific percentage for an EMA, you can use this formula to convert it to time periods and then enter that value as the EMA’s parameter:

Time Period = (2 / Percentage) – 1

3% Example: Time Period = (2 / 0.03) – 1 = 65.67 time periods

For a deeper dive on how to trade with moving averages check out my book Moving Averages 101.

SMA VS EMA
Chart courtesy of TrendSpider.com