Home › Guides

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:

StepToolWhat happens
Write and compileupload_eaSends the .mq5 source; it's compiled on the server in about 5 seconds. Errors come back with line numbers.
Check inputsea_inputsReads the EA's inputs and defaults before attaching it.
Backtest itrun_backtest, get_backtestRuns 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 itrun_optimizationSearches 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 itattach_eaAttaches the EA to its own chart with the symbol, timeframe and inputs you chose.
Watch itget_logsReads what the EA printed and any runtime errors (the Experts log), or the terminal journal.
Tune itset_ea_inputs, get_ea_sourceChanges inputs (only that EA restarts), or reads the source back to edit it.
Stop itremove_ea, stop_tradingRemoves one EA, or switches off all trading on the account.

Setup

  1. Create a free HostMT5 account and add a demo MT5 account from your broker.
  2. In the dashboard, open AI & API and create a Trading key. The assistant needs it to upload and attach EAs.
  3. 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:

  1. The assistant writes the source and calls upload_ea.
  2. If the compiler reports, say, an undeclared identifier on line 42, it reads that error and uploads a fixed version.
  3. Once it compiles, it calls run_backtest and waits with get_backtest. A test takes seconds to minutes; past results don't guarantee future ones.
  4. 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.
  5. It reads get_logs to confirm the EA loaded and shows you what it printed.

Keep it safe

Honest limits

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.

Host your MT5 in the cloud, free

Real MetaTrader 5 in any browser. EAs 24/7, copy trading, TradingView webhooks. No card needed.

Start free →
More guides

All guides · HostMT5 facts