AIQUANT.MY — XAUUSD EA Blueprint
← Back to free kit
AIQUANT.MY — Educational Resource

XAUUSD EA Blueprint

A structured guide to Expert Advisor architecture, backtesting, and risk management for Gold trading on MetaTrader 5.

Educational Disclaimer: This document is for educational purposes only. It does not constitute investment advice or a recommendation to trade. Past performance of any strategy is not indicative of future results. AI QUANT is not licensed by the Securities Commission Malaysia (SC) or Bank Negara Malaysia (BNM) to provide investment advice.

1. What is an Expert Advisor?

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.

2. Why XAUUSD (Gold) for Automation?

  • High liquidity: Gold is one of the most traded instruments globally. High liquidity means tighter spreads and smoother execution.
  • Trend tendencies: Gold tends to trend — up during risk-off periods, down during dollar strength. EAs that follow trends can find consistent conditions.
  • News sensitivity: Gold moves sharply on news events (Fed decisions, CPI, geopolitical events). EAs can be designed to avoid or exploit these windows.
  • Malaysian relevance: Malaysian retail traders widely use XAUUSD on MT5. Local broker support and MYR accounts make this the natural instrument for Malaysian EA learners.

3. The Anatomy of an EA

Every EA is built from four components:

① Inputs

Adjustable parameters — lot size, indicator periods, stop loss distance. These are the dials you turn when optimising an EA without changing the code.

② Entry Logic

The condition that triggers a trade. Example: "Enter BUY when the 20 EMA crosses above the 50 EMA." Clear, testable, repeatable rules.

③ Risk Management

Stop loss, take profit, maximum open positions, drawdown limits. The most important component — poor risk management destroys accounts faster than poor entry logic.

④ Exit Logic

When to close a trade. Can be a fixed TP/SL, a trailing stop, a time-based exit, or a signal reversal.

4. How to Read a Backtest Report

MT5's Strategy Tester generates a report after backtesting. Key metrics:

MetricWhat it meansTarget
Profit FactorGross profit ÷ gross loss> 1.5
Max DrawdownLargest peak-to-trough account loss< 20%
Win Rate% of trades that close in profitVaries by strategy
Expected PayoffAverage profit per trade> 0
Recovery FactorNet profit ÷ max drawdown> 3

⚠️ Backtest results are historical and do not guarantee future performance. Always forward-test on a demo account first.

5. Your First 30 Days: Learning Roadmap

1
Days 1–7
Understand the tools

Install MT5, open a demo account, load the starter EA template, run your first backtest.

2
Days 8–14
Study the starter code

Read every comment in the starter EA. Change one parameter at a time and re-run the backtest.

3
Days 15–21
Modify the entry logic

Try changing the EMA periods. Add an RSI filter. Each change is a lesson.

4
Days 22–30
Forward test on demo

Run your modified EA on a live demo account for 1–2 weeks. Compare to backtest results.

6. Glossary of EA Terms

EA / Expert Advisor
Automated trading program on MT5
MQL5
Programming language for MT5 EAs
Backtest
Running an EA on historical price data
Forward test
Running an EA on live demo data
Tick
A single price update from the broker
Spread
Difference between buy and sell price
Lot size
Volume of a trade (0.01 = micro lot)
Stop Loss (SL)
Price where a losing trade auto-closes
Take Profit (TP)
Price where a winning trade auto-closes
Drawdown
Decline from peak account balance
Profit Factor
Gross profit divided by gross loss
Magic Number
Unique ID to identify this EA's trades
OnTick()
MT5 function called on every price update
OnInit()
MT5 function called when EA first loads
EMA
Exponential Moving Average indicator

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.