Let Claude or ChatGPT build and run your MT5 EA
Updated 2026-11-28 · HostMT5 guides
Claude and ChatGPT can write MQL5, but the first version often doesn't compile, and copying errors back and forth from MetaEditor gets old fast. Connected to HostMT5, the assistant does the whole loop itself: it writes the EA, has it compiled on the server, reads the errors, fixes them, attaches the EA to your demo account and checks its log. The EA then keeps running 24/7 in your hosted MT5.
What the assistant can do
The HostMT5 MCP server gives the assistant 49 tools. These are the ones for building an EA:
| Step | Tool | What happens |
|---|---|---|
| Write and compile | upload_ea | Sends the .mq5 source; it's compiled on the server in about 5 seconds. Errors come back with line numbers. |
| Check inputs | ea_inputs | Reads the EA's inputs and defaults before attaching it. |
| Backtest it | run_backtest, get_backtest | Runs MT5's Strategy Tester on your broker's history in a sandbox copy of the terminal that can't trade, and returns net profit, profit factor, drawdown, trades and win rate. |
| Optimise it | run_optimization | Searches input ranges (every combination up to 20,000, or genetic) and can check the best settings on the last third of the period, kept out of the search. |
| Run it | attach_ea | Attaches the EA to its own chart with the symbol, timeframe and inputs you chose. |
| Watch it | get_logs | Reads what the EA printed and any runtime errors (the Experts log), or the terminal journal. |
| Tune it | set_ea_inputs, get_ea_source | Changes inputs (only that EA restarts), or reads the source back to edit it. |
| Stop it | remove_ea, stop_trading | Removes one EA, or switches off all trading on the account. |
Setup
- Create a free HostMT5 account and add a demo MT5 account from your broker.
- In the dashboard, open AI & API and create a Trading key. The assistant needs it to upload and attach EAs.
- Connect your assistant to
https://hostmt5.com/mcp. For Claude Code:
claude mcp add --transport http hostmt5 https://hostmt5.com/mcp --header "Authorization: Bearer mc_your_key"
Claude.ai, ChatGPT, Cursor and VS Code: see connect MT5 to Claude or ChatGPT.
An example prompt
Write an MT5 EA that buys XAUUSD when the H1 RSI(14) crosses back above 30
and sells when it crosses back below 70. One position at a time, 0.01 lots,
stop loss 300 points, take profit 600 points. Compile it, fix any errors,
backtest it on XAUUSD H1 for 2026 and show me the results. Then attach it
to my demo account on XAUUSD H1 and show me the Experts log after it loads.
A typical run looks like this:
- The assistant writes the source and calls
upload_ea. - If the compiler reports, say, an undeclared identifier on line 42, it reads that error and uploads a fixed version.
- Once it compiles, it calls
run_backtestand waits withget_backtest. A test takes seconds to minutes; past results don't guarantee future ones. - It then calls
attach_ea. The first attach of a new EA takes about 30 seconds, because MT5 restarts once to see the file; your other EAs come back by themselves. - It reads
get_logsto confirm the EA loaded and shows you what it printed.
Keep it safe
- Start on demo. AI-written code can compile and still trade differently from what you meant. Watch it on a demo account before you move it to a live one.
- Read the code. Ask the assistant to explain the entry, exit and position-size logic in plain words, and check the stop loss is really set.
- Use the kill switch. "Stop all trading on my real account and close everything" calls
stop_trading: Algo Trading goes off for every EA and stays off through restarts until you resume. - Analysis only? Give the assistant a Read-only key. It then sees only the read tools and can't trade.
Honest limits
- MetaTrader 5 and MQL5 only; no MT4 or MQL4.
- There's no MetaEditor window on the server. The assistant (or you) edits the source and uploads it again.
- Up to 10 EAs per account. Ask before relying on EAs that call DLLs.
- HostMT5 runs your code; it doesn't judge your strategy, and nothing here is trading advice.
Prefer to write the code yourself? The REST API has the same upload, attach and log calls.
FAQ
Can ChatGPT or Claude write an MT5 Expert Advisor?
Yes, in MQL5. Connected to HostMT5 through MCP, the assistant can also compile it on the server, fix the compile errors, attach it and read its log, without MetaEditor.
Where do compile errors go?
Back to the assistant, with line numbers, so it can fix the code and upload it again. Compiling takes about 5 seconds.
Is it safe to let an AI trade?
Start on a demo account and read the code. Use a Read-only key for analysis without trading, and the stop_trading tool as a kill switch.
Does the EA keep running after the chat ends?
Yes. It runs in your hosted MT5 terminal 24/7, like any EA you upload yourself.
Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.
Start free →- A free MT5 VPS alternative: hosted MetaTrader 5, free during launch
- Do you still need an MT5 VPS?
- How to run an MT5 Expert Advisor 24/7 without your PC
- TradingView alerts to MT5 orders with a webhook
- Copy trades between MT5 accounts at different brokers
- A MetaApi alternative for traders, not only developers
- A free PineConnector alternative with MT5 hosting included
- The full MT5 terminal in your browser
- Let an AI assistant work with your MT5 account
- Use MT5 from Python on Mac, Linux or a notebook
- A REST API and live stream for MetaTrader 5
- Download years of MT5 price history to CSV
- Moving Skynet MT5 alerts to HostMT5