Amibroker Tutorial Video - Backtesting Entry Trigger Profitability With Amibroker

Adrian Reid (Enlightened Stock Trading) demonstrates how to test whether an entry trigger has a positive edge using Amibroker. He uses a highest-high breakout entry (default 200-bar highest close) on Australian stocks (1993–Dec 2018), applies liquidity and size filters, and runs optimizations over breakout length (25–300 bars in steps of 25) and holding period (10–50 bars in steps of 10). A default test (200-bar breakout, 50-bar hold) produced 2,362 trades with an average profit per trade of about 1.85%, indicating a positive edge for that entry in this market/sample.
Questions this video answers
$10,000,000
1000
$500,000 (measured over the last 20 days)
25 to 300 bars, in steps of 25
10 to 50 bars, in steps of 10
Chapters
Did you know that the vast majority of entry triggers that many traders use have absolutely zero predictive value and are no better than random? My name is Adrian Reed, and I'm the founder of Enlightened Stock Trading, and I've been a systematic, profitable stock trader for over 15 years now. And in this video today, I want to talk to you about the importance of ensuring that you have an edge, a positive edge generated by your entry trigger. Now, I know there's a lot of talk out there about how entry triggers are not that important and you make the money on the exits and everything. And while that's true, what I know from all of my trading experience and system testing over the last 15 years, and I've tested hundreds of trading systems, is that if you have an entry trigger which is no better than random or is not profitable, then you are leaving a ton of money on the table. So if you don't know whether your entry trigger has a positive edge, generates positive expectancy, then you are leaving money on the table. Now, if you get your entry trigger right, when you know that you've got a positive edge as a result of your entry trigger, then you can be a lot more profitable. Yes, entry is not the only thing that matters. You've got to have a complete trading system. But in this video, I want to demonstrate how you can determine whether your entry is better than random and whether it actually makes money. So what I'm going to do is use amibroker to show you how to to test the edge of your entry trigger over various different time frames. And I'm going to do that using a highest high breakout entry. So, looking at stocks making new highs, we're going to determine whether or not that entry trigger actually makes a difference. Is it better than random? Does it generate a positive edge in your trading? So in amibroker, what I've done is created a simple template here.
Here it is. So I've created a simple template here to.
Calculate the edge of an entry trigger over various different time frames. Now, I've just set this up and I'll run you through this real quick. I've set it up with a very high level of starting equity. So I've given it $10 million. Because what we want to do is we want to run this entry trigger over over thousands of stocks, over decades of trading data, to determine whether, on average, over many, many trades, this entry makes a difference. So we're going to have a large starting equity. Similarly, we're going to have a large maximum number of open positions. So I've set the max open positions to 1000. I'm not going to worry about margin or leverage. I'm just going to set the account margin to 100. Because this is not really a proper backtest. We're just calculating the edge of the system. I've set commissions to zero because again, we just want to know how big the edge is. This is not a complete trading system. I'm using a standard backtest and.
I'm entering the day after the breakout. So in this test we're going to see the close is a new highest high breakout and then we're going to enter the open the next day. In order to make this somewhat realistic, I'm setting a minimum turnover because I want to of the stocks that we're trading because I want to eliminate tiny little micro cap stocks or stocks that are really illiquid because I want to make this representative of stocks that you would actually trade. So I've set a minimum daily turnover over the last 20 days of $500,000. Now what that does is eliminate stocks that trade very erratically. So these are stocks that are tradable. You'll be able to get in and out without too much slippage. And so that's really important. Now here's the actual entry signal that we're testing. The first thing I've done is we're going to test different lengths of breakout. Okay, so I've set the breakout bars, number of breakout bars as an optimization variable in Amibroker. And I'm going to set a default value of 200. But I'm going to set my optimization to vary it between 25 bars and 300 bars in steps of 25. And what that's going to allow us to do is look at different lengths of breakout to see if the length of the breakout impacts the magnitude of the edge that this entry trigger gives you. And that's going to be really important. As you'll see, the actual entry trigger itself is that the closing price is equal to the highest high close of the last x number of bars, in this case breakout bars. So when we run this back test with a default value of 200, we going to enter when the stock makes a new 200 day highest close.
And then we're going to hold, in order to determine whether this entry is valid, we're going to hold it for a certain number of days. So I've set the exit bars again to an optimization variable and we're going to vary it from 10 days to 50 days in steps of 10 or 10 bars to 50 bars in steps of 10. Now you'll see here the buy signal and the sell signals. The buy signal. I'm combining the liquidity filter which we defined here, the entry trigger which we defined here, which is the breakout. And I've also added this extra thing which says basically ensures that we're only taking a new breakout. So I don't want to take every single breakout in a trend because over the course of a trend there will be many breakouts. What I want to demonstrate here is the edge generated by the first breakout in the trend. So that's what this system does, this little rule does here. Now, there's no sell signal, no formal sell signal. What I'm doing instead is having a time stop. So this is an N bar time stop using the apply stop function in amibroker. And the number of bars in the time stop is determined by this exit bars function, which again we're varying from 10 to 50. And for the purpose of this test, I'm making every single position a constant $1,000 going into each trade. And what that allows us to do is compare across all the different trades and make sure whether or not we've got an edge. So I'm going to run this back test over 20 years of data or so on the Australian stock market and we're going to see whether or not entering on a new 200 day highest close gives us a positive edge in our trading. So what do you think? We will it or not? So let's go across to the amibroker screen here and I'm just going to open up this.
Little piece of AFL code that we were working on just before. And I'm going to set the stocks to all Australian stocks. And in my backtest settings, it's long only on a daily chart. And so that's what we're going to test. And it's from 1993 to 2018, middle of December actually. Let me just set this to today and we're going to run a back test. You'll see amibroker is super quick at this sort of thing, which makes analysis so easy. So if you're trading without the benefit of trading software like amibroker, you've got to get on board because this allows you to analyze your performance of your different components of your system and your whole trading system just so much better. Okay, so you can see already in just a couple of seconds we've got data on all of the different stocks in Australia from 1993 to present on the Profitability of that breakout signal. Now remember, I just ran the default signals here, the default settings. So we're testing a 200 day breakout and holding it for 50 bars. There's no other rules. And what we want to know is, is that profitable? So coming back to amibroker here, I'm going to just click on the report tab and let's have a look at the report. I'll just maximize that. You can see it took 2,362 trades. So that's a lot of data. And the average profitability of those signals was 1.85%. Now this is huge, right? Because what this shows you is that just buying a 200 day high and holding it for 50 bars has a positive edge. This there is no stop loss, there's no exit rule, there's no fancy filtering, there's no index filtering. There's no worrying about whether it's a bull market or a bear market. This shows you that just buying a highest high breakout, a 200 day highest high breakout has a positive edge over 50 days. Now let's have a look at the chart and just see how stable this is over time. Now obviously this is not a complete trading system and I don't recommend you only trade by buying and a 200 day breakout and holding for 50 days. But what this shows you, this equity curve shows you is that the performance is fairly stable over a long period of time. Okay, there's some shaky periods in here and it's not always profitable. You know, the equity curve is going sideways in the middle here. But over the last 20 odd years.
This signal has had a positive edge. Now that's fantastic because that, that means that this is a solid basis for you to start to develop a trading system around. This is why breakout systems work. But I want to show you a couple of other things here because the question really is over what time period is this signal giving us an edge? You know, is this is 50 bars? You know, does it give us an edge over 10 bars or over 20 bars or you know, over 100 bars? So what we can do with our code here is remember we had this optimization variable which is the number of bars in a breakout. We had this other optimization variable which is number of bars. We hold for. I'm just going to leave it at a 200 bar.
Breakout for now and let's try varying the exit bars and have a look what happens. Because when you vary the exit bars, you're going to see whether or not the edge is profitable at 10, 20 30, 50 days. And that's going to give you an idea of how long term your system should be when you use this 200 bar breakout entry trigger. So I've just changed it to a param statement. So it's not going to vary amibroker when I run the optimization, it's not going to vary the breakout bars, it is going to vary the number of bars we hold for. So let me save that. I'm going to come back to amibroker here. Let's open it up again and this time I'm going to hit optimize. And what it's going to do is it's going to step through 10, 20, 30, 40, 50 days of hold period and see what sort of edge the system generates. So here we've got.
Five test values and if you look all the way over on the right hand side, if I just expand this out here a bit.
You'Ve got the number of bars held in the test. Now, coming back to the beginning, I just want to look at the average profit per trade. So let's go across here and find it. Again. Remember, this is not a complete trading system. All I want to do is demonstrate.
Is this signal giving us a profitable edge over certain amounts of time frame. So the average profit or loss in percentage terms is in this column here. And you can see that over 10, 20, 30, 40 and 50 days, the edge of, of a 200 bar breakout is absolutely profitable. And so what that means is that entry is going to give you an advantage in the markets. So is your entry giving you an advantage in the market? Right now, if you're using an indicator to give you an entry and you have not tested it, then you don't know if your trading is any better than random. You need to do this sort of analysis and validate that your entry is actually better than random and better than a simple entry trigger like this. A 200 bar highest high breakout can give you a dramatic edge. Now this is in the Australian stock market. So if you're trading in the US or in the UK or anywhere else, you want to run this on your own data on your own stocks and determine whether or not it gives you an edge in your markets too. Now I want to take this a little further so we can see that the 200 bar breakout gives us an edge over 10 to 50 days and beyond, probably. But what I want to do now is look at different lengths of breakout. So let's fix the number of bars that we hold these trades to, just 50 bars so it's a fairly long term system, medium to long term system. And then I want to vary the number of bars in the breakout and just see whether or not that makes a difference. Do lower levels of breakout, you know, that allow you to enter more quickly, give you a positive edge as well. So let's go back to our code here and, and I'm going to set the number of bars held to a default value of 50. And I'm going to change the breakout bars so the size of the breakout to an optimization variable.
So I'm going to optimize that and let's vary it from 25 to 300 in steps of 25. That will give us a good idea about whether or not different lengths of breakout give you a profitable area edge again over a constant 50 bar hold period. So let's come back to our amibroker. I'm going to open this up again and run the optimization. Now this will take a minute or two to run or even maybe just a couple of seconds. And then we'll be able to analyze whether or not different lengths of breakout have different levels of positive edge. So again, you can see that running a backtest like this in amibroker is super quick. And if you're not doing this sort of analysis, chances are you're leaving money on the table. And if you're not doing this analysis, chances are you don't have the level of confidence in your trading approach that you really need to be profitable in the long run. Okay, so the test is finished. You can see we've got 12 different.
Optimization results because we're varying our.
Breakout period from 25 to 300 in steps of 25. Now again, what I want to do is just look at the average profit per trade in percentage terms and see is that breakout giving us a positive edge and is there some sort of logical optimum over this 50 bar hold period? So let's have a look. So the shortest breakout period, not surprisingly gives us the lowest positive edge. So a positive edge of 0.44% per trade.
Buying a 25 bar breakout and holding for 50 bars. Now, now the short term breakouts are not as profitable. Why is that? It's because a short term breakout like a 25 bar breakout will get you into lots of false moves. There's plenty of moves where you'll get a little rally. It'll hit a 25 bar high, but then it'll fail and fall back to a ranging market. But the longer the breakout, the more certain you can be that you're Getting a real trend. Okay, so let's see if the data actually supports that. So as we, if we're just looking down this column here as we increase the length of the breakout, this is 25 bars, this is 50 bars, this is 75, this is 100. You see that the average profit on each of these trades is increasing. So longer breakouts give us better results, but only to a point. You'll see here that the results start to flatten off and we get less and less incremental advantage from lengthening the breakout. But what this shows me is that I would not want to use a very short term breakout for a medium term system. I much rather use a longer period breakout. Like anywhere.
In this sort of range is going to give you pretty good results, right? So that's between 125 bar say and 300 bars, doesn't really matter that much. The entry edge is fairly Constant. So a 200 bar breakout right in the middle of that range actually works really well. And this is the way that you want to evaluate your entries to make sure that they're better than random. Are they actually giving you a positive edge? Now this system, if you like the 200 bar breakout, let's just run this 200 bars 50 bars breakout again and have a look at this equity curve. You'll see when you look at the equity curve again, it's not a complete system, doesn't include slippage and commission, but this is keeping you out of bear markets. It's stopping you from buying trades when the market's going down. The overall trend in equity curve over 20 odd years is up. And so having an entry with an edge can make a dramatic difference in your trading. Now if you're not doing this, then chances are, as I said earlier, you're leaving money on the table and you probably don't have 100% confidence in your trading system. Now I don't know if the 200 Baht breakout high tide breakout is the right entry for you, but what I do know is that you need to test the entry you're currently using. And if you're not doing this, then what I want you to do is click the link on this post, click the link below and download my trading system confidence cheat sheet. Because what that'll do is show you step by step how I evaluate trading system, the steps I go through to make sure that I've got absolute confidence in my trading systems. And when you've got that confidence, you better follow your system much more consistently and you'll know for certain, is your system profitable. Simple testing techniques like this using amibroker can put you streaks ahead of the pack of unprofitable traders, because getting an edge in each component of your trading system makes a real difference. Just imagine if you take this technique. You get an entry signal with an edge, you get a trend filter with an edge, you get an initial stop loss that gives you an edge, and you get an exit signal that gives you an edge. And you get a market filter that gives you an edge. And you combine all of those together, all of a sudden you've got a dramatic positive expectancy in your trading system. It's going to make a huge difference for your trading. So click the link below and download my Trading System Confidence cheat sheet and improve your trading today. My name's Adrian Reed. This is Enlightened Stock Trading, and I'll see you in the next video. Bye for now.











