Advertisement IC Markets

Research in a Python notebook, execution through MT5

Share, develop, and backtest custom MQL4/MQL5 Expert Advisors, Python data-scraping scripts, trading bots, and automated market alert systems.
Post Reply
FXS London Scalper
Posts: 1119
Joined: Sun Oct 18, 2026 12:25 pm

Research in a Python notebook, execution through MT5

Post by FXS London Scalper »

A popular workflow: do research in Python (pandas, numpy, backtesting libraries) and execute through MT5 using the official MetaTrader5 Python package or a bridge.

What works well:
- Python for data analysis, feature engineering and backtesting.
- MT5 for order execution, position management and broker connectivity.
- The MetaTrader5 package for pulling history and sending orders from Python.

Pitfalls:
- The Python package requires the MT5 terminal running on the same Windows machine.
- Latency between Python decision and MT5 execution can be higher than a native EA.
- Error handling: network drops, terminal restarts and rejected orders need solid code.
- Research and live code diverge. The backtest uses one function, the live bot a slightly different one.

Advice from people who've done this:
- Share code between research and live wherever possible.
- Log every decision and order with timestamps.
- Run in paper mode for weeks before going live.
- Keep the MT5 side simple. Let Python handle logic, MT5 only executes.

Anyone running this setup in production? How do you handle terminal restarts?
FXS Official Team | London Session Desk
Recommended broker for automated trading & scalping IC Markets
Amanhasnoname
Posts: 2438
Joined: Fri Oct 30, 2026 9:45 am

Re: Research in a Python notebook, execution through MT5

Post by Amanhasnoname »

Terminal restarts are the part most people underestimate with this setup, so build for them from day one. Treat the Python process as stateless: on every start, query open positions and pending orders from MT5 and rebuild your internal state from that, never from a local variable or file alone. Tag each order with a magic number and a unique comment so the bot can recognise its own trades and never duplicate an entry after a reconnect.

On the latency point, keep the decision loop and the order call close together and measure the round trip between a signal and the fill confirmation, because a Python bridge adds a hop a native EA does not have. For scalping, check the spread and the price again right before sending, and use a deviation limit so a late order does not fill far from the intended level.

Also handle the failure paths on purpose. Check the return code of every order request, retry only the codes that are safe to retry, and log each decision with a timestamp so a restart can be audited afterwards. Run the same code path in research and live as far as you can, and paper trade it through a few forced terminal restarts before risking real money.
Post Reply