Convert Python to MQL5
Python to MetaTrader 5. Paste or upload a Python trading bot or indicator and get it back as MQL5 for MetaTrader 5 (.mq5), with a report on every part of it: what converted exactly, what had to change for MetaTrader, and what couldn't be converted.
AI-converted code to review: compile it in MetaEditor and test it in the Strategy Tester and on a demo account before you rely on it.
How it works
- Paste or upload your .py — A trading bot or an indicator: a live bot, a backtest strategy or a pandas script. Say which it is: each has its own conversion rules. We keep the MQL5 version and its report, not your Python code; it's only sent to our AI provider to convert it.
- The AI rewrites it in MQL5 — Loops become MetaTrader's events, pandas columns become bar-by-bar calculations from the formulas your code really uses, and orders become CTrade calls, while your settings, signals and stops stay as they are.
- Read the report, then compile — Every part of the code is marked as the same as Python, changed, or not converted, with the reason. Download the .mq5, compile it in MetaEditor and test it. If MetaEditor shows errors, paste them for an AI revision.
Why not just use ChatGPT?
Generic AI gives you code and leaves you alone. We fix it if it breaks.
Generic AI chatbot: Gives you code and leaves you alone. If it breaks, you're on your own. No real developer to turn to.
PositionAlpha: AI builds it, and you see a preview first. AI revisions in plain English. A real MQL5 developer fixes it, at no extra cost.
ChatGPT is a trademark of OpenAI. We are not affiliated with OpenAI.
Developer Fix Guarantee
AI builds it. Real MQL5 developers make sure it works.
If your converted file doesn't compile or doesn't do what you approved, one of our developers fixes it by hand, at no extra cost. We reply within 24 hours, and if we can't fix it, you get your money back.
Our developers have built 300+ trading bots for prop firms and hedge funds.
We guarantee working code that follows your rules, not trading profits. No bot is guaranteed to make money, and trading can lose money.
See exactly what changed
Sample report: RSI Bollinger bot (backtrader).
- Same as Python:
params = (("rsi_period", 14), ("bb_period", 20))→ MT5 inputs, same names and defaults - Same as Python:
bt.indicators.RSI(self.data.close, period=14)→ iRSI handle read with CopyBuffer - Same as Python:
self.rsi[0] < self.p.rsi_low→ The closed bar, read once per new bar - Same as Python:
self.close()→ CTrade.PositionClose - Changed:
self.sell() while long→ Close the buy, then open only what's left. backtrader holds one net position. On an MT5 hedging account a sell would open beside the buy, so the EA closes first. - Changed:
bt.sizers.PercentSizer(percents=20)→ 20% of equity, turned into lots. MetaTrader sizes in lots, so the share of equity is divided by the price and contract size, then rounded to the volume step. - Changed:
GenericCSVData("eurusd_h4.csv")→ The chart's bars, H4 time frame input. The EA reads your broker's prices. Attach it to the symbol the CSV held. - Not converted:
cerebro.broker.setcash(...), setcommission(...), analyzers, plot(). These run the backtest in Python. Set the deposit and costs in MetaTrader's Strategy Tester instead.
- Results won't match the Python backtest. backtrader fills at the next bar's open with no spread. MetaTrader fills on ticks, with your broker's spread and costs.
What it converts
- Live bots on the MetaTrader5 package, ccxt and other broker libraries
- Backtest strategies in backtrader, backtesting.py and freqtrade
- Indicators and signal scripts in pandas, numpy, TA-Lib and pandas_ta
- Settings, with the same names and defaults, as MT5 inputs
- Indicator formulas as your code calculates them, including sample or population deviation and how each average starts
- Orders, stops, targets, trailing stops and sizing, turned into CTrade calls and lots
- Plotted series, levels and markers, as MT5 indicator buffers
What it changes or leaves out, and tells you
- The backtest harness and logging in: an Expert Advisor doesn't need them
- Sizes in units, coins or a share of the account, turned into lots
- Machine-learning models, web APIs and data files: MQL5 can't have them, and if the main signal depends on one, the code can't be converted
- Telegram messages, web requests and file access: left out of converted code
- Code that reads future bars (shift(-1), centered windows), which a live program can't do
- Bugs and risks kept from the original, such as a missing stop loss or a martingale
Why Python to MQL5 conversions go wrong
A trading bot in Python and an Expert Advisor can read almost the same and still trade differently. These are the usual reasons:
The newest row isn't always a closed bar
In backtrader, close[0] is the bar that just closed. With the MetaTrader5 package or ccxt, the last row is still forming. Mix them up and the bot trades a bar early or late.
An indicator's name isn't its formula
pandas' .std() divides by n - 1 and MetaTrader's iBands by n. MT5's iATR is a simple average and TA-Lib's is Wilder's. A function called rsi may not be Wilder's RSI at all.
A sell can mean two things
In backtrader or backtesting.py, a sell while long reduces the position. On an MT5 hedging account it opens a second position beside the buy.
Sizes aren't lots
Python bots trade units, coins or a share of the account. MetaTrader trades lots, with a contract size and a volume step that depend on the symbol.
A backtest can read the future
shift(-1) and centered windows use bars that haven't happened yet. A live Expert Advisor can't, so a strategy built on them won't behave like its backtest.
Numbers behave differently
7 / 2 is 3.5 in Python and 3 in MQL5. NaN passes quietly through pandas, and a division by zero stops an MQL5 program.
The converter is built around these differences, and its report tells you where the MQL5 version can still differ.
Pricing
Converting a Python bot or indicator is free to try: you see the report and a preview of the code. You pay once to download the .mq5 file, and the price is shown before you pay. Bot Studio is pay per build: building and previewing a bot, an indicator or a conversion is free, and you pay once to download it. Each of those purchases includes AI revisions and a fix by a professional MQL5 developer. No subscription.
Questions
What if the AI code doesn't work?
If your converted file doesn't compile or doesn't do what you approved, one of our developers fixes it by hand, at no extra cost. We reply within 24 hours, and if we can't fix it, you get your money back. We guarantee working code that follows your rules, not trading profits.
What kind of Python code can it convert?
Trading bots and indicators, in one .py file: a live bot on the MetaTrader5 package or ccxt, a backtest strategy in backtrader, backtesting.py or freqtrade, or a script in pandas and numpy. Pick Trading bot or Indicator before you convert: each has its own conversion rules. For a Jupyter notebook, export it as a .py file first.
Will the MQL5 file compile?
The AI is told to write code that compiles in MetaEditor on the first try and to follow MQL5's rules, but PositionAlpha doesn't compile or test the code. Compile it yourself in MetaEditor. If it shows errors, paste them on the result page for an AI revision, or request a developer fix.
Will my bot trade the same way as my Python backtest?
It's written to keep the same signals, orders, stops and exits, but the results won't match. A Python backtest usually fills at a bar's open with no spread, while MetaTrader fills on ticks with your broker's prices, spread and costs. The report lists every difference the AI knows about, so test it in the Strategy Tester and on a demo account before using real money.
Does it change my strategy or fix its bugs?
No. It converts what your code does, settings included. Bugs and risks it notices, such as a missing stop loss, are kept and listed in the report. To change the result, ask for an AI revision after converting.
My bot uses a machine-learning model or a web API. Can it be converted?
Not when the main signal depends on it: a trained model, a news or sentiment feed and data from a web API or a file can't exist in an MQL5 program. That comes back as can't be converted, which is free. If only a small part depends on one, the rest is converted and that part is reported.
Should I take my API keys and passwords out first?
Yes. An Expert Advisor runs inside your logged-in MetaTrader, so it needs no broker password or API key. Values that look like them are blanked out before the code goes to the AI, but that can miss some, so remove them before you paste.
Do you keep my Python code?
No. PositionAlpha keeps the MQL5 version and its report in your account, not your Python code. The code is sent to our AI provider to convert it.
How much does it cost?
Converting and previewing is free. Downloading the .mq5 file is a one-time payment, shown before you pay, and it includes AI revisions and a fix by a professional MQL5 developer. We guarantee working code that follows your rules, not trading profits.
Python is a registered trademark of the Python Software Foundation. PositionAlpha isn't affiliated with the Python Software Foundation.
MetaTrader, MQL4 and MQL5 are trademarks of MetaQuotes Ltd. PositionAlpha isn't affiliated with MetaQuotes.