What Are Expert Advisors?
Expert Advisors (EAs) are automated trading programs that run inside MetaTrader 5. They analyze price data, apply trading rules, and execute buy and sell orders without human intervention. Think of an EA as a set of if/then rules coded into a program that the platform executes on every new price tick.
EAs can range from simple scripts that place one trade based on a moving average crossover to complex multi-strategy systems that manage dozens of positions across multiple instruments simultaneously. The underlying programming language for MT5 EAs is MQL5, a C++-like language specifically designed for trading applications.
The appeal of Expert Advisors is clear: they remove emotions from trading, execute faster than any human, and can monitor markets 24 hours a day. The challenge is equally clear — building an EA that is genuinely profitable over the long term requires deep understanding of both markets and programming.
How EAs Work on MT5
When you attach an EA to a chart in MT5, the platform calls the EA's code on every new tick (price update) for that instrument. The EA's logic decides whether to open, modify, or close trades. Here is the basic flow:
- MT5 receives a new price tick from the broker's server
- The platform calls the EA's
OnTick()function - The EA reads current prices, indicator values, and account information
- Based on its rules, the EA may send trade requests (open, modify, close)
- MT5 sends the trade request to the broker's server
- The broker executes (or rejects) the order
- The cycle repeats on the next tick
MT5 EAs have access to rich data: historical prices, all built-in and custom indicators, account balance and margin information, the economic calendar, and even other open charts. This makes MT5 EAs significantly more powerful than their MT4 counterparts.
Where to Find Expert Advisors
There are several sources for MT5 Expert Advisors, each with different quality and risk profiles:
MQL5 Market
The official marketplace built into MT5. Access it via the Navigator panel > Market tab, or through the MQL5 website. The MQL5 Market offers both free and paid EAs. Paid EAs range from $30 to $5,000+. Every EA on the market includes backtesting results and user reviews.
MQL5 Code Base
A free repository of open-source EAs, indicators, and scripts. The code quality varies widely, but it is an excellent learning resource. You can study how experienced developers structure their EAs and adapt the code for your own strategies.
Freelance Developers
If you have a specific strategy but lack programming skills, the MQL5 Freelance section connects you with developers who will code your EA for a fee. Typical costs range from $100-$500 for a simple EA to $1,000+ for complex systems.
Third-Party Websites
Numerous websites sell or give away EAs. Exercise extreme caution here. Many third-party EAs are scams, use manipulated backtests, or contain harmful code. If you download an EA from outside the MQL5 ecosystem, never run it on a live account without thorough testing.
Installing an EA on MT5
Installing an Expert Advisor on MT5 is straightforward:
From MQL5 Market (Automatic)
- Open the Market tab in the Navigator panel
- Browse or search for your desired EA
- Click "Download" (free) or "Buy" (paid)
- The EA appears automatically in your Navigator > Expert Advisors folder
Manual Installation (File-Based)
- Download the EA file (.ex5 for compiled, .mq5 for source code)
- In MT5, go to File > Open Data Folder
- Navigate to
MQL5\Experts - Copy the .ex5 file into this folder
- Restart MT5 or right-click in the Navigator and select "Refresh"
- The EA appears in Navigator > Expert Advisors
Configuring EA Parameters
After installing, attach the EA to a chart by dragging it from the Navigator. A configuration dialog appears with three tabs:
Common Tab
Critical settings here include:
- Allow Algo Trading: Must be checked for the EA to place trades
- Allow DLL Imports: Only enable if the EA specifically requires it (some EAs use external libraries). Enabling DLL imports for untrusted EAs is a security risk.
Inputs Tab
This is where you configure the EA's trading parameters. Common inputs include lot size, stop loss distance, take profit distance, indicator periods, trading hours, and maximum spread. Every EA has different inputs depending on its strategy.
Before Running Live
Enable the "AutoTrading" button in the main toolbar (it should be green, not red). Also ensure your broker allows automated trading — some brokers restrict EA usage on certain account types.
Best Broker for EAs
Exness supports all Expert Advisors with no restrictions, offers raw spread accounts from 0.0 pips, and provides free VPS for qualifying traders.
Open Exness Account →Backtesting with the Strategy Tester
Never run an EA on a live account without backtesting first. MT5's Strategy Tester is one of the most powerful backtesting engines available to retail traders. For a dedicated deep-dive, see our backtesting guide.
Setting Up a Backtest
- Open the Strategy Tester via View > Strategy Tester (or Ctrl+R)
- Select your EA from the dropdown
- Choose the symbol (e.g., EURUSD) and timeframe (e.g., H1)
- Set the date range (at least 2-3 years of data for meaningful results)
- Select the modeling mode: "Every tick based on real ticks" gives the most accurate results
- Set the initial deposit and leverage
- Click "Start"
Interpreting Results
Key metrics to evaluate in the backtest report:
| Metric | What It Means | Good Value |
|---|---|---|
| Net Profit | Total profit minus total loss | Positive (obviously) |
| Profit Factor | Gross profit / Gross loss | Above 1.5 |
| Max Drawdown | Largest peak-to-trough decline | Below 20-25% |
| Sharpe Ratio | Risk-adjusted return | Above 1.0 |
| Recovery Factor | Net profit / Max drawdown | Above 3.0 |
| Total Trades | Sample size | 200+ for statistical significance |
Optimization and Overfitting
MT5's Strategy Tester includes a genetic optimizer that finds the best combination of EA parameters by testing thousands of variations. While optimization is powerful, it carries a serious risk: overfitting.
Overfitting occurs when an EA is tuned so precisely to historical data that it performs brilliantly in backtests but fails on new data. To avoid this:
- Use out-of-sample testing: Optimize on 70% of your data (in-sample) and validate on the remaining 30% (out-of-sample). If performance drops sharply on out-of-sample data, the EA is overfit.
- Keep parameters minimal: An EA with 3-5 adjustable parameters is far less likely to be overfit than one with 20+ parameters.
- Test across multiple symbols: A robust strategy should work (even if less profitably) across related instruments.
- Forward test on demo: After backtesting and optimization, run the EA on a demo account for at least 1-3 months before going live.
Deploying an EA Live
When you are confident in your EA's performance after backtesting, optimization, and forward testing, follow these steps for live deployment:
- Ensure your live account has sufficient margin for the EA's position sizing
- Start with the smallest lot size your EA supports
- Attach the EA to the correct chart (same symbol and timeframe as your backtests)
- Monitor closely for the first 1-2 weeks, comparing live results to backtest expectations
- Gradually increase lot sizes only after consistent live performance
The jump from backtest to live is the most dangerous moment in EA trading. Slippage, spread widening during news, and requotes create friction that backtests do not capture. Always start small.
VPS for 24/7 Operation
Expert Advisors only run while MT5 is open and connected. If your computer sleeps, loses internet, or crashes, the EA stops working — potentially leaving open positions unmanaged. The solution is a VPS (Virtual Private Server).
A VPS is a remote server that runs MT5 continuously. Options include:
- MQL5 Cloud VPS: Built into MT5, one-click deployment. Costs from $10-15/month. Located near major broker servers for minimal latency.
- Broker-provided VPS: Many brokers like Exness and XM offer free VPS hosting if you maintain a minimum balance or trading volume.
- Third-party VPS: Services like ForexVPS.net, AccuWeb, or any cloud provider (AWS, DigitalOcean). More control but requires manual setup.
For a detailed comparison of VPS options, check our VPS hosting guide.
Building Your Own EA
If you have programming experience (or want to learn), building your own EA gives you complete control over your trading logic. MT5 uses MQL5, a C++-like language with built-in functions for market data, trading operations, and technical indicators.
The basic structure of an MQL5 Expert Advisor:
// EA initialization
int OnInit() {
// Set up indicators, validate inputs
return(INIT_SUCCEEDED);
}
// Called on every new tick
void OnTick() {
// Check entry/exit conditions
// Place, modify, or close trades
}
// EA removal cleanup
void OnDeinit(const int reason) {
// Release resources
}
The MQL5 IDE (MetaEditor) is built into MT5 and includes code completion, debugging tools, and extensive documentation. For a deeper introduction, see our MQL5 programming basics guide.
Run Your EAs on the Best Infrastructure
XM offers free VPS hosting for active traders and supports all Expert Advisors with no restrictions on trading strategies.
Open XM MT5 Account →