A structured guide to Expert Advisor architecture, backtesting, and risk management for Gold trading on MetaTrader 5.
An Expert Advisor (EA) is a program written in MQL5 that runs inside MetaTrader 5 and automates trading decisions. Instead of sitting in front of charts and clicking buy/sell manually, an EA follows a set of rules you define — checking price conditions, managing positions, and executing trades automatically.
An EA does not think for itself. It only does exactly what its code says. The quality of an EA is entirely determined by the quality of the strategy and risk management rules built into it — which is exactly what this education platform teaches you to build.
Every EA is built from four components:
Adjustable parameters — lot size, indicator periods, stop loss distance. These are the dials you turn when optimising an EA without changing the code.
The condition that triggers a trade. Example: "Enter BUY when the 20 EMA crosses above the 50 EMA." Clear, testable, repeatable rules.
Stop loss, take profit, maximum open positions, drawdown limits. The most important component — poor risk management destroys accounts faster than poor entry logic.
When to close a trade. Can be a fixed TP/SL, a trailing stop, a time-based exit, or a signal reversal.
MT5's Strategy Tester generates a report after backtesting. Key metrics:
| Metric | What it means | Target |
|---|---|---|
| Profit Factor | Gross profit ÷ gross loss | > 1.5 |
| Max Drawdown | Largest peak-to-trough account loss | < 20% |
| Win Rate | % of trades that close in profit | Varies by strategy |
| Expected Payoff | Average profit per trade | > 0 |
| Recovery Factor | Net profit ÷ max drawdown | > 3 |
⚠️ Backtest results are historical and do not guarantee future performance. Always forward-test on a demo account first.
Install MT5, open a demo account, load the starter EA template, run your first backtest.
Read every comment in the starter EA. Change one parameter at a time and re-run the backtest.
Try changing the EMA periods. Add an RSI filter. Each change is a lesson.
Run your modified EA on a live demo account for 1–2 weeks. Compare to backtest results.
AI QUANT · aiquant.my · Education Platform Only
This document is for educational purposes only. It does not constitute investment advice, a recommendation to trade, or a promise of financial returns. AI QUANT is not licensed by the Securities Commission Malaysia (SC) or Bank Negara Malaysia (BNM) to provide investment advice or manage funds. Past performance is not indicative of future results. Trading involves significant risk of loss.