This is the code for my series How to Build a MetaTrader 5 Python Trading Bot found on Medium @appnologyjames
The five part series covers all you need to get started building your very own Python Trading Bot. Each episode in the series contains working code samples to help you build your own.
I could never have imagined how popular this series would become. It became so popular, I launched a YouTube Channel, and got ton's of comments, people reaching out, etc.
What I found was that many of my readers/viewers were spending tens of hours configuring their environment, before even getting to building an algorithm
I wanted to change this situation!
As a result, I've now launched Tradeoxy.com. This platform brings together things:
- Powerful API's to drastically simplify algorithm development
- Education, through free and paid courses and YouTube videos
- Supportive community where everyone helps each other
Currently we are in the build/early access stage, and we would love you to join our journey (also, it's currently free!)
To join us, head to Tradeoxy.com
If you want to follou our journey, you can do so here:
- Windows 10 or above endpoint (for whatever reason, MetaTrader doesn't support their Python API on macOS or Linux)
- MetaTrader 5 (note MetaTrader 4 doesn't have a Python API)
- A basic knowledge of Python, such as functions and variables
- Python 3 installed (my build version is 3.10)
- An IDE (I used JetBrains Pycharm Community Edition)
This episode covers everything you need to get started building your Python Trading Bot, including:
- How to set up your files
- How to securely import your settings, including username/password
- How to initialize your project through
___main___
- Where to find the MetaTrader 5 Python API
This episode shows you how to make and modify trades on MetaTrader 5. It covers:
- How to enable a trade symbol on MetaTrader 5
- Placing Trades
- Canceling an Order
- Modifying an open position
This episode demonstrates how to break down a strategy into a series of codified steps. By the end of the episode, you can take an untested strategy and implement it in your code. It covers:
- Setting up a program structure
- Design considerations
- Algorithmic decision making
- Initiating trades based on decisions Note: The algorithm used in this episode is simplistic and not recommended. It is for demonstration purposes only!
Demonstrates how to close the loop on your automated strategy, including:
- Design considerations for parallel processing, polling method for data
- Managing order queue
- Some further improvements to consider
This episode shows you how to implement one of the most requested features I get: a trailing stop. It includes:
- An overview of a trailing stop
- Ways to take this code and improve it
- How to use the
modify_position()
function to trail a price - How update an existing position
Our YouTube channel algoquant_trade contains tons of helpful content on how to use the AutoTrading Bot or build one for yourself. Check out these episodes:
- Secure Setup
- Connect To MetaTrader 5 with Python
- Retrieve 50000 Candlesticks from MetaTrader
- Add the EMA Indicator to Your Algorithmic AutoTrading Bot
- How to Install TALib on Windows
- Build Your Own AutoTrading Bot EMA Cross Detector
- How to Trade the EMA Cross Strategy with Your AutoTrading Bot
- How to Convert Your AutoTrading Bot Strategy into BUY and SELL Signals
- How to Calculate Lot Size for Your MetaTrader 5 Python Trading Bot
- How to Create Orders with Your MetaTrader Python Trading Bot