Trade with Claude in MetaTrader 5

A simple guide for CXM clients who have MetaTrader 5 and Claude Code on the same Windows computer. Setup takes about 10 minutes.

  • For MetaTrader 5 build 6060 or newer
  • Windows
  • Claude Code
  • Demo account first
Start on a demo account. Everything Claude does in MetaTrader happens on the account the terminal is logged into. Nothing in this guide is financial advice.

What you need

  • MetaTrader 5 for Windows, build 6060 or newer. Check with Help → About. If your build is older, restart MetaTrader and let it update.
  • Your CXM demo account, logged in inside MetaTrader.
  • Claude Code on the same computer (installation instructions: https://code.claude.com). Claude Code runs in a text window: you type a request and Claude answers below it.
  • Nothing to install in MetaTrader and no programming.

Setup in five steps

1Switch on the connection in MetaTrader

  1. In MetaTrader open Tools → Options (or press Ctrl+O).
  2. Open the MCP tab.
  3. Tick Enable internal server.
  4. Leave Address and API Key as they are. Do not press Generate.
  5. Do not close the window yet.

2Decide whether Claude may trade

  1. In the same Options window open the AI Assistant tab.
  2. Open the Trading list. It has three choices: Enabled, Manual confirmation and Disabled.
  3. Choose Enabled if you want Claude to place and manage orders. Choose Disabled if you want Claude only to read your account and charts. With Claude Code you confirm each order in Claude Code itself (Step 5), so use Enabled or Disabled. You can change this at any time.
  4. Click OK. Close MetaTrader and open it again.

3Create the settings file for Claude Code

  1. In MetaTrader open Tools → Options → MCP and click Copy. MetaTrader puts the connection settings on the clipboard, including your personal access keys. Treat this text like a password.
  2. Create a folder for Claude, for example C:\Claude-MT5. (In Explorer open This PC → Local Disk (C:), right-click an empty space and choose New → Folder.)
  3. Open Notepad and paste the text (Ctrl+V). Keep this window open: you will take two keys from it.
  4. Open a second Notepad window and paste the template below into it (use the Copy button on the box).
JSON
{
  "mcpServers": {
    "metaeditor": {
      "type": "http",
      "url": "http://127.0.0.1:22345/mcp",
      "headers": { "Authorization": "Bearer PASTE-METAEDITOR-KEY" }
    },
    "terminal": {
      "type": "http",
      "url": "http://127.0.0.1:22346/mcp",
      "headers": { "Authorization": "Bearer PASTE-TERMINAL-KEY" }
    }
  }
}
  1. In the first window find the part that begins with "metaeditor". A few lines below it there is a line with the word Bearer followed by a long code of letters and digits. Select only the code, copy it, and paste it into the second window in place of PASTE-METAEDITOR-KEY.
  2. Do the same for the part that begins with "terminal" and PASTE-TERMINAL-KEY. The two keys are different.
  3. Save the second window: File → Save As, open the C:\Claude-MT5 folder, set Save as type to All files, type the name with the quotation marks, ".mcp.json", and click Save.
  4. Close the first window without saving.

4Start Claude Code

  1. In Explorer open the C:\Claude-MT5 folder, click the address bar at the top, type cmd and press Enter. A black text window opens.
  2. Type claude and press Enter.
  3. The first time, Claude Code asks whether to use the MCP servers found in .mcp.json. Choose Yes with the arrow keys and press Enter.
  4. Type /mcp and press Enter. A list appears and terminal shows as connected. metaeditor shows as connected only while MetaEditor is open (in MetaTrader press F4); you need it only for building trading robots. Press Esc to close the list.

To leave Claude Code later, type /exit and press Enter. To start it again, open the black window in the same folder and type claude.

5Say hello

Type in Claude Code:

  • Show my account.

Claude replies with your account number, server, balance and equity, and says whether the account is demo or real. Compare the account number with the MetaTrader title bar and the balance with Toolbox → Trade. If they match, you are connected.

Before each MetaTrader action Claude Code asks for your permission and offers Yes, Yes, and don't ask again, or No. For actions that only read (account, positions, charts) you can choose "don't ask again". For every order choose plain Yes, so you approve each trade yourself.

What to watch in the terminal

  • Toolbox → Journal. Every action Claude takes is written here in plain words, for example send market order market buy 0.01 XAUUSD or XAUUSD:M5 chart opened. This is your record; read it after every session. After each start of MetaTrader you also see a line beginning MCP: started, which means the connection is on.
  • Toolbox → Trade. Positions and pending orders that Claude opens appear here immediately, with the comment you asked for, for example "MCP demo". The Ticket column shows each position's number. The profit here is live; the number Claude quotes is from the moment you asked.
  • The chart. Orders show as arrows and lines on the chart of the same symbol. Ask Claude to trade the symbol whose chart you are watching.
  • Market Watch. Check that the symbol has a fresh quote time before you trade. Use the exact symbol name shown here when you talk to Claude.
  • Tools → Options → AI Assistant → Trading. This setting decides whether Claude can place orders. The AutoTrading button on the toolbar does not stop Claude.
  • Tools → Options → MCP → Enable internal server. Untick it to cut every AI program off from MetaTrader at once. Close MetaEditor as well if it is open.
  • Keep MetaTrader open and logged in. Claude works only while MetaTrader runs on your computer. If the computer sleeps or MetaTrader closes, Claude loses the connection, and positions already opened stay open.
  • Restart after changing Options. After any change on the MCP or AI Assistant tab, close MetaTrader and open it again.

Prompts you can use

Use the exact symbol name from your Market Watch. The examples use XAUUSD (gold); replace it with your symbol. When you ask for an order, always say the symbol, buy or sell, and the size in lots, for example 0.01. When you change or close a position, give its number from the Ticket column, or ask Claude to show your positions first.

Account and overview

  • Show my account.
  • Show my open positions and pending orders.
  • Show today's closed positions.
  • Analyze my open positions. Which trades carry the highest risk, and why?
  • Which symbols can we trade?
  • Show the contract specification of XAUUSD: minimum lot, lot step and minimum stop distance.
  • Read the last terminal journal lines.

Charts and indicators

  • Open XAUUSD M5.
  • Work on the XAUUSD H1 chart that is already open; do not open a new one.
  • Add a Moving Average, period 20, to the XAUUSD chart.
  • Remove the Moving Average from the chart.
  • Show the last 50 H1 candles of XAUUSD and describe the trend.
  • What are the next important economic events for USD this week?

Trading on a demo account

  • Buy 0.01 XAUUSD, comment MCP demo.
  • For the position I just opened, set the stop loss 10 dollars below its open price and the take profit 10 dollars above.
  • Move the stop loss of position 12345678 to break-even.
  • Show my open positions with profit.
  • Close position 12345678.
  • Place a buy limit 0.01 XAUUSD 5 dollars below the current price, comment MCP demo.
  • Delete the buy limit order I just placed.

Building and testing a trading robot (optional; first open MetaEditor: in MetaTrader press F4)

  • Create a simple trading robot for XAUUSD: buy when the fast moving average crosses above the slow one, sell when it crosses below, 0.01 lots, with a stop loss and take profit.
  • Create a trend robot for XAUUSD with an EMA cross, an RSI filter, ATR-based stops, 0.01 lots and a daily loss limit.
  • Compile it.
  • Backtest it on XAUUSD H1 from 2025-10-01 to 2026-03-25.
  • Explain the result.
  • Try EMA 20/50 on H1 and H4 and compare.
  • Test the best one on the next six months.

A backtest shows how a robot would have done in the past. It is not a forecast.

A ten-minute test drive

  1. Show my account.
  2. Open XAUUSD M5.
  3. Add a Moving Average, period 20, to the XAUUSD chart.
  4. Buy 0.01 XAUUSD, comment MCP demo.
  5. For the position I just opened, set the stop loss 10 dollars below its open price and the take profit 10 dollars above.
  6. Show my open positions.
  7. Close the XAUUSD position.
  8. Show today's closed positions.
  9. Remove the Moving Average from the chart.

Gold moves quickly: a stop loss or take profit closer than a few dollars can close the trade before you reach step 7.

Five rules

  1. Demo first. Use a demo account until you are comfortable, and stay at 0.01 lot.
  2. Orders go to the account MetaTrader is logged into. On a demo account they are demo orders; on a real account they are real orders with real money.
  3. Claude acts only when you ask. It does not watch the market while you are away and it does not move stops by itself. For rules that must run around the clock, use a trading robot.
  4. Be explicit. Say the symbol, buy or sell, the lots, and the position number when you change or close something.
  5. Clean up. Close test positions, delete test pending orders and remove test indicators at the end of a session.

FAQ

Need help?

Contact CXM support with your account number and a screenshot of the last Journal lines (Toolbox → Journal). Never send your access keys.

Prepared by CXM for clients who use MetaTrader 5 and Claude Code on the same Windows computer. Trading involves risk. Use a demo account first.

Ready to Start Trading?

Got a cell phone, a tablet or a laptop? Build your strategy and manage your trading positions 24/7/365 wherever you may be. CXM makes trading easier for you with just a click on a button. Because trading never stops!

CXM trading app on mobile phone showing a XAUUSD gold candlestick chart