Amibroker Tutorial Video- Using Amibroker Backtest Report To Understand Trading System Profitability

Adrian Reid backtests a trend-following strategy called the Freight Train on Australian stocks from 1993 to 2019. He walks through Amibroker's backtest report, explaining compound annual return, drawdown, profit factor, and how transaction costs affect real results. Long historical tests help you size positions and manage risk.
Chapters
Have you ever wondered how to determine quickly whether or not a trading strategy that you want to use is actually profitable?
My name is Adrian Reid and I'm the founder of Enlightened Stock Trading and I've been a profitable systematic trader for over 15 years and I've been in the markets for over 18 years now. And today what I want to share with you is, is the method that I use to quickly find out whether or not a strategy is actually profitable. So as you can see on the screen here, I've got amibroker open. Now amibroker is my trading software of choice. What amibroker does is allow you to back test your trading strategies quickly and easily and get a good understanding of whether or not the strategy is actually profitable. Now there's a lot of detail and process that you've got to go to to backtest correctly, but for the purpose of today's video, all I wanted to do is demonstrate a backtest and show you just how powerful it is to get insight into whether or not your trading strategy is profitable. Because frankly most traders out there are using rules that are not properly tested. And if you're using rules that aren't properly tested, then chances are you're going to end up losing money or losing confidence or both. And we've got to prevent that if you, you're going to be a profitable systematic trader. So let's jump straight into it. I'm going to back test today one of my favorite trading strategies which is the Freight Train system, which is a trend following system on the Australian Stock Exchange. Now members of the Trade Success System get the Freight Train as well as over 15 other trading systems as part of the Trader Success System. So if you're interested in learning how to back test, develop systems and establish a portfolio of systems very, very quickly so you can transform your trading, click the link below to find out about the Trader Success System. But right now let's get into backtesting. So the Freight Train, as I said, is a trend following system on the Australian Stock Exchange. It also works with some slight modifications on the US Market and many other stock markets around the world. And what we're going to do is we're going to test the rules in the Freight Train over all of the stocks in the Australian market over the last 25 odd years of history. And we're going to see how well they performed. So in amibroker, what we're going to do is we're going to open up the Freight train code in here in this formula bar and I've already done that for you before this video, we want to test the strategy from 1 January 1993, which is about where the Australian data that I've got on my computer starts. And I'm going to test it up until 21st November 2019, just for the purpose of this exercise. And which stocks are we going to test this strategy over? I'm going to test it over the entire Australian stock market. That list that I just selected is every listed stock in Australia. Now look, just how easy it is to get this insight, to get the insight into whether or not your system is profitable. I'm just going to hit back test. It takes just a couple of seconds. And what it's doing right now is taking my rules from the freight train system and it's applying them to every stock listed in Australia over the last 25 odd years and generating all of the buy and sell signals, doing all of the position sizing and assembling a portfolio to show you just how that strategy would have performed had you traded it in real time. Now, before I could even finish explaining it, it's finished. And what we've got here now is a list of all of the trades that this system would have taken in the past.
And when exactly it bought them, when exactly it sold them.
How many shares it would have bought, all the brokerage costs, all of that is included in here. This is all the detailed information. But what I want to share with you now is actually the performance report that really explains how profitable this strategy was and gives you a whole bunch of statistics that talk about how well this strategy performs. So we are going to click here on the backtest report and I'm just going to maximize this window so that you can see it. So let's just focus a little on this performance report, what it gives you in amibroker. When you run a backtest, you get this report which has the statistics, a bunch of charts, the list of trades, the formula that you're using, the settings you've used for the backtest, all the symbols that you've run that backtest over, and some Monte Carlo simulation results which I'm not going to go into today in this video. So let's first have a look at the statistics of the basic statistics of this system. So I've run the backtest since 1993. There's a couple of things interesting here. So you can see with this backtest, it started with $100,000 worth of capital in the account. So that's the starting Equity in the backtest. I run the backtest over 25 years and it's ended up growing to $62 million. Now that's a compound annual return, you can see here, rather here, of 27% for the life of the backtest. So 27% compound annual return over that entire test period is absolutely phenomenal. So I'm super excited about this strategy. I really love it. I trade it. It's one of the backbones of my systematic trading portfolio. But I don't want to talk too much about the system itself. I'm far more interested in sharing with you the, the power of backtesting through amibroker. So you can see here you get some high level statistics about the performance of the system. You get the annual return, you get the net profit in total dollars that the system has generated. The total profit percentage that's generated over the life of the backtest. You also get this thing called exposure. Now, exposure tells you the percentage of the time the system is actually invested. Now think about it this way. If you were 100% invested 100% of the time, the exposure figure would be 100%. If you were 100% invested 50% of the time, then the exposure figure would be 50%. So why is that so important? Well, one of the mistakes a lot of traders make when they're looking at a backtest is looking at the compound annual return figure. And if it's low thinking, oh, that's not very exciting. It doesn't make that much money. But let me ask you this. I've got a system that makes about 5% per year on average in the back test over the last 25 years. So at face value, that's not very exciting. Right? But what about if it made 5% per year on average, but it was only invested about 2% of the time? It's very, very selective about when it goes into the market to take a trade. And so it's very targeted in its trades and its profitability. So if you can make 5% return per year only being in a market 2% of the time, is that better? Is that good? Hell yes, it's good. Because the return on the capital that you've invested for the duration of time that you've invested is amazing. Now, this is why the exposure figure is so good. Because you don't want to throw away a perfectly good system just because the compound annual return, which is this figure here, is low. You want to first look at the exposure and combine that with the compound annual return. So amibroker has this statistic, which a lot of people don't understand and don't refer to, don't use, called risk adjusted return. And what risk adjusted return does is it tells you what the equivalent compound return would be had your system been invested 100% of the time. This figure is really, really powerful because I've got systems where it makes 5% per year on average. That's the annual return. But the risk adjusted return is several hundred percent per year. And the great thing about systems like that is you can combine many systems together into a portfolio and use them all on the same pool of capital and really get some amazing returns. So that's annual return and risk adjusted return. You can also see here one of the things that a lot of traders fail to do when they're testing and thinking about their system is look at the transaction costs. You want to know how rich you're making your broker, and you want to make sure that you're fully taking into account transaction costs in your testing of your trading system. Ideas. So here amibroker reports the transaction cost. And I have a generous allowance for slippage and commissions in my code for this system. And so you can see here that this system generated a lot of brokerage, a lot of commissions, over $3 million over the 25 years. Now that's great because you have also made money in the process. If you'd have traded this system, you would have made dramatically more money than that. But a lot of published trading systems, a lot of subscription sites and newsletter services and whatever, they don't take into account commissions and slippage. And so therefore, they might look great on paper before commissions and slippage, but with very razor thin margins, by the time you add slippage in commissions, they may not actually be profitable. So one of the great things about backtesting with amibro is that you can include different levels of commissions and slippage and make sure that your strategy is robust and profitable, even with commissions and high levels of slippage in the market, so that you can be sure that if you trade it in real time, you're actually going to make money, which is what we're all about here. So what else do you get in the backtest results? You get a lot more information here. So I was looking at a Facebook group about stock trading the other day, and one of the questions in there was asking how long it takes people to backtest manually to get 50 or 100 trades in their manual backtest. And my response to that question was, why would you do that? Because for you to go back and get 50 or 100 trades is going to take hours, if not days of work. And the trouble is, 50 or 100 trades is nowhere near enough data for you to actually determine whether or not a system is profitable. So the great thing about backtesting with amibroker like this is you can generate a lot of data, a lot of trades, so you get much higher levels of confidence about whether your system is actually profitable. So you can see here, this system generated 710 trades in the backtest period. And again, this is a trend following system. The system holds trades for a long time. There's some very big long trends in the Australian market. And so you don't need to take a lot of trades to make a lot of money. This is another one of the fallacies of trading. There's a lot of people out there promoting day trading and short term trading and high frequency and all of this. But you don't need to trade often to make a ton of money. This system has made an absolute fortune. I've taken hundreds of thousands of dollars of profit out of the market using exactly this system with real money. But see, this generated 710 trades over 25 years. Now it doesn't sound like a lot, but it's a lot more data than you would get manually backtesting. And that's the key here, because with 50 or 100 trades, you're not going to get a real understanding for how well the system performs, because it's probably going to be 50 or 100 trades from this year, or maybe if you're lucky, the last two years. And if we've been in a solid bull market for the last two years, for example, and you haven't back tested through 2008 or through the 2000 tech crash, then you have no idea how big your drawdown could be. You need to backtest over a much longer period of time in order to get a solid understanding of how your system is going to perform. So this backtest produced 700 trades over 25 odd years. And so it's through bull markets and sideways markets and bear markets. So you get a lot more insight into the performance of the system. So what else do you get? You get the average profit per trade, in this case 28%, which is really solid. Now why is that so high, you might be asking? Well, this is a trend following system. And so the winning trades that this system generates are huge. Losing trades are very small. So it's lots of small losses and a small number of very large winners. So It's a great way to trade because you buy, you get on a winner, and you just hold it, and it just runs and runs and runs. Makes you a lot of money without you actually having to do very much work. Which is my favorite way to trade. It gives you statistics about the winners. So the percentage of winners in this system is about 46%. According to this backtest.
This is 46% of the time you're right. That means about 54% of the time you're wrong and you lose money. But the great thing is you also know how big the winners are and how big the losers are. And to make money trading, if you think back to the expectancy equation, if you haven't come across expectancy yet, then this is a critical concept you need to look up. But.
The expectancy equation is the fundamental equation of profitable trading. And expectancy is equal to the percentage of winning trades times the average size of a winning trade, minus the percentage of losing trades times the average size of a losing trade. And that has to be profitable. Now, the key. So there's four statistics in there. There's the percent winners, the size of winners, the percent losers, and the size of losers. You can influence your trading results by playing with any of those four variables. And in fact, the easiest ones to influence for you to get more profitable are the size of winners and the size of losers, not the percentages. If you just let your winners grow and become monster winners and you cut your losses short, it's very hard not to make money. I mean, when you let your winners run and your profits are really big, they overcome almost any losses that you can make. The key is, though, you've got to cut your losses. You can't let losses get out of control, because if you put these examples into the expectancy equation, when you make your winners bigger, expectancy goes up. When you let your losers get bigger, your expectancy goes down. So ideally, what you want to do is cut your losses, let your winners run, and follow a system that allows you to do that consistently. You get high expectancy and profitability in your trading. And again, back to amibroker and backtesting. The backtest report gives you all of the information you need to see that and see how that dynamic is working. So you can see here, you've got the average percent winners, you've got the average size of winning trades here, 79%, you've got the percentage of losing trades, and you've also got the size of losing trades. So you can work on refining your strategy Adjusting the the parameters, adjusting the entry rules and exit rules, and the stop losses to give you the maximum profit that you can get out of the strategy. The backtest report from amibroker gives you all of that. Now, there's lots of other information that we don't necessarily have time to go through in this video today, but there's a few more things I want to share with you. Down the bottom of this backtest report, there's some really powerful figures. And the first one that I want to highlight here is the maximum system drawdown. Now, the reason most traders lose confidence and quit when they're following a system or a set of rules is because the maximum drawdown that they encounter in their real trading is more than they're comfortable with. So just imagine this scenario. You've got a system that you're back testing or a system that you're trading rather, and you're comfortable with a drawdown of, say, 15%. But when that system hits a drawdown in your account of 20%, you're freaking out because you were only comfortable up to a 15% drawdown. But you've now lost 20% of your account and you don't know what to do. Do we hold on? Is it going to turn around? Are we going to start making money sometime soon? How bad could this drawdown get right?
If you don't know the answers to those questions, it's almost impossible psychologically to keep following the rules. Chances are you're going to pull a pin on the system, start mucking around with it, change the rules and completely ruin it. And that's going to lead to even more losses or quitting the market in the middle of the drawdown, walking away as a loser. And if that's something you want to avoid, the maximum system drawdown in your backtest is something you've really got to pay close attention to. Now, this is the statistic I look at before anything else. When I design a new system and I first test the concept, I'm going to go straight to the drawdown line and have a look how deep the drawdown got in the past. Because if that drawdown was higher than I can tolerate, I don't care how high the returns are, because 60% return per year would be amazing, right? But if you have to sit through an 80% drawdown to get it, there is no way I'm putting my money online to do that because I just don't want that level of fluctuation in my account. So when you test a new strategy, you've got to check the drawdown and make sure that you're comfortable with it. And what I do is I actually have. For every strategy I develop, I have an objective up front that says what is the maximum drawdown I'm willing to tolerate? And that objective drives the system development. So I'm making sure that when I build a new system or when I test a system and incorporate it into my portfolio, it meets my drawdown objective because I want to be comfortable with my trading at times, and you should be, too. And the maximum system drawdown, this dip in your account, that is the key to making sure that you stay comfortable. If that gets too high and you lose faith, then it's game over. There's a couple other great, powerful statistics in here. Again, I'm not going to go through everything because it'll take hours, but this car over Max dd, it's compound annual return divided by max drawdown. What that is, is how much money on average per year does the system make divided by the maximum percentage drawdown. So this statistic in other packages and other books, sometimes it's called the ma. It's a measure of smoothness of your returns. So you want ideally high compound annual return, low drawdown. So if you divide the compound annual return by the percent drawdown, you want that number to be as high as possible. And the higher it is, the smoother the equity curve of the system. Now, in reality, there's no real threshold about what level is acceptable or not. It's really just a case of higher is better. If you've got a system that generates a compound annual return over max drawdown of 0.5, is that good? Well, it's okay. There's much better systems out there. Is it tradable? Yeah, probably, potentially. As long as the max drawdown is within your comfort zone. Your comfort zone. So when I'm playing with trading systems, improving them, optimizing and making them better, looking at this Kargramax drawdown is an important figure because I always want to make sure that with each change that I make in my system, I'm making that number better and better. Because what I'm trying to do is make the portfolio return smoother. And I'll show you the chart of the portfolio return shortly so you can see that in action.
You've also got profit factor here. Profit factor is something that a lot of trading books talk about. It's the total dollar profits divided by the total dollar losses. Obviously, the higher it is, the better it is. I don't really use profit factor that much, but a lot of people are interested in it. I much prefer to look at the car over max drawdown here, like I said earlier.
And then there's some other statistics down here like standard error and risk reward ratio and ulcer index. These are all different measures of basically SM of the portfolio and consistency of the trades. The key is you don't need to understand every single statistic in the backtest report that comes out of amibroker. But if you can look at several different measures of performance, you get a much deeper understanding of how the strategy actually performs. So that's just an overview of some of the stats. Let's go and have a look at the charts and see what that shows. So there's a couple of great charts in the backtest report. The first one is the portfolio equity chart. And what you can see here is from 1993 when we started the backtest. Up until now, had you followed this system and executed it exactly the way it is described in the code, this is the result that you would have achieved in your portfolio. Now this is a representation. If you started trading on the 1st of January 1993, or if you started trading on the 1st of January 2000 or 2005, you get slightly different results. But this is an illustration of how the equity would move in your account. It's not gospel. This is not guaranteed that you're going to achieve this in real time trading. But you need to understand how the equity grows over time, how smooth it is and how deep the drawdown is, how long the flat spots are. And when you're looking at the equity curve, and this is what we call it, the equity curve, what you're looking for is an exponential growth that is relatively smooth and consistent over time. What you don't want to see is big long flat spots or massive long drawdowns that take years to recover from. You want your equity to be growing consistently year on year on year. Are you going to have losing months or losing years? Yes, probably. Most systems do have losing periods, but you want to make sure that those are not too long and that the flat spots and dips in your account.
Take too long to recover from. So that's what you use the portfolio equity curve for. And if you're interested, you can actually download the equity curve into Excel and see day by day what the exposure and the equity is and how much cash you've got in the account according to the backtest and analyze it that way. But this is the equity curve and you want that to be nice and smooth. Exponential growth. Like I said, the second chart you get when you run a backtest in amibroker is the underwater equity. Now what this is, is it shows when you're in drawdown. Now this is critical, critical for traders to understand. If you want to be consistent and profitable, you must know this, you must get this point. You are going to spend a lot of time in drawdown. Now what is drawdown? Well, drawdown is whenever your account balance is lower than it has been at some point in the past. Let's say you had hit an all time equity peak of $100,000 at 10 o' clock this morning and at 1 o' clock today, your account is at $99,000. You're in a $1,000 drawdown. Or let's say you hit an all time equity peak three weeks ago of $125,000 and today your account balance, your account equity is $100,000. Well, you're in a $25,000 drawdown. What this chart shows is the percentage that your account has fallen at any point in time from the historic peak in your account.
You cannot grow your account trading in an absolute straight line. There's no system that just makes money every single day. It just doesn't exist. And anyone who tells you that is an absolute freaking liar. So avoid anything that says you can make money every single day consistently smoothly with no drawdown because it's a scam.
Drawdown is something that you need to be comfortable with. So when you look at this chart, what it shows you is, let's take this example here, just here. So on that day, the drawdown from the previous equity peak, which was about here was about, looks like about 12%, something like that. The maximum drawdown ever was 30%. You can see that here. So from the peak, which was about here because anytime the drawdown, the underwater equity chart hits zero, that means you're at a new equity high. So all these points where the blue line is right up the top, that means that the system achieved a new equity high on that day. And these points where the blue line is down here in the negatives, that's when you're in a drawdown. So the maximum drawdown here was 30%. So is 30% a bad drawdown? Well, it depends on your perspective and it depends on your objectives and your tolerance. Many long term systems can have quite big drawdowns. 30% is actually okay. I mean I'd be happy with a 30% drawdown if I can make 25, 30% per year over 25 years, I'm willing to sit through that level of drawdown. If 30% is beyond your level of comfort, then you need to adjust the system or design a system that fits with your drawdown tolerance. But the key is you need to understand how frequently drawdowns happen, how deep they tend to be, and the worst possible drawdown that was generated in your backtest. And that's exactly what the underwater equity chart does. Now, the next table that you get in this charts tab is the profit table. This is really interesting because what it shows you is month by month and year by year, exactly how the system performed. So you can see here, in January 1993, this system made 0.6%. And then in February it lost 1.8% and in March it gained 9.1% and so on. And so you can see month by month and also down here on the side, year by year, the returns that system made. This is really important because what it shows you is, is the variation in monthly returns and also annual returns that you can expect from your trading system that you're back testing right now. Now, I know heaps of traders who have got two or three months into a losing streak and freaked out and given up on their strategy. But if you had this information and you knew that a 3, 4, 5 month losing streak was perfectly normal, and after that losing streak, the system tended to take off and make money, then chances are you haven't been confident to sit through that losing streak. This is why the back testing is just so important. When you look at this, it gives you an understanding that you can have winning streaks and you can have losing streaks. Several losing months in a row is okay, and you can still end the year well ahead making a ton of money. But if you quit in the middle of a two or three month losing streak, you don't go on to get the recovery. And so your account stays in drawdown and you lose money. And this is what most traders suffer from. If you start using an approach and you quit just because you have a bit of a drawdown, you're quitting at the bottom and you're always going to be in losses, you're always chasing your tail. But build confidence in your system by backtesting, by looking at the results, by understanding what's possible, then you can have the confidence to follow it through, trade through the drawdown, out the other side to the profits, and keep growing your account really, really critical. So this profit table is super useful to show you what expect from your system. And I like to look at this month by month and analyze or check out the range of possible returns. How bad the losses can get in a month, how big the gains can get in a month, and kind of what to expect on average. Because whenever my real time trading goes outside the expected bounds that I see here on this profit table, that's a warning sign. And you want to check out what's going on and whether or not there's something wrong with the system or whether something is broken. Now you also get this profit distribution chart. This is a frequency histogram and it shows, it's a frequency histogram showing how many trades give you what different outcomes. So you can see here that there's 99 trades that give you a small sort of 15% loss.
Let's have a look at this. There's five trades that give you 150% gain. There's 24 trades that give you more than a 210% gain and so on. So what this does is show you the profile of trade outcomes this system will generate. And what I like to see here is a very positive skew where the results are skewed to the profitable side. I want to see lots of, lots of small losses and then a small number of very big winners. For a trend following system, a mean reversion system will have a different profile. But one of the things you've got to look out for is big outlier losing trades. Down here on the left hand side, if you have a fat negative tail, you've got to be really cautious with your position sizing because if you size too big and you've got a fat negative tail, where there's a number of big losing trades, sizing big can wipe out your account. So you've got to be really cautious. So understanding the range of possible trade outcomes is critical to your survival because it feeds into your position sizing. Now you might be able to trade for five or 10 years making really great solid returns with aggressive position sizing. But when one trade comes along that has a massive negative outcome and you're sizing too big, you can wipe out all of those profits and more and end up destroying your account. So understanding the full range of possible outcomes, possible trade outcomes, is an important feed into your position sizing. So I always want to look down here and make sure, okay, with this worst case trade that has actually happened in the past and my position sizing strategy, will I be comfortable with the drawdown that it actually generates. So that's the profit distribution chart. The next chart that you get is maximum adverse excursion distribution. That's a whole mouthful and sorry about that. But there's also a maximum favorable excursion distribution. Mae maximum adverse excursion tells you how far a trade tends to go against you before it comes back and gets closed out as either or a winner or a loser. This is really important for setting the width of your stop losses. If you have a system that has a maximum adverse excursion or a high number of trades that have an mae of say 25% and you set a 10% stop loss, you're going to end up stopping out a whole lot of trades that could have turned around and come back as winners. And so your expectancy is going to get impacted as a result. So if you look at this chart here, we see maximum adverse excursion. There's a whole concentration of trades that have a MAE of only 5%. But you can see as we go to bigger and bigger MAEs maximum adverse excursions, the number of trades drops. And so here at about 30%, this is where I've set the stop loss roughly in this system. And so beyond that there's not many trades that go beyond that level. So you can see if you had a tighter stop loss, you would stop out a lot of trades that could potentially have been winners in the future. Now another thing that MAE is useful for is analyzing how effective your entry system, your entry signals are. If you have a really tuned in entry that's great at picking entry points where from that point onwards the trade goes in the right direction, MAA is really low. If your entry is pretty random and doesn't really do a good job of selecting stocks that are about to move in the right direction, then MAE is going to be much higher. So when you're comparing two different entry signals, you can look at the maximum adverse excursion and determine which one is better at catching the right entry point. Obviously you've also got the system stats. So if you compare two different entries in a backtest, you can backtest one entry and then backtest another entry. You can compare all of the system stats, but looking at the MAE chart will tell you whether or not your entry timing is spot on or not. And then you've got maximum favorable excursion. And Maximum Favorable excursion tells you how far a stock tends to move in your favor at its peak before being exited. Now this is not the exit point because sometimes a stock will go way up and then come down and hit your trailing stop or your exit point. And when it does that, the maximum favorable excursion is the distance that it's moved in your favor as a percentage.
At its peak. And so maximum favorable excursion tells you how good your system is at capturing great moves. Your exit timing.
You want to design your exits to capture as much of the favorable excursion on your trades as you can. So here what you can see is this system generates a lot of trades that don't go very far, but it's got a really fat tail of trades that just go almost to the moon. And this is what a good trend following system will do. It's got all of these trades out here that are very big winners. They go a long way in your favor. And this is what I like about the freight train and trend following in general, because these trades are the trades that change your life, the trades that multiply your account and they just keep going and going and going, building your equity. This is my favorite sort of trade outcome. When you get on one of these where the trade goes so far in your favor, that's when your account just grows effortlessly and you end up with a huge winning year as a result. So there are all the charts you get in the amibroker backtest window. If you want to look at individual trades, you can look at them in this tab here or you can just look at them in the backtest window. Other things, if you want to look at the formulas that you use to generate those signals this backtest, then you can look here, the settings, the backtest settings that you've used are here as well and the symbols that you've generated. So that's a quick overview. Well, actually that's not quick, is it? It's a long overview of the Amy Brooker backtest report and just how useful it is. So let me ask you this. Do you want to learn how to backtest properly? Because if you have not been using statistics like this to evaluate your trading strategies, then you are missing out. You're leaving profit on the table and you're risking your money with an untested result. So if this sounds like something that you want to learn more about, click the link below and register for my free web class, which is how to quickly gain the knowledge to build wealth and freedom systematically in the stock market without the market wiping you out. Click the link below and register for the free web class and learn how you can do this in your portfolio and make even more profit from the market. So my name is Adrian Reed. This is enlightened stock trading. I hope it helps. Click the link below, register for my free web class and learn more about how back testing and trading systematically can change your world. That's all for this video. I'll see you in the next one. Click the link below and don't forget to subscribe to this channel if you found this useful and you if give it a thumbs up. Send me a comment and let me know because I want to make sure I produce videos that really help you out. Again, my name is Adrian Reed from Enlightened Stock Trading. Click the link below and register for my free web class so you can learn how to incorporate this sort of analysis into your trading life. I'll see you in the next video. Bye for now.
Sa.











