Study ›
[Course] [Build an EA 9] Writing EA code with AI (ChatGPT, Claude)
Today you can describe an EA in plain words and AI will write MQL5 for you — no coding needed. But you have to ask well to get usable code, and you must verify it.
1. Request template (copy and fill in)
Write an MQL5 EA for MT5.
- Symbol/timeframe: XAUUSD, M15
- Buy: (e.g.) on the just-closed candle, 20 EMA crosses above 50 EMA
- Sell: (e.g.) on the just-closed candle, 20 EMA crosses below 50 EMA
- Stop loss: $30 from entry / take profit: $60
- Size: lose only 1% of equity at the stop (respect broker min lot and step)
- One position at a time; manage only my orders by magic number
- Decide only when a new candle opens
- All settings as inputs
- Use CTrade, comments in EnglishFilling in the 7-item rule checklist from part 3 makes results much better.
2. When there are errors
- After F7, copy the message from the Errors tab exactly and paste it with "I get this error."
- If one round doesn't fix it, give the full code plus the error.
- AI often mixes in MQL4 (old MT4) syntax. Pin it down: "MQL5 only, use CTrade instead of OrderSend."
3. Verify AI code like this
AI confidently writes plausible but wrong code. Always check these yourself.
- Do all orders get a stop and a target?
- Is the lot calculation correct for the 1% rule? (check the first trade's size in the Strategy Tester)
- Does "sit out if a position is open" actually work? (no overlapping positions in the backtest trade list)
- Backtest 2+ years, as in part 6
4. Requests to avoid
- "Build an EA that always profits" → AI doesn't know either. You have to define the rules.
- "An EA with a 90% win rate" → usually no stop or martingale (see part 8).
- "Copy this EA someone sells" → possible copyright issues, and the core logic usually isn't public anyway.
5. Next steps
An AI-built EA follows the same path: backtest → demo → small live → publish with EADesk live linking. As your record builds up, compare it with other members on Verified strategies.
That's the end of the series. Post your EA on Verified strategies or ask in Q&A where you get stuck. We're planning more examples next, like RSI and breakout strategies.
