The Moving Average Convergence / Divergence (MACD) technical indicator is one of the world's most popular technical indicators. Many intraday traders use the MACD to help identify price trends and find entry points for their trades.
Whether you trade in the crypto markets, FOREX markets, or stock markets, the MACD is a useful indicator to have in your trading bot toolbox.
In this story, I’ll show you how to add the MACD to your autotrading bot.
About This Episode
This episode will demonstrate how to add the MACD technical indicator to your trading bot. If you’re using the trading bot from this GitHub repo, you’ll be able to use the MACD on any market you trade.
What You’ll Need to Complete this Episode
- 20-minutes. All up, including writing and testing the code, you’ll only need about 20 minutes to complete this episode.
- Basic knowledge of Python. I try to make sure all my content can be used by beginners right through to experts. You do need to have a basic knowledge of Python to complete this episode (or if you’re just starting out, it may take you a bit longer to complete)
- Python development environment. You need somewhere to develop and test your trading bot. I use the AI powered development environment which is completely free (at the time of writing) in this episode, so check it out if you feel that will help.
- Market data. You need data to analyze. I’ve got some great content that shows you how to get this data completely free if you need to implement this.
Learning Experience Excellence
Great education experiences lead to incredible life outcomes. At least that’s my belief. As I build my team, here’s what we’ve got so far:
- Complete code repository. All the code I share can be found in a working GitHub.
- Discord help. Got a question not answered in the article? Ask it on our community Discord!
- YouTube. If you prefer YouTube content for learning, you can follow my channel to stay up to date.
Legal Stuff
- DYOR. Note that all trading is at your own risk. My goal is to provide you with the self-developed methods, systems, and tools I use — it is up to you to figure out if this solution works for you AND if I’ve provided credible content. Always DYOR (Do Your Own Research).
- Not Financial Advice. At no point should you consider anything in these articles to be financial advice. Any opinions expressed are about the technical aspects of the topic, not financial suitability.
- Referrals. I receive no commissions for any of the products I mention in this blog. They’re all free (or have a free tier), and I simply provide links to simplify your learning experience.
- AI Use. No AI was harmed in the creation of this blog. Some of the images are partially generated or enhanced through AI tools, we always use a real human to put them together. I do not use AI to generate the text, just spell check.
Create Your Own Indicator Library
It’s almost inevitable that you won't stop with just one indicator. Almost every client I’ve ever built a trading bot for starts with one indicator then quickly expands to others. They can be technical, fundamental, AI driven, sentiment based or whatever…the point is you’re almost certainly going to want to add more indicators to your trading bot at some point.
As a result, I’m going to show you how to build your very own indicator library
This will help you now and in the future in a few ways:
- Add indicator once, use forever. You’ll only ever need to add the indicator to your trading bot dev environment once, then you can use it whenever you’re building a trading bot.
- Simplify additive indicator analysis. Once an indicator is built, adding as many indicators as you want to your trading bot will be as simple as a couple of lines of code.
- Make Python work for you. Unleash the power of automated trading on your trading bot.
Create indicators.py
Let’s start by adding our indicators file. If you’ve already used one of my episodes before, you probably already have this.
If not, add a file called indicators.py to your trading bot.
Add the Python Pandas Library
The Pandas Python Library is a bit of a game changer for data analysis. There’s entire blogs devoted to it, and I’ve come across it over and over again when developing.
Best of all, it’s super easy to add to your trading bot:
- Go to your
requirements.txt - At the bottom, add the text
pandas - Save
- Run the command
pip install -r requirements.txt
Here’s what your requirements.txt should look like now:
Watch on YouTube: Watch the episode on YouTube
Of course, you will get different values as you’re running it at a different time.
How a Trading Bot Turbocharges Your Trading
If you’re here, then your probably interested in trading bots 🚀
And let’s be honest, there’s tons of MACD related content out there. So I thought I’d take a moment to show you how a trading bot can take this simple little indicator and turbocharge your trading.
Let’s say you wanted to analyze a bunch of different stocks quickly. You could go to a chart and flick through them all.
Or you could modify ONE LINE on this trading bot and push play
Like this:
symbols = ["AAPL", "GOOGL", "META"]Watch on YouTube: Watch the episode on YouTube
You could do the same thing with the timeframe.
Quick Plug for TradeOxy
We actually use a very similar approach for the platform we’re building at TradeOxy — except we’ve scaled it tens of thousands of assets at once! Of course, we had to solve a bunch of scaling issues, but the concepts are the same.
Wrapping Up!
Hopefully this article was useful and answered any questions you had. Please subscribe to my stories via email if you’d like more content like this, it really helps me keep growing my audience and platform.
I’m always interested in hearing what’s resonating or not with my audience. If you’ve got an idea, drop me a suggestion in my suggestion box.
I’ll see you on my next episode.
Say Hi!
I love hearing from my readers, so feel free to reach out. It means a ton to me when you clap for my articles or drop a friendly comment — it helps me know that my content is helping.
❤