Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

The Ultimate Guide to Moving Averages

You are reading The Ultimate Guide to Moving Averages by Enlightened Stock Trading originally posted on the Enlightened Stock Trading blog.

Introduction Moving Averages 

What is a moving average and what is it used for? A moving average is an indicator that used on your trading charts to help gauge the direction of the price movements. Moving averages are one of the most commonly used indicators in technical analysis, systematic trading and algo trading. This is because they perform several useful functions which we will discuss in depth in this post and they are a robust trading indicator that has withstood the test of time. In this article we will discuss what moving averages are, we will explore 5 different types of moving average, the formulas and weightings each average uses, we will discuss how to calculate

What Is a Moving Average?

Return to Top of Page…

How do we calculate it? We’ll start with a simple moving average, and then we’ll get into the other moving averages as we go.

On the chart, I’ve got a chart of the S&P 500 index, and overlaid a 10 day moving average on the index. What is a 10 day simple moving average and how does it work? If you look on the picture below, I’ve got this red box to highlight some of the bars, and you’ll see that the moving average is a line that runs sort of alongside the price of the instrument that you are charting.

In order to calculate the moving average on each day, the simple moving average, you need to do an arithmetic average of the last X number of bars of that price series that you are plotting. We’ve got the S&P 500, this is a 10-day moving average. I’ve drawn a red box around the last 10 bars. Thus, we’ve got 1 up to 10.

To get the most recent 10-day moving average, you take the closing price on each of the last 10 days, you add them up and then divide it by 10; then you plot the result. To get the previous bar’s moving average, which was one day ago, same sort of thing. You take the last 10 bars, which is 1 up 10. It includes the previous bar that wasn’t in today’s calculation, so you add up the closing prices and you divide it by 10.

You don’t always have to do the moving average of just the closing price. You could have a moving average of the open, high, low, close, or the moving average of some calculation of  the average. There’s different ways you can calculate the moving average. On the chart below, we’ve got a simple moving average, and it’s 10 bars. A 10-bar moving average is quite a short term moving average. We could also overlay a longer term moving average. Let’s put a 200-day moving average, it is interesting because the 200-day moving average is one of the most useful tools in technical analysis.

The 200-day moving average is calculated the same as the 10-day moving average. But instead of averaging the last 10 days of data, it’s averaging the last 200 days of data. It’s a much slower-moving average and you can see that it’s a nice gradual trend. The 200-day moving average is moving down and the price is below the 200-day moving average. That has some very special significance for traders and investors because below the 200-day moving average, bad things tend to happen and the markets are much more volatile.

Above the 200-day moving average, the market is generally much less volatile and trends much more smoothly. Hence, bull markets happen above the 200-day moving average and bear markets and crashes tend to happen below the 200-day moving average. The 200-day moving average is one of the most powerful signals in technical analysis. 

How to Calculate Moving Averages

There’s several types of moving averages as shown below on the chart for comparison. There’s a simple moving average, exponential moving average, weighted moving average, and a TEMA moving average. Each of these have different pros and cons, in which I will be explaining later on. However, I just want to illustrate some of the differences and the way it appears in the chart.

Return to Top of Page…

Exponential Moving Average

The 200-day exponential moving average is colored in blue on the chart. Let’s compare the 200-day exponential moving average to the 200-day simple moving average, which is in black on this chart. You can see that the 200-day exponential moving average is a little more responsive. It’s a bit closer to the price. The same thing happens if you take a short term moving average.

Let’s take a 10-bar exponential moving average and compare it to the 10-bar simple moving average. You can see that the 10-bar exponential moving average hugs the price a little more closely than the simple moving average. The exponential moving average for the same number of bars, hugs the price more closely and is more responsive than the simple moving average. That doesn’t make it better; it just calculates the exponential moving average differently.

Return to Top of Page…

Weighted Moving Average

If you put a 200-bar weighted moving average onto the chart, you can see the weighted moving average behaves differently to both the simple and the exponential moving average. I’ve put the simple moving average in black, the exponential moving average in blue and the weighted moving average in green. It has some quite different characteristics depending on what you want to do.

Return to Top of Page…

TEMA – Triple Exponential Moving Average

These are some of the different moving averages. We’ve got simple, exponential, weighted. You also saw that there’s a T-E-M-A, that’s a triple exponential moving average. This is even more complex. I’m doing all of this plotting on Amibroker. You might use other charting software, but I use Amibroker for charts and for backtesting. The TEMA is an attempt to speed up and make the moving average more responsive. One of the challenges with moving averages is that they tend to be quite slow and laggy. The TEMA is a calculated, it’s a moving average of a moving average. It’s a complex calculation, which I’ll explain shortly that takes a combination of the original exponential moving average, the EMA of that moving average and combines them to try and reduce or remove some of the lag. You can see this purple line on the chart is here.

Now we’ve got the simple moving average in black, the exponential moving average in blue, the weighted moving average in green, and the TEMA, the triple exponential moving average in purple. If you look at the picture below, you can see that the TEMA is quite responsive to price. It moves quite quickly in line with the price, certainly compared to the simple moving average and the exponential moving average and even the weighted one here in this case.

I want to be clear and emphasize that just because it’s more responsive doesn’t mean it’s better. It’s just different. You need to backtest your system ideas using each of these different moving averages and see which gives you the best signals. There are different types of moving averages.

Return to Top of Page…

5 Types of Moving Averages

What are the types of moving averages, and how do they work?

This section will discuss the types of moving averages which is the simple moving average, exponential moving average, weighted moving average, Hull Moving Average, and the TEMA Moving Average.

Return to Top of Page…

Simple Moving Average

The weighting of a simple moving average takes the price of the last N number of bars and performs a simple average of those bars, which means the weighting of each of the last N number of bars is the same. For example, if it’s a ten-day moving average, then today and each price for the last ten days all receive the exact equal weighting in the moving average calculation. That’s why, as you can see in the simple diagram below shows it’s an even weighting over each of the different bars.

Return to Top of Page…

Exponential Moving Average

An exponential moving average on the other hand, seeks to place more weighting and more emphasis on the recent price data. The calculation of the exponential moving average is much more complicated. You don’t have to do it by hand because your trading software will do it for you. It places a much higher weight on the current data point and decreasing the weight on each previous data point. How does that work in practice? On the diagram below, the exponential moving average is a much higher weighting up on the most recent price. Then each historical price gets less and less weighting back. However, if you’re doing a ten-day moving average, the ten days prior gets a much smaller weighting than the current price.

The exponential moving average is much more responsive to price movements than the simple moving average. The simple moving average moves slowly because it averages each of the last ten days. In contrast, the exponential moving average emphasizes the more recent bars, so it’s more sensitive and moves more quickly.

Return to Top of Page…

Weighted Moving Average

The weighted moving average is somewhat similar to the exponential moving average, except instead of placing exponentially more emphasis on the recent bars, it puts the weighting on each of the historical bars in a linear profile. On the picture below, you can see the weighting of each of the bars in the weighted moving average. It decreases in a linear fashion back to the nth most recent bars.

The current bar gets a particular weighting, and then the previous bar gets a little less, but it’s less responsive. Less emphasis is placed on the more recent bar than on the exponential moving average here. The weighted moving average places much more emphasis on the recent bar than the simple moving average but less on the recent bar than the exponential moving average.

Return to Top of Page…

Hull Moving Average

The Hull Moving Average is a much more complicated calculation than the TEMA. In the following blog, you can read where I discuss the formulas for each of the different moving averages. On the chart below, you can see what it looks like for each of the different moving averages. I’ve got the chart of the S&P 500 index, and I’ve overlaid a 200-day moving average.

TEMA Moving Average

I’ve got a simple moving average in black, and I’ve got an exponential moving average in blue, got a weighted moving average in green and a TEMA moving average in purple.

I’ve dropped the Hull Moving Average onto the chart in red. You can see the Hull Moving Average below. The Hull Moving Average behaves quite similarly to TEMA. It’s a different calculation, so they move differently. If you’re looking for more responsive moving averages, then TEMA and Hull are good moving averages. If you’re looking for less responsive, exponential and weighted will do the job.

Return to Top of Page…

Formula for Moving Average 

In this section, I will explain the formulas for the different moving averages, so you know exactly how they’re calculated. That way, you can be confident when you’re using them in your trading that you know how they’re calculated, what they’re derived from, and how they will behave in your trading system or trading strategy.

Return to Top of Page…

Formula for Simple Moving Average

First of all, let’s cover the formula for the simple moving average. The formula for the simple moving average is just an arithmetic average of the last N number of bars. If you’re doing a 10-day moving average of the closing price, you take the closing price on each of the last 10 bars and add them all up. Then, you divide them and divide that number by 10, giving you the simple moving average. This formula, the moving average, is the sum from bar one to bar N of the price over the last. Divided by N, so divided by 10 bars.

You can calculate the moving average of the closing price, opening price, high, low, or some average of the open, high, low close, the volume or anything you like. You can apply this simple moving average to pretty much anything on your chart, except the most common use is to calculate the moving average and the simple moving average, of the closing price. That’s the most common way to calculate the moving average in trading.

Return to Top of Page…

Formula for Exponential Moving Average

Example Exponential Moving Average

The exponential moving average is equal to the current price, and we multiply that by two divided by the number of bars in our moving average plus one. If it was a 10-bar moving average, it’s the current price multiplied by two divided by ten plus one for the 10-bar moving average. Then, we add that the previous bars were moving averages, and we multiply that by one minus the same ratio, two divided by the number of bars plus one.

What does this look like in practice? Let’s do a worked example. To calculate an exponential moving average of 200 days, we’re going to look at the current price, and we’re going to multiply it by two divided by 200 plus one. Then we’re going to add the previous bars moving average, but we’re going to multiply that by one minus two divided by 200 plus one.

Now what this does is it gives the most weighting to this current price bar and less weighting to the previous price bar. Then, when you work out this ratio, what you get is the exponential moving average equals the current price times, in this case, .00995 plus the previous bars exponential moving average times .99005, and these two add up to one. That gives you the full exponential moving average. That’s how you calculate the exponential moving average.

Again, you can do this by hand. Any good charting software will have exponential moving averages, be able to drag and drop them straight onto your chart. I use Amibroker. As we saw from the charts we looked at earlier, like this one of the S&P 500, you can drag whatever moving averages or indicators you want onto the chart and have them calculated, and you can adjust the number of bars in the calculation.

It is important to understand how they’re derived so that you know how they will behave and whether they will perform appropriately for your trading system. Therefore, that’s the exponential moving average. Next, let’s have a look at the weighted moving average.

Return to Top of Page…

Formula for Weighted Moving Average

Example Weighted Moving Average

The weighted moving average is somewhat similar to the exponential moving average in that it places more emphasis on the most recent bars and less on the previous bars. The formula is the weighted moving average equals the price of the most recent bar times N. Then we’ll add the price of the previous bar times N minus one. The previous bar gets slightly less weight than the current bar.

We’re going to add to that the price of the third historical bar and multiply that by N minus two. We’ll keep adding those up, multiplying it by a lower and lower number until we get back to the previous Nth bar. Then we’re going to divide all of that by N times, plus one in brackets, divided by two.

Don’t worry too much about this if you’re not a math whiz. What this means is that the current bar gets the most weighting. The previous bar gets a little less, and then a little less until you get back to the last bar in the calculation. It’s a linear reduction in weight as you go back in time.

What does that look like as a practical example? Let’s do a straightforward one, a three-bar moving average. For a three-bar weighted moving average, it would be the current bar times three, the previous bar times three minus one, and the bar before that times three minus two. We’re going to divide all of that by three times three plus one, all divided by two. That simplifies to here; the weighted moving average would equal the current price times three, the previous bar’s price times two, and the bar before that’s price times one, all divided by six.

We’re dividing by six because we’ve got the total weighting of six in this formula, three here, two here, and one here as shown below. We want to get it back to a weighting of one to get the true average. The weighted moving average is calculated just like this, with the weighting on each bar decreasing in a linear fashion back to the first bar in the calculation.

The weighted moving average is excellent because it’s pretty responsive, but it could be more heavily focused on the most recent bar. It gives some weight to all of the bars in the calculation. In contrast, the exponential moving average gives less and less waiting in a very exponential fashion back to the first bar in a calculation. Thus, it can be, too responsive to price.

Return to Top of Page…

Formula for Triple Exponential Moving Average (TEMA)

The TEMA or the triple exponential moving average is combined of three different moving averages. First, we want to define these other moving averages here. EMA1, we’re going to explain as the EMA of the price, the exponential moving average of the price. That’s the standard exponential moving average formula. EMA2 is the EMA of the first EMA. EMA2 is the EMA of this number here, of this value, then EMA3 is the EMA of that value there.

Once you’ve calculated EMA1, EMA2, and EMA3, it’s the EMA of the price, the EMA of that EMA, and then the EMA of that EMA. Then, you combine them using this formula here. The triple exponential moving average is three times the first moving average minus three times the second moving average plus the third moving average. This formula is an attempt to remove some of the lag in the exponential moving average.

I don’t use TEMA personally in my trading, but it’s an interesting indicator that warrants investigation. When you’re developing system ideas when you’re backtesting, you can try all the different moving averages, as we’ll discuss later in this moving average video series. That’s the formula for the TEMA, triple exponential moving average.

Return to Top of Page…

Formula for Hull Moving Average

The hull moving average is even more complicated. It’s another attempt to remove the lag from the standard moving average formulas we’ve already seen.

The hull moving average is a weighted moving average. It’s WMA weighted moving average. But we’re calculating the weighted moving average of a couple of different things. You’ll see here we’re calculating the weighted moving average of everything in these brackets. The first thing is we’re doing two times the weighted moving average of price. It’s the standard weighted moving average that we’ve already shown you the formula above, but we’re doing it over the last two bars.

If it’s a 10-day moving average, we’re doing two times the five-day moving average and five-day weighted moving average. Then we’re subtracting from that the weighted moving average of the price over N bars. Therefore, it’s twice the short-term moving average minus the long-term moving average. Then, we’re calculating a weighted moving average of all of that over the last square root of N bars.

It’s complicated and I don’t think you need to know this formula because it’s in your charting package, or it can be very quickly coded into your charting package. However, what it’s trying to do, is eliminate some of the lag, and this was one person’s attempt to do that.

Again, the hull moving average is quite a good tool for trading systems. It gives you very responsive signals, much more responsive than a simple moving average. It’s great for things like an entry trigger. Not so great for a long-term trend filter because it’s too responsive. Yet it can also be good for an exit because when the price crosses below the hull moving average that typically happens much earlier than the price crossing below the simple moving average. You can use it to capture more of your profits.

They’re the formulas for the different types of moving averages. We’ve covered the formula for the simple moving average, the formula for the exponential moving average, the formula for the weighted moving average, the formula for the TEMA or triple exponential moving average, and the hull moving average.

Now you know how to calculate them. Just remember, you don’t need to understand those formulas in detail. I want you to have a broad understanding of where they’re coming from and how they behave so that you’re not doing it blindly when you’re applying them in your trading systems and strategies. You should only ever use an indicator that you broadly understand how it works and how it’s calculated.

Return to Top of Page…

Calculating Moving Average in Excel

Return to Top of Page…

Types Of Moving Averages In Excel

In this section, I’m going to explain how to calculate all the different types of moving averages in Excel. I don’t know why you would want to do this because your charting software should have all the moving averages in there. If you are trading in using Excel for your analysis package, you need to upgrade because trading packages like Amibroker allow you to do all of your charting. It has all of the calculations for the indicators built in. It also allows you to backtest and optimize your trading systems. If you are using Excel, you’re really selling yourself short. Move across to a proper trading package so that you can do the charting, and do the backtesting way more easily.

Having said that, let’s have a look at how you calculate the different moving averages in Excel just so you know how the calculations work. What I’ve done is I’ve extracted a few bars of data from the S&P500 index and I’ve pasted them here. You can see, I’ve got the SPX ticker and the dates. I started in 1990 and I’ve got the closing price and the volume. I’m not using the volume so we’ll just ignore that for now.

Return to Top of Page…

Calculating Simple Moving Average in Excel

How do you calculate the simple moving average in Excel? If we have a look at this formula here, the simple moving average is just the average of the last 10 bars. We can use the average function 1, 2, 3, 4, 5, 6, 7, 8, 9, and 10. We’re going to increase that up to there, so this is the average of those 10 numbers, and that’s the 10 bar average. If I want to calculate the moving average for each of the following bars, all you need to do is drag this formula down and you can see, this one uses those 10, and you can see how the formula increments down on each new day.

It drops off the oldest day and it picks up the newest day. This is how the simple moving average formula works. You can see it’s moving those 10 bars down for each new bar of data. The moving average does use the current day. Today’s moving average uses today’s closing price so you can only calculate today’s moving average after the market closes, in which that’s the simple moving average.

Return to Top of Page…

Calculating Exponential Moving Average in Excel

Exponential moving average is more complicated.  The formula is the current price times two divided by N plus one, where N is the number of bars in the moving average. Hence, closing price times two divided by N+1 plus the previous day’s value of the exponential moving average times 1 minus 2 over N+1. We encountered this formula in a previous section so you can see, it’s the current price times two divided by N+1 plus the previous value of the exponential moving average times 1 minus 2 divided by N+1. There’s the formula and then if we drag this down, it’ll just continue to calculate. You can see that each day, it refe



This post first appeared on Learn Stock Trading, please read the originial post: here

Share the post

The Ultimate Guide to Moving Averages

×

Subscribe to Learn Stock Trading

Get updates delivered right to your inbox!

Thank you for your subscription

×