Before you start
- Windows (or Wine) with the MT5 terminal installed
- A demo or live MT5 account
Create your MetaTrader 5 API key
- 1
Open a demo account
In the terminal choose File → Open an Account and pick your broker’s demo server.
- 2
Enable algo trading
Click Algo Trading in the toolbar and allow it under Tools → Options → Expert Advisors.
- 3
Install the package
Run
pip install MetaTrader5in the same Windows Python. - 4
Store login details
Save
MT5_LOGIN,MT5_PASSWORDandMT5_SERVER(andMT5_TERMINAL_PATHif needed).
Test the key
Before wiring the key into a strategy, make one request by hand. It separates “the key is wrong” from “my code is wrong”.
import MetaTrader5 as mt5
print(mt5.initialize(), mt5.account_info())True and your account info mean Python is connected.Keep the credentials safe
- Store values in a password manager or a git-ignored
.env, never in code or notebooks you share. - In an AlgoGP project you can still add them under APIs & keys (encrypted at rest) and read them with
strategy_runtime.secrets.get("MT5_LOGIN"). - Give each bot its own credential so you can revoke one without stopping the others.
MT5_LOGIN=paste-your-value-here
MT5_PASSWORD=paste-your-value-here
MT5_SERVER=paste-your-value-here
# MT5_TERMINAL_PATH=Design and backtest your MetaTrader 5 strategy first
AlgoGP turns an idea into Python and tests it on years of history before you connect it to MetaTrader 5. The exported code keeps the broker behind four small adapter methods.
- AI copilot writes and revises the rules
- Backtests with realistic costs
- Exported Python ready to wire to MetaTrader 5
Free plan, no card required.
How the MetaTrader 5 API works
AlgoGP is not affiliated with MetaTrader 5. Menus get renamed from time to time; if a label differs, the official documentation has the current path.