Buying 52-Week Highs Trading Strategy — Is it profitable? | Beyond The Charts: EP002
Hi everyone, my name is evan and welcome to our brand new series. Beyond the charts. Beyond the charts is designed to give you insights, into. The trade risks, research, process. We start by simply, asking, a question, and the question can be anything, from. Is there really such a thing as a santa claus rally, to something. Much more specific, like. Buying a breakout, after a very particular, type of consolidation. No matter what the question is we follow the same process, each and every time, that you might actually remember from middle school, as the good old-fashioned. Scientific. Method. We start by simply, observing, the market. Forming a hypothesis. And asking, a question. Next we gather our data, we write some code and we conduct, the experiment. Finally, we analyze, those results, and we compare, them to what we thought might happen. And draw some conclusions. So the goal, of this series, is three parts, the first is to simply, ask questions, and to test our assumptions, about the market. Second, is to learn how to write code we're gonna be looking at lots of code throughout the series. And hopefully, some new tools as well, to answer those questions. Third is hopefully, we get some good, results, or some meaningful, conclusions. From those experiments. And they'll actually, impact the way we view the markets. And invest, or trade, our own dollars. So all of this might not be for everyone, if looking at code makes your eyes glaze over then we're going to leave some time stamps, in the description, of all these videos. So you can jump around, and. Jump to the end if you just want to see those conclusions. Or. In the middle if you're interested, in, learning how to program, yourself. We're also going to have this available, as a blog post so you can read through this instead of watching the video, and all of the code that we're going to go through, in this series. Is going to be made public, on our github, account, for you to download, and test out yourself. So hopefully, this is interesting to you we're super excited to get started with it so without further, let's jump into. Today's, experiment. Today we're here asking the question. Does buying stocks, hitting new 52-week. Highs. Lead to a profitable. Trading strategy. Now it may sound counter-intuitive. To buy stocks that are at new highs but, this is referred to as momentum, investing, and it's becoming, increasingly. Accepted. And popular. As a trading strategy. And it comes in all different flavors. In today's experiment, we're going to be looking at stocks. Breaking out to new, 52-week. Highs, so here's how it's going to work. Go back in time 12 months, and follow a stock's, trading history. As soon as we have a full year's worth of trading, we're going to make note of the highest price, investors, we're willing to pay and prepare to buy the stock. Once it reaches. New highs, on the chart, after we own the stock we're going to set a trailing stop loss, and see how much profit. We can capture. Lots of investors, track the stocks hitting new 52-week. Highs, on a daily, basis, most financial, media sites are talking about it every day as well, your trading software, and screeners, out there all have the ability. To show you, the number of stocks in, the specific, stocks, that are breaking out to new highs, on a daily, basis. So because, it is so widely, followed. And tracked. We want to find out, is it worth, paying attention, to, and can it lead to trading, profits. So, with today's. Experiment, we're going to be building things out with ninjatrader. And, microsoft, excel, so without any further, let's dive right in. All right here we go we've got ninjatrader. 8 open, we have, our, strategy. Code, started. Just like last time we're going to be writing, just a, piece, of. This code probably about 12 lines it's a pretty straightforward.
Strategy. With some pretty simple rules, and i've already gone ahead and stubbed out kind of all of the other. Logging. And. Declaration, of variables, and all that fun stuff. So you can follow along you can sit back all of this code will be available, on our github account so you can download, it uh, run it on your local workstation. And just have, sort of the final output of everything, that we write here. Today. So, we've got our, um, our strategy, here which again if you run through the strategy, wizard you get basically, this template, in, ninjatrader. I've added in some of the documentation. I've declared, some variables. And if we scroll down there's basically. Two, methods. That we are going to be writing, together. It is the, by cell rules so line 111. And. Line 118, which is the close it 52-week. Highs. Boolean. Method, as well those are pretty much, all we're going to write here today. That'll get us our our entry, logic, for, this strategy. And then we will. Run the results, we'll visually. Sort of verify, that they're what we expect. And then we'll crunch the numbers, and look to see, uh if this actually. Makes, money. So, let's kick things off here, with our. With the closed at 52, week highs. What i'm calling the helper method here. But basically, this just returns, a true, or false value. Whether or not, the close, today. Is a new 52-week. High close, that's all this thing does. And um. It will be called. By our, buy sell rules method, which we'll write, after this. So, three lines that we need to put in here the first is to, find the highest, bar over the past 252. Days, and the reason we use 252. Days is because that's the approximate, number of days. That, equates, to one year. In, the market, because we don't care about weekends, so we want to strip out those weekends. We're basically, left with 252. Trading, days, in a year, that's a one-year, high, that we're going to be going after. So, finding the highest bar over the past 252. Days. We are going to declare. An integer. Which is going to hold. The index, of or the location. Of. The, highest. Bar. Over the past. 252. Days, so essentially, what we've got here is we've got a new integer, declared. And we're using a built-in, ninjatrader. Function called highest, bar, we're looking at closing, prices. And we're looking at 252. Days, that'll hold the index, of. The day. That was the closing, high price. So now we need the actual, price. And the way we can do that is to declare, another variable. Um. And this one we'll just call the 52-week. High. Um. 52 week high should be good. It will be, the closing, price, of, the index.
That We just found. So this will actually give us the price, value. Of, the one year high, i'm going to move pretty quick here, um. There's lots of rabbit holes we could go down in terms of explanation. And everything. But if you have questions. Again, leave them in the comments, of this video. Or on the blog post and i'll gladly. Do my best to get back to you. With an answer. So finally, now that we have that information. What we need to do is is essentially, return. Whether or not today. Is. Greater, than, our 52-week. High, so the way we can do this is we can look at the. Bars, array, that we're running this on. And i'll explain what that is in just a moment. But basically. Whatever. Uh, so bars array, index. Zero, basically, means. Whatever. Price series that we're running this strategy, on, we wanna get the close. Uh of the current bar so give me the close of the current bar. And, then let's compare, it, to see if it's greater than or equal to. The 52-week. High. Variable. That contains, the highest, price, so hopefully that makes sense hopefully you're following along you rewind, and just listen to that sentence a couple of times. But that'll give us, a true or false. Return. Which will then help us determine. If we have anything to do if there's a new buy signal. So, that completes that method that tells us uh where the new high is what the new high price was and whether or not today. Is uh greater than or equal to, that price. So when we have that information, now we have enough to, write our buy sell rules, and our buy sell rules, are pretty, pretty straightforward. Uh it's basically, just going to be the result. Of. This function that we just uh, wrote. Um, so the closed at 52-week. Highs. Um. Result. But we also just need to make sure. That we don't already, have, a position. So there's a few ways we can write this, but basically. If we use this line here, this is essentially, saying. To make sure that we are flat, on this position that we don't have a. Current active trade. In this particular, stock, so as long as it closed at 52 week highs and as long as we don't already have a position, on it, then. We want to buy. So we can do that by using the good old-fashioned. Enter long method. Which, we've used before in the past, and we are going to use this compute, share size method. I'm not going to go through this again, in this video, we we sort of talked about it.
In Last week's video, uh it's not really important here because we're not gonna be caring about position size we're not gonna build a portfolio. An equity, curve, uh like we did last time, we're really just looking for trade signals, and the results, of those trade statistics. So um, we could have entered 10 shares 100 shares it doesn't really matter. For the context. Of. This. Experiment. But what's important, is that, we are going to use a trailing. Stop. In, this, uh in this experiment. So, we're going to use a built-in, method called set trail stop. And the first parameter. It takes. Is, the, name that we gave the entry signal which is new 52-week. High. We're going to set the calculation. Mode. Of our, trailing, stop to a percent. And what that basically, means is we're just going to use a, percentage. Uh, trailing, stop. For, this, strategy. There's a million ways you could write the strategy there's there's, profit targets you can introduce, there's lots of different ways you could, compute. Trailing stops, and fixed stops. But we're going to just keep things simple. And what we're going to do. Is. Use, a simple, percentage. Method, but we're going to use a variable. So we can. Adjust. The distance. And run simulations. On different, distance, stop losses to see if it impacts. Performance. So what we did is we're going to use this stop distance, variable. I've already declared, it and initialized, it and we can set it when we do our strategy, test in just a moment, we can adjust. The distance at which our stop loss, trails. So, that's it with with that complete, here we now have. These two methods finished, up uh there's no profit target for this strategy, so it's just a trailing stop loss. And um. That's basically, it so what we can do is we can now kind of, uh move this up here, and if i scroll down you can see there's a bunch of other code, that i was sort of holding back to not overwhelm, everyone. Uh, it was the compute, share size the calculate, performance, methods, we talked about those in in our, beyond the charts episode, one, uh they're not super necessary, here but i just included them in there for good measure, the on, execution. Update, this is, a method that we do need, but it's all just for, logging, purposes. And, um. And and keeping track of strategy, performance. So it's not impacting, by cell rules, all of this is not for, you know really any other reason, except for us to. Um, you know really, assess, the strategy, which we'll do, um in a few minutes, uh later on. So, that's it, everything, is now complete. And we're ready to actually run this strategy, on, some historical, data, so let's open up the strategy. Analyzer. And let's get this strategy, ready to, run on some. Historical, market data. And the data set that we're going to choose to use. Is, the. Uh, dow jones industrial, average but the actual, stocks, that that make up the dow, so we're going to run it on. The dao, sort of composite, or constituents. And a important, note to distinguish. Here is that we're going to use. A survivorship. Bias. Free. Dow jones. Industrial. Average. Index, constituents. Right huge mouthful. But basically, what that means is, um. We want to make sure that we keep track of all of the stocks that used to be in the dow jones. 5 10 15, 20. Years ago, right so it is not okay, to essentially, run a back test on. The current, 30 stocks that are in the dow. And say that that was, your you know your hypothetical. Results, because what you're not accounting, for, are all the stocks. That, got delisted. Got bought out. Went to xero, i don't know if there's any stocks in the dow that went to zero in the past. Decade or two but. The point is is that there's a lot more than just 30 stocks you need to run this test on so once again this is why we recommend, using nor gate as as the data source, uh because they keep track of all of this stuff, uh so uh you don't have to basically. And it makes sure that your data your back test is actually, realistic. And not uh you know sort of fantasyland.
In In only picking. The survivors, the the stocks that remain. Uh in the year 2020.. So, uh survivorship, buys free dow jones. Constituents. We're going to start our back test in the year 2000. So january, 1st to 2 of 2000. To, august. 2020. And so we're gonna uh also, uh fill in our trailing stop loss distance. Right now i have five percent, in there, you can put any number you want in there but we're gonna start off with just a five percent trailing stop, so, stock hits new 52-week, highs. Buy the stock, and put a five percent trailing stop loss so let's run this, test. And let's see, uh what things look like, uh after we run this test, so we've got some results, here and our first step is let's just, let's just visually, kind of compare, and and verify. That the strategy, is actually. Um, you know buying, and selling. When it should be, so i i clicked on uh, so ticker symbol ba. So let's just go back here in time. And uh sort of visually, inspect, what's going on, so here we are you can see back in 2019. Uh 389. Dollars. Looks like a new closing, high, our strategy, buys. And then you can see the trailing stop gets triggered a couple of weeks later around 4 13. Because, note here so let me switch over to this view, uh we got as high as about, 436. And then as the stock continued to pull back here it hit our five percent threshold. And you can see we exited. Right there so that seems like. It is working, as intended, let's go back a little bit further. So here we are now back in 2018. The stock closes at new highs you can see takes out the old peak. And then we get long, stock, rallies. Get trailed out and exit the stock a few days later that looks correct. Back up a little bit further. Stock breaks out to new highs, continues, just a little bit gets stopped out, a lot of whipsaw, here in early january, essentially, buying the stock getting trailed out uh buying the stock getting trailed out so this looks. Like. Things are, working, as intended. And uh i've already, sort of uh behind the scenes, double checked on this code, so uh this this should be in pretty good, working, order, um. So, our, next step, is to actually, kind of put all this together. And, see, if it collectively. Has made money, uh over the past, uh in this case 20-year. Back test, so what we're going to do is we're going to export, all of this information, to excel. And then we're going to crunch the numbers, and, look at, some graphs, and metrics. Using microsoft. Excel, so we'll be back in just a second. Okay we're back here we've got, microsoft, excel, open, and all i've done, is. Export, all of the trade data from ninjatrader. Into. Microsoft, excel into this template that i built out to just, more closely, analyze. Um, some of the statistics, behind the strategy. Ninjatrader, is capable of doing some of it i tend to like to. Compute some different stats and just, get the trade data. Um. Imported, myself, so i can look at, things a little bit differently. But, we have all of. The trade data here.
Five Percent trailing stop laws on the dow jones, uh survivorship, bias free. Index. Let's take a look at. Metrics. First. So. Here are uh the the sort of end results, the stats, if you will, of this trading strategy. So, there were a total of. 1912. Trades almost 2 000 trades. Across. 19, years of a back test, so remember it was a it was a 20-year, back test we started in the year 2000. But um. We our strategy, requires. One full year of data. So you need a 52-week, high so you got to wait for that full year to go by. Which means your first trade doesn't actually happen until, 2001.. So it's a 19-year. Back test, which basically, gives us, about 96. Trades. Per, year, that's the average. Now some years are going to be more active than others but that's that's the average. Uh average hold time. On uh number seven here row seven, is 31, days, that's a calendar, day, so basically, one month, that is the average amount of uh time, that you are spent, in a trade. Once you buy that 52, week high. And the, cumulative. R. After, all is said and done is. 168.71. So. Whatever, your, risk is on a trade if it's one percent. Then. This would have been 168. Return. Over 20 years, so remember it's only the dow jones universe. And that's if you risk one percent, per trade and you could take all the trades. Uh we're not factoring, in position, size or comparing, it to buy and hold at this point, uh that's a good next step, uh but, that's that's not so much what we're looking at here, we're really interested, in kind of this next grid, which is the percentage, of winning trades, and then. How the winners compare to the losers. So, uh in this particular, strategy, you can see that, uh the percentage, of winning trades was only, 38.4. So most of the time when you bought this, when you when you took the signal and bought the new high. Most of the time that resulted, in a losing, trade. However. You can see in the next row, the average return of winners, is about six percent, and the average return of losers. Is negative, three percent.
So What that gives you is a a positive, uh win to loss ratio, of uh just about two just under two one point nine, eight. Uh so that basically, means, you know you're only winning at 38 percent of the time, but when you win, your lose, your winners, are are almost twice as big. As your losers. And so if we were to look at the actual, chart of this. You actually, can see, that this, does, produce. Returns. Over time this is, not exactly, an equity, curve, because. An equity curve. Would require, us to think about position, sizing, and portfolio, composition. And. Mark to market, all of these days, what this is is basically, just, looking at the results, as soon as the trade, closes, out, uh so i'm, i'm actually, graphing, the r multiple, accumulative. R multiple. Over time. And the graph, is being updated. As soon as the trade. Essentially, closes, out, so it it mimics, an equity, curve. But um it's certainly a little bit smoother, than a real equity curve would be, and um again it just doesn't factor in position, size, but it gives you a pretty good indication, here that if you were to run this strategy. Over this 20-year period, on the dow jones, it in fact. Made some money buying 52-week, highs with a 5, stop, uh did in fact work. So. If we kind of trail off here on the last couple of metrics here you can also see this does have sort of trend following characteristics. Or at least, uh this the the characteristics. That your winners, so your three largest winners over this time period 54. 38, 35. Versus your three largest, losers, 13, 12, and 12.. Um. We're much bigger so you're you're again you're your average winners your largest, winners, much bigger than your largest losers. So, pretty promising, results, so, let's actually change things up let's look at. A 10, trailing stop loss because remember we. Made the stop loss variable, so we could control. Just how wide. That, stop loss was. And so if we pull in another. Spreadsheet, here. And we look at, a, 10, trailing stop loss. What you'll notice, immediately. Is that the number of trades decreases. Pretty dramatically, so it basically gets cut in half a little bit more than half. Down to, 905. Stocks. Over, this uh or i'm sorry 905.
Trades. Over this 19-year. Back test, so a lot less trades. The, um, average, hold time jumps to 114. Days. So basically, you know we're at a 30-day, hold time the first time, now we're at 114. Days, and one of the most important stats is your cumulative. R. Is now 212. So your total, net profitability. Actually, went up, by, raising the stop loss so even though you took less trades. You actually made more money, in this particular, back test, the percentage, of winning trades, jumped up to 42, percent, the average winner's, bigger, the average loser's, bigger, and then your average win to loss ratio, actually went up. At the same time, so you won, more percentage, of the times, and you also, increased. The ratio, of winners, to losers. All in all, a very good thing, by. Increasing, that stop loss distance. If we take a look at the chart here. Pretty similar i mean the path is pretty similar, a little bit of a smoother, ride. And uh it does end up sort of getting to the same place for the most part but, again just a, more. Uh, healthy, sort of of. Of a depiction, here of, uh trading stats. So, last but not least let's take it one step further let's increase the stop loss one more time, and go to, a, 15. Stop loss, so if we look here at a 15. Stop loss once again we can see that we nearly, cut, uh the number of trades in half again. So now we're only taking let me zoom in a little bit. 502. Trades. Over, this 20-year, period, or 19-year, period, so that brings us down to 25. Trades, per year remember we started, with. Nearly 100 trades per year and then take a look at the average, hold time. In this particular. 15. Trailing stop-loss, strategy. 285. Days now. Is the average. Hold time so you're sitting in stocks for nearly. A year. And, the most important statistic, is probably. Uh row eight here the cumulative. R, continues. To go up and into the right direction, now, uh 280. Uh spot four, six. Over this 19-year. Back test, the percentage, of winning trades here also now. Nearly, a coin flip so. 47.41. Remember our first strategy, with a five percent trailing stop, um. Had basically like a 38. 37. Win rate this is nearly, uh, you know 40, almost, yeah, 47.41. The average winning size went up average. Losing size did go up but look at this ratio, now is. 3.16. So once again we saw, more stocks, uh, winning, the percentage of winning stocks went up and the average, win to loss ratio. Also went up so both of those speak to. Increased, profitability. Equity. Basically. This thing looks uh more smoother, and again it's not a pure equity curve. But, the, um. Performance, profile, here. Continues, to to head in the right direction. It's smoothed out even more and it covers more ground, to the upside. And if we look back here at the uh performance, metrics, take a look at the largest, winners now, in this particular, strategy, you're getting 204. Percent. Largest, winner here 149. 137. For your largest, three winners, and, your largest three losers, of course did go up but, certainly. Uh much smaller, by a factor of of you know 10. Compared, to those, to those winners. So. This is good news, less trading, more profit, that certainly, checks the box of of, personally, what i'd be interested, in, is seeing uh more profit and being able to do less stair screens less, uh so on and so forth less commissions, less slippage, less taxes. All that stuff, uh, is is, is something we sort of like to see, so, we're going to end it on that we're not going to go any further uh we could go on and test 20, stop losses 25, stop losses but, i think we covered a lot of ground here today, and you know really. We we. Set out to ask the question of buying, 52-week. Highs as to whether or not that can lead to profitable, trading strategies. And i think we demonstrated. That the answer is yes, uh it certainly, does lead to, profitable, trading strategies. Uh of course, you know we, sort of just scratched, perhaps the tip of of a real rigorous, test we of course would want to test.
More Markets, or more individual, stocks so we want to get outside the dow, let's see how small caps perform let's see how s p 500, stocks perform. Let's try and get some different, uh, price history, decades, in so if we get back to the 90s the 80s the 70s. That would be really cool to test. Even further back to see if the strategy, still holds up. In different, market, environments. So those are all sort of the next. Things that we would sort of want to test, if you're really going down this route to build, a. 52-week, high sort of breakout, system but, we at least got the ball rolling. And we've we've got two other things that i think are actually very interesting, that we sort of uncovered. In this, particular. Experiment. The first was stop losses, so like we demonstrated, here, going from ten, from five percent and from fifteen, to four from ten percent. Extended. Uh and an increased, profit. In each of those cases. So i think we have um, you know some of the ingredients, some of the data supporting. The fact that wider stop losses. Is a good thing at least for, this type of what i would consider, trend following, momentum, type of strategy. Not sure if this is going to hold up in all cases. But certainly we saw. That there was some good evidence here supporting, it the other thing i wanted to point out which i didn't actually mention at all, is, when we look here at this equity curve, or this performance, profile. What i want to actually, just bring our attention, to for the last couple of minutes here is, the um. The stretch. Of, the strategy. Not, producing. Returns. Right so take a look here from 2001, to 2004. This strategy, basically, went nothing but down, to sideways. Same thing from 2008. To 2012.. Now obviously. Those were bear markets. So, nothing. In terms of equities were really doing well, during those periods. But. Um. This is a um, you know this is something where. You need. Lots of conviction. And lots, of, um. You know fortitude. To really kind of stick with a strategy. Throughout, a, multi-year. Um, i don't want to call it under performance, because, we actually don't know if it underperformed, it probably. You know i would imagine that this type of strategy, would, outperform. On a risk-adjusted. Basis, but it's still a, a multi-year, period where there were no returns, generated. And so for, most, traders, out there. They are not going to stick with a strategy. That, doesn't produce results, for. Heck, you know usually multiple, months at a time. Traders are already, kind of moving on to the next thing, let alone, years at a time, so, i think this goes to show you um that you can have a very, profitable. In this case, you know breakout, system, that seems to work well over a multi-decade. Period. But. In the interim, of, multiple months or multiple, years in this case, it can actually, under you know go sideways, underperformer, just not do a whole lot, and it doesn't mean that it's broken or doesn't work it just means it's not in favor right now, and that uh maybe better times are sort of down the road, and i think that's an important lesson that uh really translates, to i think all of us no matter what we're doing, um, you know the the analogy, here is 52 week high breakouts, but you know you could be doing some, short-term, mean reversion thing or you could be doing um, i don't know some pairs trading, and perhaps it's not working right now, but, it may not just be the environment, the conditions that you need for that strategy, to really excel. In a bigger picture context. So, hopefully, um this was interesting, we got a couple of bonus little tidbit takeaways, here, and, as always i'd love to hear your feedback, and i'd love to know, uh for future episodes, what are you interested, in are there any other strategy, systems. Um. Or even just uh behaviors, in the market that you want to see tested, and i hope to see you back here in a future episode, thanks so much.
Hey It's evan here again and i'd love to know what you learned, from this episode, was there anything that stood out or surprised, you, leave a comment below, and let me know your thoughts. Thanks again for tuning in and. Watching. You.
2020-08-28 09:02