Formula for Moving Average

Adrian Reid walks through five moving average formulas: simple average over n bars, exponential with smoothing factor 2/(n+1), weighted with linearly decreasing weights, triple exponential (TEMA) to reduce lag, and Hull moving average built from weighted components. Understanding these formulas helps you pick the right indicator for entries, filters, and exits.
Chapters
Okay, in this video, I'm going to explain the formulas for each of the different types of 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 actually know how they're calculated, what they're derived from, and how they're going to behave in your trading system or trading strategy. But before we go any further, make sure you hit the subscribe button and give this video a thumbs up so that you get notified of all of my future videos, because I've got new trading content coming out all the time and I don't want you to miss a thing. So let's have a look at each of them in turn. 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. So if you're doing a 10 day moving average of the closing price, you take the closing price on each bar of the last 10 bars and add them all up and then you divide them, divide that number by 10 and that gives you the simple moving average. So this formula is the moving average is the sum for from bar one to bar n of the price divided by n, so divided by 10 bars. So you can calculate the moving average of the closing price, the opening price, the high, the low, or some average of the open, high, low, close or 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, the simple moving average of the closing price. That's the most common way to calculate the moving average in trading. Now next is the exponential moving average. So what's the formula for the exponential moving average? You can see here on the slide, I've got 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. So if it was a 10 bar moving average, it's the current price multiplied by two divided by 10 plus one for the 10 bar moving average. And then we add to that the previous bar's moving average and we multiply that by one minus the same ratio, two divided by number of bars plus one. So what does this look like in practice? Let's do a worked example. So 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 and then we're going to add to that the previous bar's moving average. But we're going to multiply that by 1 minus 2 divided by 200 plus 1. And what this does, this gives.
The most weighting to this current price bar and then less weighting to the previous price bar. And then when you work out this ratio, what you get is the exponential moving average equals the current price times, in this case, 0.00995, plus the previous bar's exponential moving average times 0.99005. And these two add up to one. So that gives you the full exponential moving average. So that's how you calculate the exponential moving average. Now, again, I want to stress and emphasize that you don't have to do this by hand. Any good charting software will have the exponential moving average. Just be able to drag and drop it straight onto your chart. I use amibroker, and as we saw from the charts we looked at earlier, like this one of the S&P 500, you can simply 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 so you don't have to do these by hand. It is important, though, to understand how they're derived so that you know how they're going to behave and whether they're going to perform appropriately for your trading system. Okay, so that's the exponential moving average. Let's have a look at the weighted moving average. The weighted moving average somewhat similar to the exponential moving average in that it places more emphasis on the most recent bars and less emphasis on the previous bars. But here's the formula. So the weighted moving average is equal to the price of the most recent bar times n. And we're going to add to that the price of the previous bar times n minus 1. So the previous bar gets a little less weighting than the current bar. And we're going to add to that the price of the bar, the third bar, the third historical bar. We're going to multiply that by N2, and we're going to keep adding those up, multiplying it by a lower and lower number until we get down to until we get back to the nth previous bar. And then we're going to divide all of that by n times n plus 1 in brackets divided by 2. Now, if you're not a math whiz, don't worry too much about this. What this really means is, is that the current bar gets the most weighting. The previous bar gets a Little less and then a little less, and then a little less, and then a little less and then a little less until you get back to, say, the last bar in the calculation. So it's a linear sort of reduction in the amount of weighting as you go back in time. Now, what does that look like as a practical example? Let's just do a really simple one, a three bar moving average. So for a three bar weighted moving average, it would be the current bar times three plus the previous bar times three minus one plus the bar before that times three minus two. And we're going to divide all of that by three times three plus one, all divided by two. And that simplifies to here. Weighted moving average would equal the current price times three plus the previous bar's price times two, plus the bar before that price times one, all divided by six. And the reason we're dividing by six is because we've got the total weighting of six in this formula, which three here, two here and one here. And we want to get it all the way back to a weighting of one, so we get the true average. So the weighted moving average is calculated just like this, with the weighting on each bar decreasing in a linear fashion all the way back to the first bar in the calculation. So that's the weighted moving average. The weighted moving average is really nice because it's quite responsive, but it's not purely focused or too heavily focused on the most recent bar. It gives some weighting to all of the buyers in the calculation, whereas in the exponential moving average, it gives less and less and less and less weighting in a very exponential fashion back to the first bar in a calculation. And so it can be, for some purposes too responsive to price. Let's have a look now at the tema, the triple exponential moving average. What's the formula for the TEMA moving average? Well, the TEMA moving average is combined of three different moving averages. So first we want to define these different Moving averages here. MA1 we're going to define 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. So EMA2 is the EMA of this number here, of this Value here, and ema3 is the ema of that value there. So once you've calculated EMA1, EMA2 and EMA3, it's basically the EMA of the price and the EMA of that ema and then the EMA of that ema. And then you combine them together using this formula here. So the triple exponential moving average is three times the first moving average minus three times the second moving average plus the third moving average. And this formula is an attempt to remove some of the lag in the exponential moving average. Now, I don't use TEMA personally in my own trading, but it's an interesting indicator and certainly warrants some investigation. So when you're developing system ideas, when you're back testing, you can try all the different types of moving averages as we'll discuss later on in this moving average video series. So that's the formula for the TEMA triple exponential moving average. The last one I want to show you is the hull moving average. So the hull moving average is even more complicated still. And again, it's another attempt to remove the lag from the standard moving average formulas that we've already seen. So the hull moving average is a weighted moving average. So 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've got, we're calculating the weighted moving average of everything in these brackets. Okay, so the first thing is we're doing two times the weighted moving average of price. So it's the weight, the standard weighted moving average that we've already shown you the formula of above. But we're doing it over the last n over 2 bars. So if it's a 10 day moving average, we're doing 2 times the 5 day moving average, 5 day weighted moving average. And then we're subtracting from that the, the standard, the weighted moving average of the price over n bars. So it's twice the short term moving average minus the long term moving average. And then we're calculating a weighted moving average of all of that over the last square root of n bars. So it's kind of like, to be honest, I think uber complicated. And I don't think you need to know this formula because again, it's in your charting package, or it should be, or it can be very easily coded into your chart and package. But what it's really trying to do, as I said, is eliminate some of the lag. And this was, 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. So it's great for things like an entry trigger, not so great for a long term moving long term trend filter. For instance, because it's too responsive. But it can also be good for an exit, because when price crosses below the hull moving average, that typically happens much earlier than the price crossing below, say, the simple moving average, so you can use it to capture more of your profits. So 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, formula for the TEMA or triple exponential moving average, and finally for the hull moving average. So now you know how to calculate them. Just remember, you don't need to understand those formulas in detail. I just want you to have a broad understanding of where they're coming from and how they behave so that when you're applying them in your trading systems and strategies, you're not doing it blind. You shouldn't ever apply any indicator that you don't broadly understand how it works and how it's calculated. So that's all for this video on the formulas for each of the different types of moving average. Now that you understand how each of the different types of moving averages are calculated, you're probably wondering, why is the 200 day moving average one of the most powerful signals in technical analysis? And if you're wondering why the 200 day moving average is so powerful and how you can use it in your trading, this is the video that you should watch next. Because no matter what type of moving average you use, the 200 day moving average is a very, very powerful technical analysis signal. And in fact, the 200 day simple moving average is one of the best out of all of them. So watch this video to find out why the 200 day simple moving average is such a powerful indicator that you can use in your trading to improve your results.











