00:00Hello everyone. Today I'm going to show you one of the most underrated technical analysis techniques that has completely transformed
00:05my trading, which is calculating the moving average slopes. Most traders just look at whether the price is above or
00:11below a moving average, but they're actually missing a crucial information. The angle of the moving average tells you everything
00:17about the momentum and the trend strength. In today's video, I'll show you exactly how I calculate these slopes using
00:23Python. You will see how I use them to identify trend strength, spot potential reversals, and make better entry and
00:28exit decisions.
00:30I'll also walk you through some real-life examples so you can see this technique in action. If you want
00:34to stop getting faked out by false breakouts and start identifying real trends with confidence, this is the video for
00:40you. So let's just dive in.
00:43If this is your first time here, welcome. My name is Vivek and I'm a financially independent algo trader. This
00:48channel is all about building a community of algo traders. We discuss everything about algo trading using Python, building and
00:52back-testing trading strategies, market updates, and much more.
00:55Please do visit our community website, fabtrader.in. Also do check out my other YouTube channel, Fab Wealth, where I
01:00talk about my own financial independence journey and share tools, methods, and strategies that help me achieve my financial freedom.
01:06Thank you.
01:08The code that I'm about to walk through is, as usual, available on our community website, fabtrader.in. You're familiar
01:12with this. So you can go into stories and you would find the moving average slope.
01:17So, the article is pretty detailed. It gives you an entire account of how this works, including the actual code
01:23is embedded here. It also gives you a couple of real-world examples.
01:27And then most importantly, it tells you how to interpret the values that comes out of the program itself, right?
01:32So how to understand it, how to interpret it, and how do you find out, you know, what trend the
01:37particular stock is following can be made out from this one.
01:40You don't have to worry. I'll also provide the link to this blog article in the description, as well as
01:46in the comment section as well. So you can always refer to that.
01:52Now, let's jump into the actual code itself. I don't want to keep the video short. I don't want to
01:58spend a lot of time trying to explain what moving average is all about and all that, because I'm pretty
02:02sure you're already aware of that.
02:04So I'll jump right into the code. The code is pretty simple. It takes three inputs. One is your stock
02:10code. In this case, I'm using Yahoo Finance.
02:11The second input it takes is, what is the moving average window that you want? In this case, I've just
02:17kept 20, because since I'm considering daily candles here, 20MA is basically a good measure of MA to look at.
02:24The third input is basically the slope period. How long do you really want to consider the data going back?
02:29In this case, it's going back up to 30 trading sessions.
02:32So it would basically calculate the moving averages for this 30 day period. And then based on that information, it
02:37calculates the slope.
02:38So to make this code work, you would have to install two dependencies. One is NumPy and the other is
02:43scikit-learn.
02:44Scikit-learn is again open source. I mean, typically people use it for machine learning, especially when it comes to
02:49if you want to work with classification, regression or clustering.
02:52It's one of the best and powerful tools available in the market. So the way code works is, we use
02:58a linear regression to figure out what the slope of the moving average is.
03:01For the time period that we already mentioned. And then it returns a slope value. And then depending upon the
03:07slope value,
03:08you can now figure out whether the trend is either very weak, weak, moderate, or strong, or very strong, depending
03:13upon the value.
03:14And also if it's positive, it means it's an uptrend. If it's a negative, it is a downtrend.
03:18So I'll show you a couple of examples on how this works. For example, in this one, I've considered Infosys.
03:22Infosys, as we know, it's taken a nose dive here.
03:25So if you look at the output, the moving average slope value is actually negative and it's showing a very
03:31strong downward trend.
03:32I'll also show you the chart and we can check whether the code is working fine.
03:37So let's look at the Infosys chart itself. This is a daily candle here. And then this line denotes the
03:4230 candles, 30 day period that we're talking about.
03:45And this is the 20 EMA. We can consider moving average EMA doesn't make a lot of difference there.
03:50And this yellow line is basically the line that I drew, which basically gives you an idea as to what
03:57the slope is,
03:57which indicates that it is a pretty downtrend. Look at the way it has taken a nose dive here.
04:02So that way the code seems to be working and then giving you the right results.
04:06Now let's take a look at another example. This time, what about the uptrend bonds?
04:10For example, Bajaj Finance is in the news all the time. It's quite famous now.
04:16When the entire market seems to be going downhill, Bajaj Finance seems to be like a racing horse.
04:22So it's an interesting case. So I've taken Bajaj Finance here and then rest of the inputs remain the same.
04:27And then when we run it, we get a positive 38, which is pretty steep.
04:31And it's also showing a very strong upward trend based on the value.
04:36Let's take a look at the chart now.
04:39There you go. That's the Bajaj Finance daily chart.
04:42And then this line that I had connected from these 30 days start of the moving average to the end
04:48denotes the overall angle and the trend this stock is going,
04:52which pretty much is very clear that it's a very strong upward trend.
04:55So we've tested both scenarios with the code and the code seems to be working well.
05:02So that is how exactly the code works. You can refer to the blog article where it explains how to
05:06basically infer the data, the slope value or the angle.
05:10And then accordingly, how do you find out the trend? So you can read through this blog article for more
05:14details.
05:16So how I personally use this is basically I don't use this as a standalone indicator.
05:20You should never do. As any good algo trader would tell you, you would have to use a confluence of
05:25indicators.
05:25Do not take just one indicator and trade with it.
05:28You typically look for confirmation from multiple sources of indicators to ensure that you are in the right direction.
05:33You're making the right trade, right? That increases your success of your trade to a higher degree.
05:39So I typically take this also into account whenever I'm getting into a trade.
05:42For example, if I'm getting into a long trade, I would really want to check if the slope of the
05:46moving averages are all aligned.
05:47In fact, there are strategies that I use where I use multiple moving averages and then I check the slope
05:53of every moving averages to ensure that all of them are indeed pointing towards a particular direction that I want
05:57to take the trade into.
05:59So that is one way I use it. Or sometimes if the slope is very steep, in the case of
06:03the Bajaj winners that we talked about, I typically tend to avoid taking a trade because anything that has a
06:08very steep slope like that tend to reverse with a vengeance.
06:12So you'll have to be very careful. So you can actually use this tool in multiple ways to ensure that
06:17your whole success of the trade improves.
06:20In the next video, I'll take this concept that I've just explained and then show you a small utility that
06:25can do a screening of any stock universe that you want.
06:29And give you a list of top up trending or the down trending stocks from that universe.
06:32If you genuinely found this video useful, please consider subscribing and liking the video.
06:36And I will see you soon in another video. And until then, take care and happy trading.
Comments