A lot of traders arrive at Python because MQL is a constraint they have outgrown. They want scikit-learn, or pandas for feature engineering, or a data pipeline that talks to something other than MetaTrader. The natural instinct is to reach for a cheap Linux box, because that is where Python lives.
Then they hit the wall. The official MetaTrader5 Python package only works on Windows. It is not a networked API — it communicates with a running MetaTrader 5 terminal on the same machine through inter-process communication. No terminal, no data, no orders. And the terminal is a Windows application.
That single architectural fact determines your entire hosting decision. This guide covers how the setup actually works, what breaks, and how to run it reliably.
How the MetaTrader5 Python Package Actually Works
The mental model most people start with is wrong, so it is worth correcting first.
The MetaTrader5 package is not a REST client talking to your broker. It is a bridge to a locally running MT5 terminal. Your Python process asks the terminal for data and sends orders through the terminal. The terminal maintains the broker connection, the authentication, and the account state.
The consequences follow directly:
- Windows only. The package depends on the MT5 terminal, which is a Windows application. There is no supported Linux build of this workflow.
- The terminal must be installed and running. If MT5 is closed,
initialize()fails. - Architecture must match. You need 64-bit Python to talk to
terminal64.exe. A 32-bit Python interpreter produces the most common error in this entire ecosystem:(-10003, 'IPC initialize failed, MetaTrader 5 x64 not found'). - Same machine. Python and the terminal live together. You cannot point the package at a terminal running elsewhere.
⚠️ Warning: If you see error
-10003, 'IPC initialize failed, MetaTrader 5 x64 not found', check three things in order: is MT5 actually running, is your Python interpreter 64-bit, and is the path you passed toinitialize()pointing at the realterminal64.exe. The path is typicallyC:\Program Files\MetaTrader 5\terminal64.exe, but a broker-branded installation will sit under its own folder name.
Why This Requires a VPS, Not a Laptop
A Python trading bot has all the availability requirements of an EA plus a few of its own.
It needs the terminal alive continuously. Your bot’s data access and order routing both depend on a running MT5 process. Anything that closes the terminal — a reboot, a sleep, an update — takes your bot offline even if the Python process technically survives.
Long-running processes accumulate state. A bot that has been running for three weeks holds warm caches, open positions it is managing, and internal state built from that history. Restarting it is not free. A host that stays up for months is worth more here than for a stateless EA.
Data collection has no natural pause. Many Python setups run a collector alongside the strategy, writing tick or bar data to disk for later analysis. A gap in that dataset is permanent — you cannot go back and collect Tuesday’s ticks on Wednesday.
Python’s memory profile is different from MQL’s. A pandas DataFrame holding months of M1 bars across several symbols is a real memory commitment, and a poorly bounded loop that appends rather than rotating will grow until it fails. Sizing matters more than for a typical EA.
📊 Key Stat: A single Python process holding a year of M1 bars for a handful of symbols in pandas can consume hundreds of megabytes before you have loaded a model. Add the MT5 terminal itself and a scikit-learn model in memory, and 2GB gets tight quickly — which is why the Pro tier tends to be the realistic floor for Python setups rather than Core.
Setting Up Python and MT5 on Your FXVPS
-
Choose a datacenter matching your broker. Same rule as any MetaTrader setup: London (LD4) for the majority of retail forex brokers, New York (NY4) for US-routed brokers and futures, Tokyo or Hong Kong for Asian execution. Our VPS location guide covers the decision.
-
Connect via RDP with your FXVPS credentials.
-
Install MetaTrader 5 from your broker’s client area so the correct server entries come preconfigured. Log in and confirm the account connects and shows live prices before you write a line of Python.
-
Install 64-bit Python 3. Download the Windows installer from python.org and take the 64-bit build — verify this, because the site will happily offer you a 32-bit installer. Tick “Add Python to PATH” during installation.
-
Verify the architecture. In Command Prompt, run
python -c "import platform; print(platform.architecture())". You want to see64bit. If it says32bit, stop and reinstall — nothing downstream will work. -
Create a virtual environment so your dependencies are isolated:
python -m venv C:\bots\venvC:\bots\venv\Scripts\activate -
Install the packages:
pip install MetaTrader5 pandas -
Test the connection with the smallest possible script:
import MetaTrader5 as mt5 if not mt5.initialize(path=r"C:\Program Files\MetaTrader 5\terminal64.exe"): print("initialize failed:", mt5.last_error()) quit() print(mt5.terminal_info()) print(mt5.account_info()) mt5.shutdown()If this prints your terminal and account details, the hard part is done.
-
Configure MT5 to allow algorithmic trading. In the terminal, enable algo trading — order submission from Python is subject to the same terminal-level permission as an EA.
-
Set both to start automatically. Put the MT5 shortcut in the Windows Startup folder, and register your bot as a scheduled task set to run at logon or at startup. Our Task Scheduler guide has the pattern.
💡 Tip: Start the terminal before your bot, and give it a moment to establish the broker connection. A common intermittent failure is a bot that starts at boot, calls
initialize()before the terminal is ready, and exits. Build a retry loop with a short delay rather than assuming the first attempt succeeds.
Writing Bots That Survive Real Conditions
A script that works while you watch it is not the same as a bot that runs for six months. The difference is entirely in the failure handling.
Check every return value. order_send() returns a result object with a retcode. Check it. A rejected order that your code treats as filled produces a position state in your bot that does not match the account — the most dangerous bug class in automated trading.
Handle disconnection explicitly. The terminal can lose its broker connection while your Python process is perfectly healthy. Poll mt5.terminal_info() and check the connection state rather than assuming data will keep arriving.
Reconcile state on startup. When your bot starts, do not assume it knows what positions exist. Query mt5.positions_get() and rebuild your internal picture from the account’s actual state. This makes restarts safe and turns a crash into an inconvenience rather than an incident.
Log with timestamps you can trust. When you reconstruct an incident later you will be comparing your Python logs against the terminal journal and the broker’s records. That only works if the machine’s clock is correct — see our time synchronisation guide.
Bound your memory. If you append to a DataFrame in a loop that runs forever, you will eventually exhaust RAM. Use a rolling window and write historical data to disk rather than holding everything.
✅ Best Practice: Run your bot as a scheduled task with “restart on failure” configured, not as a script in an open Command Prompt window. A console window is tied to your RDP session, and while a properly disconnected RDP session leaves processes running, it is a fragile arrangement. A scheduled task survives logoff and reboot cleanly. Our RDP disconnect guide explains the distinction between disconnecting and logging off.
Recommended FXVPS Plan for Python Bots
Core Plan ($29/mo) — 2GB RAM, 1 vCPU. Workable for a single lightweight bot: one terminal, modest data windows, simple logic without machine learning. Be honest with yourself about whether that describes your setup, because Python makes it easy to exceed it accidentally.
Pro Plan ($39/mo) — 4GB RAM, 2 vCPUs. The realistic default for Python-based trading, and what we recommend for most people reading this. It gives the MT5 terminal and a data-heavy Python process room to coexist, and the second core means your strategy loop is not competing with the terminal for CPU on every tick.
Scaling Plan ($79/mo) — 8GB RAM, 4 vCPUs. Required if you are running model inference, holding large historical datasets in memory, operating multiple bots across several terminals, or running research and live trading on the same box. Also the right level if you run a data collector continuously alongside your strategy.
🚀 Try FXVPS free for $1.99 — get 7 days on the Core VPS and run your bot through a full trading week before committing. Watch Task Manager during the busiest session to see which tier you actually need. Cancel anytime.
Compare specifications at /pricing/ and validate on a $1.99 trial.
Frequently Asked Questions
Can I run the MetaTrader5 Python package on Linux?
Not in a supported way. The package works by communicating with a running MT5 terminal, which is a Windows application. This is the main reason Python algo traders end up on Windows VPS hosting despite Python’s Linux heritage.
Do I need MT5 open the whole time my bot runs?
Yes. The terminal is the bridge to your broker. If it closes, your bot loses both market data and order routing. Configure the terminal to start with Windows and have your bot verify the connection rather than assuming it.
Why does initialize() fail with error -10003?
Almost always one of three things: the terminal is not running, your Python interpreter is 32-bit rather than 64-bit, or the path you passed does not point at the real terminal64.exe. Check the architecture first — it is the most common cause and the least obvious.
Can I run Python bots and regular EAs on the same VPS?
Yes, and many people do. They can even share one terminal, though running separate terminal instances is cleaner if they trade the same symbols, since it avoids magic-number collisions and makes attribution easier. Size the plan for the total load — see running multiple MT4/MT5 terminals on VPS.
Is Python slower than an MQL EA for execution?
The language difference is not what matters at retail timescales. What matters is the extra IPC hop between your Python process and the terminal, which adds a small and generally consistent overhead. For most strategies it is irrelevant; for genuine tick-level scalping, a native MQL EA running inside the terminal has the structural advantage.
Related Reading
- The Role of VPS in Algorithmic Trading — the general infrastructure case
- Automating EA Restarts with Windows Task Scheduler — the mechanism for keeping bots and terminals alive
- Time Synchronisation on a Trading VPS — accurate timestamps for reconciliation and logging
- VPS for Crypto Trading Bots — the adjacent case where APIs are networked rather than local