How to Build an MT5 Expert Advisor Without Coding Using AI Tools

The old way to build an MT5 EA: hire a coder, spend weeks back-and-forth, pay hundreds of dollars, and end up with code you can't maintain. The new way: describe your strategy to an AI tool, get working MQL5 code in minutes, and iterate yourself. Here's the full process.

What You Need Before You Start

You do not need to know MQL5, C++, or any programming language. The AI tool handles the code. Your job is to describe the strategy clearly and review the backtest results critically.

Step 1: Define Your Strategy in Plain English

Before prompting any AI tool, write out your strategy in plain English. The more specific you are, the better the generated code will be.

Strategy definition template:

  • Instrument + timeframe: e.g. XAUUSD, H1 chart
  • Entry rule: e.g. Buy when the 20 EMA crosses above the 50 EMA and RSI is above 50
  • Exit rule: e.g. Take profit at 2× ATR, stop loss at 1× ATR from entry
  • Risk per trade: e.g. 1% of account balance

Step 2: Prompt an AI Tool to Write the MQL5 Code

Open your AI tool of choice (ChatGPT, Claude, etc.) and use this prompt structure:

Write a complete, compilable MQL5 Expert Advisor for MetaTrader 5 with the following rules:

- Instrument: XAUUSD, H1 timeframe

- Entry: Buy when 20 EMA crosses above 50 EMA and RSI(14) > 50. Sell when 20 EMA crosses below 50 EMA and RSI(14) < 50.

- Exit: Take profit = 2 × ATR(14) from entry. Stop loss = 1 × ATR(14) from entry.

- Risk: 1% of account balance per trade.

- Only one trade at a time (no pyramiding).

Include all necessary includes, handle trade execution with CTrade, and add input parameters for the indicator periods and risk percentage.

The AI tool will return complete MQL5 code. Copy all of it.

Step 3: Paste the Code into MetaEditor and Compile

  1. In MT5, press F4 to open MetaEditor
  2. Click File → New → Expert Advisor (template), give it a name
  3. Delete the default template code and paste in the AI-generated code
  4. Press F7 (or click Compile)
  5. If there are errors in the Errors tab, copy the exact error text and paste it back into the AI tool with: "This code gave the following compile error — please fix it: [error text]"
  6. Repeat until the Errors tab shows 0 errors

Step 4: Backtest in MT5 Strategy Tester

  1. In MT5, press Ctrl+R to open Strategy Tester
  2. Select your EA from the Expert dropdown
  3. Set Symbol to XAUUSD, timeframe to H1
  4. Set a date range (at least 2 years of data for meaningful results)
  5. Set Model to Every tick based on real ticks for most accurate results
  6. Click Start

Review these key metrics in the results: Profit Factor (aim for above 1.5), Maximum Drawdown (aim for below 20%), and Total Net Profit. If the results look wrong, describe the issue to the AI tool and ask it to fix the logic.

Step 5: Debug Errors with the AI Tool

Most first-generation EAs have bugs — the EA opens too many trades, the position sizing is wrong, or the entry logic fires at the wrong time. Fix these by describing the problem precisely:

"The EA is opening multiple trades in the same direction at once. I want only one position at a time. Here's the current code: [paste code]. Please fix this."

Be specific — "it's not working" produces poor fixes. "It opens 3 buy trades simultaneously instead of 1" produces accurate fixes.

Step 6: Deploy on Your XAUUSD Chart

  1. In MT5, open a XAUUSD H1 chart
  2. In the Navigator panel (Ctrl+N), find your EA under Expert Advisors
  3. Drag the EA onto the chart
  4. In the EA properties dialog, set your risk parameters (e.g. RiskPercent = 1.0)
  5. Ensure Allow Automated Trading is checked
  6. Click OK — the EA icon should appear in the top right corner of the chart (smiley face = running)
  7. Enable the AutoTrading button in the MT5 toolbar

Common Mistakes and How to Avoid Them

Frequently Asked Questions

Do I need to know MQL5 to build an MT5 EA?

No. AI tools like ChatGPT and Claude can generate complete, working MQL5 code from a plain English description of your strategy. You describe what you want — entry rules, exit rules, risk settings — and the AI writes the code. You then paste it into MetaEditor, compile it, and run it in MT5.

Which AI tool is best for building MT5 EAs?

ChatGPT (GPT-4o or above) and Claude (Sonnet or above) both produce reliable MQL5 code when given a well-structured prompt. The quality depends more on your prompt than on the specific AI tool. Follow the 4-part framework: instrument + timeframe + entry/exit rules + risk rule.

What if the AI-generated code has errors?

Copy the exact error message from MetaEditor and paste it back into the AI tool. Ask it to fix the error. This debugging loop — generate, compile, fix errors — typically takes 2-5 iterations for a simple EA. More complex EAs may require more rounds.

Can I build a profitable EA this way?

The AI tool writes code that matches your strategy description — it does not create a profitable strategy for you. Profitability depends on the logic of your strategy, how well it's backtested, and whether it performs in live market conditions. Always backtest thoroughly and use strict risk management.

Do I need a VPS to run an MT5 EA?

For consistent 24/5 operation, a VPS (Virtual Private Server) is recommended so your EA runs even when your PC is off. Many MT5 brokers offer free VPS hosting for accounts above a minimum balance. Alternatively, you can run MT5 on your PC during market hours.

Trading involves significant risk of loss. AI QUANT is an educational platform and does not provide licensed investment advice. Past performance does not guarantee future results. Only trade with funds you can afford to lose. For regulatory guidance, refer to the Securities Commission Malaysia and Bank Negara Malaysia.

Want to build your first EA with live guidance?

AI QUANT VIP Members get monthly live sessions where we build EAs and indicators using AI tools — step by step, with live Q&A.