We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.
BOOK YOUR FREE STRATEGY SESSION NOW >>Moving averages are among the most widely used indicators in trading. There are many types of moving averages and they can be set in various ways, so it isn't always easy to use them in our strategies.
Therefore, in today's video we'll not only explain how moving averages work but also how to use and test them in trading systems.
By watching the video you'll learn about:
- the 3 main types of moving averages and how to calculate them
- the parameters to set when using moving averages in trading systems
- how to correctly evaluate the results of backtests
You'll also find an interesting actionable idea on how to create a system based on moving averages which, judging by the equity of the backtest, looks very promising!
Enjoy the video!
Hey everyone and welcome back! One of the coaches of Unger Academy here and today we’re going to be talking about moving averages, surely one of the most known and used indicators by all traders.
Many of you have asked us if we use moving averages and what we think about them, so I thought it would be useful to discuss this topic in more detail in this video.
As already said, today we're going to be analyzing moving averages and their main aspects, and we'll see how and if they can be used in systematic trading.
But before we start, I’d like to give you a preview and show you what kind of equity lines we'll get at the end of our study. I'd like to point out that these equities are calculated on starter scripts and are calculated on a portfolio of instruments, so they can be improved by applying filters and better studying the approach on the product, on each product in particular, and I'd say that as a starting point it isn't bad at all. But now let's go in order and start from the very beginning.
So, first of all we're going to address several points, such as what moving averages are, what are their main uses, their efficiency on a timeframe that I have chosen, in this case the 240-minute (namely, the 4 hours timeframe), and finally we'll try to draw our conclusions based on the results obtained.
First of all, what are moving averages? Well, they consist of price lines that are calculated by averaging the most recent market prices. The calculation can be done in different ways depending on the type of average that you're going to use. We'll see that there are mainly three categories, but theoretically we can also find more complex categories derived from these main 3.
Lastly, as I told you at the beginning, moving averages are among the most popular instruments in technical analysis and are also used to build other more complex indicators. One of them is, for example, the Bollinger Bands indicator where the central line is a simple moving average that, in the standard setting is at 20 periods.
Here you can see an example of a simple moving average on the Crude Oil futures chart at 4 hours, and in this case we're talking about a 200-period average.
Let's now come to the main types. As I mentioned, there are 3 main types: the first is simple averages, which we'll examine later. In particular simple averages are obtained by calculating the arithmetic average of the last N prices, where obviously the number N can be varied.
Then there are weighted averages that are designed to assign a greater weight to the latest prices, namely the most recent prices.
While exponential averages are similar to the weighted average (in the sense that they also aim to assign a greater weight to the most recent prices) but the decay of the weight of the oldest data isn't constant but exponential. So, the further back you go, the less the older prices weigh in the calculation.
In this chart, we can see plotted 3 different types of averages but of the same length, so always at 200 periods. In particular the blue average, which is a bit "slower" to adapt, is the simple average, while the red average is the exponential average, and lastly the blue line represents the weighted average.
There are two main approaches when talking about moving averages in trading. More in detail, the first one is the crossing of an average with the price, or rather of the price with an average. In the sense that, one tends to go long and buy when the price crosses over a moving average, or to go short and sell when the price crosses under, therefore from the top downwards, a moving average.
The second main approach is to use two moving averages, one with a shorter period and another with a longer period. In this case you'll go long (buy) when the faster moving average crosses over the slower average, and vice versa you'll go short and sell when a fast-moving average crosses under a slow-moving average.
There are also more complex approaches such as the Daryl Guppy bundle, which involves interpreting the trend of a bundle of more averages on a chart. But we won't deal with this more complex issue.
Here's an example of trading using the first type of approach, namely the approach where the price crosses an average. In this case, for example, at the beginning you'll see that there have been multiple crosses in a small number of bars, so actually here the signal isn't very clear and probably you would have had to continue to buy and sell several times consecutively.
While instead here the signal is much clearer and in particular, at this point, we would have gone long when the price would have crossed over the average.
The second approach, as I mentioned earlier, uses two moving averages, one faster and one slower. In this case, I used a 50-period average for the fast one and a 200-period average for the slower one.
So, we'll see that in this case when the faster average (namely the blue one) crosses under the slower average (namely the red one) we should sell. While on the contrary, when the average crosses over the red one, that is the slowest, we should buy.
I coded this little script to test the efficiency of these two approaches. Obviously, like all things in computer science, you could have coded it in a different way. Anyway, here in case 1, we’re describing the first situation, namely when the price crosses over average number 1, namely the only one existing in the price-average crossover, we'll go long while if the contrary happens, we'll go short.
Case 2, instead, foresees the crossing of the averages. So, in this case, we're going to calculate also the second average and then we'll go long when average 1, the fastest one, crosses over average 2, the slowest one. And vice versa, we'll enter short.
At this point I decided to do a little test on a portfolio of futures to see how this indicator would behave on a group of different instruments. To do the test I arbitrarily decided to use a 4-hour timeframe in order to combine some short-term trading with a more medium-term trading.
So, expecting to stay a little bit longer on the market compared to an intraday trade and therefore obviously having a certain margin to compensate for the impact of commissions and slippage. Also, in order to meet everyone's needs, namely to trade both short term and longer term. So, in order to see, in general, if this kind of approach is worth it or not.
In this case, we'll see that sometimes there are contradictory results, such as this value 125 which is negative (at the level of number of periods) but should be inserted among the positive numbers, so there are certainly some critical issues that must be considered.
In addition, the 200 value is overall quite stable, it's definitely a bit more stable, and also the 250 value seems to be quite good. So as reference values in this case, I considered 200 and 250 as the number of periods to make the two tests.
Here I performed a backtest with MultiCharts Portfolio Trader on a portfolio of heterogeneous futures to understand for which instruments this approach gives the best results.
We immediately see that Silver seems to give the best results. However, I went to check the equity and personally I wouldn't use this approach on this instrument because most of the profits are concentrated in very few years and especially in 2011, which was a very particular year for this underlying asset and probably won’t repeat. So, I personally would exclude this result.
However, three very volatile energy products (notoriously very volatile) stand out immediately afterwards: Crude Oil (that is CL), Heating Oil (that is HO), and finally Gasoline (that is RB). These three products seem to pay off and are performing quite well. So, we should look for a confirmation in the next test to see if, by varying the number of periods, the situation remains the same.
Among the last instruments we find @US, which is the American bond. The worst product is German Dax future, and finally some currencies such as the Canadian dollar, which is the CD, and the BP, which is the British Pound.
If we then do the test on 250 periods, then lengthening a bit the period of the average, we can see that Silver is again in the lead. However, we should keep in mind most profits are from 2011 again, so we'd better exclude this value to make the test repeatable.
Immediately after Silver we can see that Gasoline, Heating Oil and Crude Oil stand out as top performers again. So, basically, we now have a confirmation that these 3 markets, which are known to be volatile and trend-following, match quite well with the moving average approach.
If we take a quick look at the average trade, we can also say that the three futures are all tradable because when traded with this approach they would already be able to compensate for the commissions and slippage.
Obviously, some work must be done to make them more sustainable in terms of drawdown and to obtain more appreciable results, but it's nonetheless encouraging that such a basic approach can already provide something sustainable in terms of commissions and slippage.
Going back just a moment, we can see that even here the results were still quite good and would still have allowed to cover the impact of commissions and slippage.
Now let's go to the second approach, that is to say the one of the crossings between two moving averages. In this case, I decided to do another optimization, this time using two parameters, and see what are the best results.
In particular, here I chose 50 and 200 as my values (for the first and second average) and then 50 and 300. When choosing these basic values, I checked what was performing the best and tried to choose fairly neutral values, or at least fairly "round" numbers, without going too much into detail in order to choose something particular.
At this point I went to create this table to see how the various products would behave here as well. Again, it's interesting to note that Crude Oil and Gasoline are among the top products. So, they do seem to confirm the validity of the approach also with method number 2.
However, it's interesting to note that with the second approach, the average trade is much higher. This is because the number of trades is much lower, which this means that far fewer trades were made to achieve this profit.
On the one hand, this is a good thing because clearly such an average trade would be definitely enough to cover commission and slippage. But, on the other hand, the strategy might not be very solid, because a small number of trades might not be a particularly significant statistical sample.
So, if I were to trade a similar strategy, maybe I would look for confirmation on other settings to verify its stability, or maybe I'd try to scale it on a lower timeframe (such as one hour or two hours) to allow the strategy to make more trades and then have a more significant statistical sample and define a probably more reliable strategy.
Even here Silver is among the best products, however, as we have already said, we shouldn’t be misled because Silver went through some very particular years.
Natural Gas is also well positioned here, certainly ranking among the top positions, while Heating Oil has dropped to the lowest positions together with EuroStoxx and also Dax and Cocoa, which already before gave indications that the strategy wasn't particularly profitable on that type of product.
Also, the Canadian dollar continues to remain among the last products, so it seems that also in this case more or less the sensations already seen before seem to be confirmed.
And here's a second case instead. Here we simply have changed the number of periods. Instead of 50 - 250, we use 50 - 300. RB Gasoline is again among the first products. Heating Oil is back in the lead as it was with approach number 1. In this case, since Heating Oil was doing very poorly by changing the number of bars, I personally wouldn't take it. And if I wanted to take it, I would definitely doublecheck, because if by changing the second parameter by just 50 bars it became one of the worst-performing ones, it certainly isn't a very reliable value.
Here again, Dax ranks among the worst products. Cocoa as well. And Natural Gas which was among the best products instead ends up here being among the worst products. Also, EuroStoxx ranks as being one of the worst products.
Arriving at this point, I decided to do a quick check and see what are the best results and what are the approaches on which I would eventually try to create a system.
For the analysis of these results, I basically looked at the equity lines of the products that appeared to be the most appealing using both approach 1 and approach 2, and also using the two different periods for each setup that we used.
Let's see what are the most promising results. I did the backtest obviously considering that the stability and security of the system must be a necessary requirement. So, I discarded almost all the equities that showed very erratic trends or that perhaps demonstrated to work only during small periods of time and had achieved all the profit in a few years, or even in some cases almost in only a year.
So, at this point we can talk about Heating Oil again, and specifically we're only going to talk about approach number 1, because with approach number 2, to be honest, I haven't found anything to look into further.
The problem with approach number 2 is that on a 4-hour timeframe, the number of trades is really very small, so there are some strange equities which, in my opinion, aren’t worth the while to be further examined. In particular for approach number 2 I obtained some good results in the past but by using averages on lower timeframes in order to have a more meaningful and truthful statistical sample.
In particular, here we can see in approach number 1, that was the one based on the crossing of the price with the average, in our case the closing price which is probably recognized by all as the most representative, I thought to look into Heating Oil.
Specifically, here we have the 200-bar average, so I'd say a round number. It's widely used, the 200-period average, in technical analysis. And, in my opinion, this equity is quite interesting because beyond the regularity that it seems to show, obviously beyond even a substantial portion here...
But remember that we're talking about a raw trigger here and without any kind of filter. Anyway, it looks like it's earning well both in the initial part and, overall, in the final part. Obviously in a different way, but it's interesting especially this final part that is in fact the closest to the historical period that we’re currently living in.
The scenario seems to be confirmed altogether even changing the number of periods, especially with the 250-period average. Unfortunately, here the middle part looks definitely a bit uglier while the initial part looks much better. The final part looks interesting though. I personally would try to work on the Heating Oil in general, maybe with the 200-period one that seems to have given better results, but then also going more into detail regarding the stability of that parameter.
As far as RB is concerned, the scenario is similar. After all, it's a future very similar to Heating Oil, indeed I'd say it's the future more similar to Heating Oil compared to all the others.
Also, here the scenario is similar, and in the end the RB even with 250 bars seems to confirm overall this trend that we've found on some energy futures.
I excluded Crude Oil because it seemed to gain a lot, especially at the beginning. In reality, even on gasoline there's a similar scenario, but on Crude Oil it's even more evident. So, I limited myself to take into consideration these two futures, Heating Oil and RB Gasoline.
Obviously, today we've only seen a small sample of what you can do on this platform by going to test several things.
So, in case you are interested in this kind of approach, I'd suggest that you to change the timeframe and try to add other filters.
So, recapping briefly, we've seen what are moving averages, what are the types of moving averages, the main types of use, and finally we've seen a possible use at the systematic level.
So, if you need help to invest in the financial markets in a systematic way, I recommend the link below that will take you to a page where you can find very useful resources. First you can register for a free presentation by Andrea Unger. Then you can get our best-selling book "The Unger Method" covering only the shipping costs. Or you can book a call with a member of our team for a free strategic consultation.
Thank you for having watched this video. As always, I invite you to subscribe to our channel and leave us a Like if you liked this video.
And with that, we'll see you in our next video. Until then, bye-bye!
We'll help you map out a plan to fix the problems in your trading and get you to the next level. Answer a few questions on our application and then choose a time that works for you.
BOOK YOUR FREE STRATEGY SESSION NOW >>Andrea Unger here and I help retail traders to improve their trading, scientifically. I went from being a cog in the machine in a multinational company to the only 4-Time World Trading Champion in a little more than 10 years.
I've been a professional trader since 2001 and in 2008 I became World Champion using just 4 automated trading systems.
In 2015 I founded Unger Academy, where I teach my method of developing effecting trading strategies: a scientific, replicable and universal method, based on numbers and statistics, not hunches, which led me and my students to become Champions again and again.
Now I'm here to help you learn how to develop your own strategies, autonomously. This channel will help you improve your trading, know the markets better, and apply the scientific method to financial markets.
Becoming a trader is harder than you think, but if you have passion, will, and sufficient capital, you'll learn how to code and develop effective strategies, manage risk, and diversify a portfolio of trading systems to greatly improve your chances of becoming successful.