Trading on ETFs: Great Strategy on Gold (Open-Source Code + Easy Explanation + Backtest Results)

by Andrea Unger | Technical

Need More Help? Book Your FREE Strategy Session With Our Team Today!

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.


We often receive questions about ETFs (Exchange Traded Funds) and the possibility of trading them with automated strategies.

Therefore, we decided to offer you a video dedicated precisely to the systematic trading of ETFs, in which we not only analyze the characteristics of these instruments but also present an extremely interesting development example.

The presented system works with one of the most important ETFs in the world, the one on Gold, and according to the results of the backtest (using data from 2005 to today), it seems to be able to achieve excellent results.

In the video, you’ll find:
-All the characteristics of ETFs that you need to know before you start systematic trading with them (leverage, commission fees, big point value, etc.)
-An open-code strategy for the Gold ETF explained step-by-step with exit rules and optimized inputs
-An analysis of the strategy's backtest results and some valuable tips

Enjoy! 😎



Hey everyone, and welcome back to this brand-new video! One of the coaches at Unger Academy here.

And well, as we are often asked, if it’s possible to create automated strategies for ETFs? Well, today we’re going to be looking at how to do that and what are the main features of these instruments you should know before jumping in and of course, starting to trade them.

We’ll discuss them in depth to understand how to use them and how to protect yourself from the pitfalls of live trading.

What is an ETF?

Alright, so, as many of you may know, ETF stands for Exchange Traded Fund.

So, ETFs are funds that specialize in investing in a certain asset class, or in a certain financial asset, such as commodities, for example.

However, there are also ETFs that track the performance of specific stocks or stock indexes. For example, stocks in the technology sector or stocks that are related to healthcare.

So, as mentioned earlier, Exchange Traded Funds are funds that track the prices of a specific financial product.

ETFs come in two varieties. In fact, as they distribute profits, they can decide whether to accumulate those profits, and in that case we are talking about "accumulating ETFs".

Or they can decide to distribute the profits, similarly to a publicly-traded companies that decide to distribute their profits or corporate dividends, and these are called "distributing ETFs."

In the case of accumulating ETFs, the fund will reinvest the accumulated profits. On the other hand, in the case of distributing ETFs, the fund will distribute the profits it has earned. So this kind of ETFs act in a way that is quite similar to how bonds yield a return.

The Big Point Value, which is the value of a single point in this market, is $1, and that's similar to stocks, as you might know.

And that means a high scalability of these products, because you can also buy ETFs for just a few hundred dollars and then have a very low equivalent value of the position and therefore a high scalability, which makes them available also for those who don’t have a lot of capital for trading.

Overnight leverage has a maximum of 2. So, that means that if we invest $10,000 in an ETF and we want to hold that ETF overnight, meaning beyond the end of the session, when the markets are closed, we have to guarantee a margin of $5,000, or half the value of our position.

This means that they are scalable, but as stock-like products, they are still risky, and that’s why brokers generally don’t allow us to trade with a leverage of more than 2 during the overnight hours.

Commissions for these products are usually much higher than for futures. They are calculated as a portion of the equivalent value of our position, and generally range from 0.05% to 0.1% of our position.

So, in short, one could say that ETFs are definitely stand-alone products and therefore fall into their own category but now, you know, they can certainly be compared to stocks because they have a lot of points in common with those very products.

As we have already said, the maximum leverage for stocks is also 1:2.

The Big Point Value is equal to $1, and again, stocks are traded only a few hours a day.

And you know, in general, we have a lot of common features, such as the fact of profit distribution or accumulation within this financial product.

Now let's go quickly to MultiCharts and try to create an automated strategy for a well-known ETF that tracks the performance of one of the most important commodities in the world, which is… yeah, you guessed it! Gold.

A Strategy on GLD

Alright, so now we are on the MultiCharts trading platform.

Let's go and take a look at the daily data of GLD, which is a U.S. ETF that replicates and invests only and exclusively in gold, so it just focuses on this very important commodity.

So those investors who want to or would like to invest in Gold also have the option of evaluating and buying an ETF rather than just buying physical gold, for example, or other financial products that track the performance of gold, such as futures or other products.

ETFs, as I said earlier in this video, are products with high commission fees, higher than futures, as well as a high scalability.

This means that very frequent entries and exits in these products aren’t recommended, because at the end of the year, if you traded in a let's say… obsessive or very hectic way, you would end up paying a lot of commissions.

And that, of course, could impact your profits and just generally cause an increase in commission and trading costs.

Now, it is usually recommended to trade these products with multiday strategies because these products don’t expire, which means that you can keep your positions open by only paying the initial commissions, and so, if you want, you can forget about those positions and literally just be in the market for a month or more.

And this is in line with the aim of these products, which are created more as a form of investment rather than for trading.

And because, as I mentioned earlier, they don’t offer the possibility to use very high leverage and have high fees.

But let's move on to the strategy that I developed. First of all, this is a trend-following strategy, and the reason is that this logic is known to be very effective in the Gold market. So the strategy buys and sells when the price reaches the highs and lows of the Price Channel, also called the Donchian Channel, which basically calculates the highest highs and the lowest lows of the last periods.

In this case I used 170 periods. This means that, using this strategy on daily bars, we're going to identify the highest highs and the lowest lows of the last 5-6 months.

We then also set a stop loss at $700.

The size used is set at $10,000 per trade, so we set a stop loss at 7% you could say.

The profit target is set at 10%.

We also have set a break-even stop that is triggered when a profit of at least $500 is reached, so in this case, when we have a positive increase of at least 5%.

We have, of course, included the periods of the channel, as mentioned above.

And also, an input that calculates the maximum number of days that the strategy should stay on the market.

As you can see, this line is used to enter the exit condition for both the long and the short sides after 35 bars.

Bars that are daily and therefore 35 days.

Here we have the entry rules of the strategy.

So, if we are not long – and this is a condition that we've simply added to avoid the strategy entering the same bar again immediately afterwards – we’ll buy with stop orders on the upper channel and then sell with stop orders on the lower channel.

Of course, as you can guess from the inputs we’ve chosen, this strategy has already been optimized to work with the most stable values but I mean, of course, this strategy was already very good at the base, so we felt safe to proceed with the optimization.

Now let's take a look at the results that this strategy produced. Our backtest data starts from 2005, so we are able to see what this system would have produced over 17 years of trading.

Let's look at the Average trade, which is definitely one of the most important parameters to evaluate the performance of a trading system, because basically, it tells us if a strategy can actually be able to cover the commission costs and the slippage that we face in the market.

Well, in this case the average trade reaches almost 2% of the equivalent value of our position.

That's certainly a large enough value to be able to cover any costs that one would incur when trading on the GLD, and of course, we would still be able to make a good profit.

Here's the equity line. So, we definitely see a good progression of profits over time.

The profits amount to more than $10,000 over 17 years.

I just remind you that we used $10,000 as a fixed size, so we are kind of like doubling our starting capital but without reinvesting the profits generated.

And we see that the Drawdown is also very good, because it doesn’t go beyond, let’s say, 21% of the equivalent value of our average position.

So, here we go, this is the equity line that the system generates. As we can see, it’s certainly interesting.

Now let’s go and have a look at how our strategy has performed year-by-year.

Here, let's see starting from 2005.... The first four years, we can say, were really very good.

Then we see a bit of a sluggish period between about 2014 and 2018.

And then look at the last few years instead: renewed volatility in this market and generally very good returns.

Overall, this strategy brings only three negative years out of the 17 that we considered in our test.

So, it could definitely be an interesting strategy to add to a portfolio that maybe contains more hectic strategies, I mean, strategies that trade more often and maybe also work on different products and instruments.

The downside however of this strategy is definitely the number of trades that it makes year after year, which isn’t higher than... Well, we could say that on average, this strategy only makes just 3 trades per year, so only enters the market 3 times in a whole year.

Now, definitely a very low number, a statistical sample that could even falter over time, so this strategy certainly needs more time to be validated than others that trade more often.

Look, in any case, we have seen that this strategy, even if working very little, is able to make really good returns.

And in a well-diversified portfolio of strategies, it could also have a say.

So if there is anyone among you who is interested in the world of systematic trading, I recommend that you click on the link in the description of this video. From there you can watch a free presentation by Andrea Unger, get our best-selling book by covering only the shipping costs, or even book a free call with a member of our team.

If you enjoyed this video, please leave us a Like, subscribe to our channel and click on the notification bell to stay updated on the release of all our new content.

Thanks so much for watching and I will see you soon in our next video, bye-bye for now!

Need More Help? Book Your FREE Strategy Session With Our Team Today!

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.

Andrea Unger

Andrea Unger

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.