Quick answer
MetaTrader 5 is not a broker but the terminal hundreds of forex and CFD brokers provide. You automate it two ways: MQL5 Expert Advisors that run inside the terminal, or the official MetaTrader5 Python package, which talks to a running terminal on the same Windows machine to read rates and send orders. There is no cloud REST API; MT4 supports only MQL4 Expert Advisors.
MetaTrader 5 API at a glance
- Pricing
- Free terminal and Python package; broker spreads apply
- Availability
- Worldwide through MT5 brokers; Python package is Windows-only
- Paper trading
- Demo accounts at almost every MT5 broker
- Integration type
- Local gateway
- In AlgoGP
- Design and backtest in AlgoGP, connect the exported code
- Python
pip install MetaTrader5(Windows, terminal running)- In-terminal
- MQL5 Expert Advisors and scripts
- Data
copy_rates_range,copy_ticks_rangefrom the broker- Orders
order_sendwith a request dict- MT4
- MQL4 only; no official Python package
Trading MT5 from Python
import os
import MetaTrader5 as mt5
mt5.initialize(login=int(os.environ["MT5_LOGIN"]), password=os.environ["MT5_PASSWORD"],
server=os.environ["MT5_SERVER"])
rates = mt5.copy_rates_from_pos("EURUSD", mt5.TIMEFRAME_H1, 0, 100)
tick = mt5.symbol_info_tick("EURUSD")
result = mt5.order_send({"action": mt5.TRADE_ACTION_DEAL, "symbol": "EURUSD", "volume": 0.01,
"type": mt5.ORDER_TYPE_BUY, "price": tick.ask, "deviation": 20, "type_filling": mt5.ORDER_FILLING_IOC})
print(result.retcode, result.comment)
mt5.shutdown()MT4 vs MT5 for automation
| MT4 | MT5 | |
|---|---|---|
| Language | MQL4 | MQL5 |
| Official Python package | No | Yes |
| Strategy tester | Single-threaded | Multi-threaded, real ticks |
| Assets | Mostly FX/CFDs | FX, CFDs, exchange stocks and futures |
Build a MetaTrader 5 strategy with AlgoGP
AlgoGP does not connect to MetaTrader 5 natively yet. MetaTrader 5 connects through a local gateway, socket, FIX or Protobuf stack rather than plain HTTPS, so it runs as a separate process next to your strategy.
- 1
Design and backtest in AlgoGP
Describe the strategy to the copilot and backtest it on years of normalized history. The result does not depend on any vendor.
- 2
Export the Python project
Every project exports
strategy.py,market_data.py,brokers.pyandlive.py. The strategy only sees bars, cash, positions and orders, never a vendor’s wire format. - 3
Plug in MetaTrader 5
Implement the four adapter methods (
account,positions,submit_market_orderand a candle fetcher) with MetaTrader 5’s SDK, or keep a built-in platform for paper trading and add MetaTrader 5 when you go live.
Built-in brokers for the same markets: Alpaca, Binance, Kraken, Bybit.
MetaTrader 5 API: frequently asked questions
Does MetaTrader 5 have an API?
Yes: MQL5 inside the terminal and the official MetaTrader5 Python package that controls a local terminal.
Can I use the MT5 Python package on a Mac?
Not natively; it requires the Windows terminal (Wine or a Windows VPS work).
Is there an MT4 Python API?
No official one; MT4 automation is done with MQL4 Expert Advisors or third-party bridges.
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.
MetaTrader 5 alternatives
- cTrader Open API GuideSpotware’s API for cTrader brokers: FX and CFD trading and data over TCP or WebSocket, JSON or Protobuf, with OAuth.
- OANDA API Built into AlgoGPRegulated forex and CFD broker whose v20 REST API serves both orders and candles, with a free demo account.
- IG API GuideRegulated CFD, spread-betting and FX broker with a REST trading API, Lightstreamer streaming and a demo account.
- FOREX.com API GuideStoneX’s retail FX broker: the GAIN Capital REST trading API for forex and CFDs, with username, password and an app key.
Independent guide. AlgoGP is not affiliated with MetaTrader 5. Limits, prices and availability change; confirm them in the official documentation. Nothing here is investment advice.