Clockwork Robot holding a red trending upward in steps arrow.
Python Trading Bot

Python Trading Bot

How to Get All Your Open Positions from MetaTrader 5 with Python

James Hinton
2 min readNov 23, 2022


MetaTrader 5 made Python Trading Bot development significantly simpler. Suddenly it was possible to access the vast range of features available on MetaTrader without going through the pain of learning C++.

For Python developers, it was a double win. Python has a huge range of free libraries available for just about any time of computing discipline you can imagine, and it’s incredibly easy to integrate them together. My company, Creative Appnologies, uses this feature of Python for much of our analysis. An open-source version of our Python Trading Bot is being developed and is available on GitHub.

One of the key functions you need in a Trading Bot is the ability to list all your open positions. This can be especially useful if you’re tracking multi-day trades.

To do this on MetaTrader 5, do the following:

  1. Make sure you’re connected to MetaTrader 5
  2. Integrate the following code:

Enjoy, and don’t forget to follow me on Medium, Twitter, and LinkedIn

P.S. If you need to see how to integrate this function into a Trading Bot, check out my series “How to Build a MetaTrader 5 Python Trading Bot”

Update August 2023

I could never have anticipated how popular this blog, along with a YouTube channel would become.

After a listening to my readers/viewers feedback, I realized that many people were spending huge amounts of time trying to solve installation/configuration problems — rather than experiencing the joy of algorithmic trading.

I want to change this narrative — and in so doing, open up algorithmic trading for everyone.

To do this, I’ve recently launched Tradeoxy: Trading For Everyone.

If you’re reading this, Tradeoxy will simplify 90% of this series, using a series of powerful API’s and easy to use tooling.

Currently it’s in the early-access / building stage and I’d be incredibly grateful if you’d join us on this adventure. Your feedback will help us shape a better product.

Join the early access program (for free) here.

You can also view our launch video, and follow our journey on LinkedIn, Twitter, Instagram, YouTube.



James Hinton

Passionate algorithmic trader and Cyber Security expert. Love developing helpful content.

Recommended from Medium


See more recommendations