MT5 Algorithmic Trading: Set Up, Backtest and Validate EAs

MT5 algorithmic trading means letting an Expert Advisor (EA), a program attached to a chart, analyze prices and place trades for you under rules you define. You can start in an afternoon: enable automated trading, attach an EA, backtest it in the Strategy Tester, then forward test it on a demo account before it touches live money. This guide walks through each step and the mistakes that make a backtest look better than reality.
TL;DR
- An EA is the MT5 program type that can trade automatically. Scripts run once, and custom indicators only analyze.
- To run one, attach it to a chart from the Navigator and make sure automated trading is allowed in both the EA settings and the platform options.
- Open the Strategy Tester with Ctrl+R, choose realistic modeling, and always include real spreads and commission.
- Read drawdown, sample size and data quality before net profit.
- Forward test on demo before going live, because no backtest reproduces future execution.
Table of Contents
- What algorithmic trading in MT5 actually is
- Setting up MT5 algo trading step by step
- Backtesting an EA in the MT5 Strategy Tester
- Reading the report without fooling yourself
- Optimization and forward testing
- Validate on demo, then go live small
- Trade your tested EA with us
- FAQ
- Sources
What algorithmic trading in MT5 actually is
According to the MetaTrader 5 Help, automated trading is making buy and sell operations in the financial markets with trading robots, which the platform calls Expert Advisors. The robot analyzes prices against preset algorithms, makes decisions and executes the trades.
The appeal is practical. The MQL5 Reference points out that a robot can work around the clock, every day of the week, and does not get tired, doubtful or scared. The catch is that you must formalize your rules clearly enough for code to follow them. A vague idea such as “buy when momentum looks strong” cannot be automated until you define what “strong” means in numbers.
Four kinds of MT5 programs
The MQL5 documentation separates the program types, and knowing the difference saves confusion:
| Program type | What it does | Can it trade? |
|---|---|---|
| Expert Advisor | Attached to a chart, reacts to events such as new ticks, timers and Depth of Market changes | Yes |
| Script | Runs a single action once | Yes |
| Custom indicator | Analytical calculations and chart drawing | No |
| Service | Background program not tied to a chart | Not as an EA |
The Trade Permission page of the same reference states that trading functions work only in Expert Advisors and scripts, not in indicators. If you want continuous automation, you want an EA.
Setting up MT5 algo trading step by step
1. Get the platform and a demo account
Install MetaTrader 5 and log in to a demo account first. Everything below works the same on demo, and that is where you should practice. Our trading platforms page explains how MetaTrader 5 is offered with us, including advanced charting and algorithmic trading support.
2. Choose or build an EA
You have three realistic routes:
- Use the MQL5 Wizard. The MetaTrader 5 Help on creating EAs says the Wizard lets a trader without programming skills assemble an EA by choosing trading signals, money management and trailing stop modules, with the code generated automatically.
- Write MQL5 yourself in MetaEditor. MetaEditor has code highlighting, a step-by-step debugger and profiling tools, plus a free code base of automated trading programs.
- Ask an AI assistant to draft the code. One tested example on the MQL5 community blog found that ChatGPT produced structurally valid MQL5 most of the time, but the author’s conclusion was that profitability depends on the strategy you specify, not on the coding. Treat AI as a scaffolding tool, then review and test every line.
The EA file lives in the Experts folder of your MQL5 directory, which is where the Navigator reads it from.
3. Attach it to a chart
Per the MetaTrader 5 Help, you double-click the EA in the Navigator or drag it onto a chart, then confirm in the Properties window. If it started correctly, its name and an icon appear in the upper right corner of the chart.
4. Allow automated trading
If that icon is red, the EA is not allowed to trade. The same help page says to enable automated trading both in the EA settings and in the platform options. The Standard toolbar also has a switch that allows or forbids automated trading for all programs at once.
One more thing to know: the Trade Permission reference notes that automated trading can also be disabled on the server side. If it is disabled for a trading account, EA orders are not executed no matter what your terminal says. Check that your account type supports it before you blame your code.
Backtesting an EA in the MT5 Strategy Tester
Open the tester from View > Strategy Tester or press Ctrl+R. The settings you will meet are Expert, Symbol, Timeframe, Date, Forward, Delays, Modeling, Deposit, Leverage and Optimization, as laid out in this Strategy Tester walkthrough. Pick them, click Start, and read the report.

The tester is its own engine, not a replay of your live terminal. According to a 2026 backtesting guide, it runs a separate copy of the compiled EA on its own historical tick stream in a sandbox. The first run for a symbol and timeframe has to download history, which can take several minutes.
Pick the right modeling mode
This one setting changes your results more than most traders expect. The MQL5 Reference describes three tick generation modes: every tick, 1 minute OHLC and open prices only. The same 2026 guide adds a fourth that matters most for accuracy:
| Mode | How it works | When to use it |
|---|---|---|
| Every tick based on real ticks | Uses actually recorded tick history | Final validation, especially for scalping and tight stops. Slowest |
| Every tick | Interpolates ticks from M1 bars | Reasonable first pass, but synthetic |
| OHLC 1 minute | Uses only open, high, low and close of each M1 bar | Fast screening of slower strategies |
| Open prices only | Fastest, least realistic | Sanity-checking that the EA initializes and trades |
The same guide warns that synthetic every-tick runs can overstate a scalping EA’s profit factor. If your strategy lives on small price moves, use real ticks for the run you actually trust.
Put real costs into the test
The most common backtesting mistake is leaving costs out. A 2026 guide to reading MT5 reports warns that zero spread and no commission can turn a losing strategy into a winning one on paper. Set spread and commission to what you will really pay.
This is where your account’s published costs matter. Our accounts page lists a commission of $7 per lot alongside a 1.0 pip markup, and you can plug whichever applies to your account type into your test. A strategy with a small average win per trade is the most sensitive to this, so run it with and without costs to see how much of its edge they absorb.

Choose a sensible date range and deposit
Cover more than one market regime: a trending stretch, a ranging one and at least one volatile period. Use a starting deposit that matches what you will actually fund, because position sizing and drawdown percentages depend on it. Test on a symbol and server that resemble your live conditions.
Reading the report without fooling yourself
Net profit is the least informative number on the page. Read in this order:
- Data quality. The official Testing Report help explains that History Quality flags gaps and incorrect data, shown on a color-coded bar where lighter green is better and red marks intervals below 50% quality. A perfect-looking result on poor data means little.
- Sample size. Total trades tell you whether the result could be luck. A handful of trades proves nothing. One practitioner guide suggests 500 or more trades across several years as a working target.
- Drawdown. Ask whether you could sit through the worst equity dip without switching the EA off. Look at it in both percent and money.
- Edge. Profit factor, expected payoff and recovery factor. The MetaTrader help says recovery factor reflects how much money was risked to earn the profit obtained.
- Structure. Largest loss, average win versus average loss and losing streaks.
On the Sharpe ratio, the official help defines it as return minus the risk-free rate, divided by the standard deviation of return, with the risk-free rate assumed to be zero in the tester. Use it to compare your own runs with each other, not as a verdict.
A suspiciously smooth equity curve is a warning, not a prize. Very high profit factors usually point to over-optimization: parameters tuned so tightly to past data that they describe noise. Treat 100% modeling quality the same way. It means the history was complete and consistent, not that the strategy will work live.
Optimization and forward testing
The tester can run through ranges of input values to find the best combination. That is useful and also dangerous, because the best past combination is often the most overfitted one. Two habits help:
- Reserve out-of-sample data. The Forward setting splits the period so optimization runs on the first part and the chosen settings are tested on the second. One tester guide advises not to keep re-optimizing after you have seen the forward result.
- Test for fragility. Repeat the run with different start dates, plausible spreads and input values near your chosen ones. If a small change flips the result from profit to loss, the edge was not robust.
Validate on demo, then go live small
A backtest tells you how rules would have behaved on history. A demo forward test tells you how the EA behaves with live prices, your connection and real-time order handling. Run it for several weeks, long enough to cover a spread of normal days and at least some news events, then compare behavior with the backtest. You are looking for the same character, not identical numbers.
Why the gap exists is well illustrated by the MQL5 blog test mentioned earlier. The author’s live run on a small account did worse than the backtest, and the causes were practical: live spread was wider than assumed, stops filled worse than specified around a weekend gap, a news release caused slippage, and the broker’s symbol suffix was not handled. Each of those is something you can prepare for:
- Use the real spread and commission in testing.
- Add a news filter or a rule against holding through weekend gaps.
- Make symbol names configurable in your EA.
- Be most careful with tight-stop styles like scalping or grid systems, which depend on precise fill prices that a zero-slippage backtest ignores.
Even a good demo period does not guarantee future results. Simulated and hypothetical tests benefit from hindsight and cannot capture every future spread, gap or outage. When you move to a live account, start with the smallest size you can and scale only after live behavior matches what you saw in testing. Only trade money you can afford to lose.
Our view: execution is part of the strategy
Most advice on EAs focuses on code and settings. We think the layer underneath deserves equal attention, because an algorithm only sees the prices it is given and only gets the fills it is offered. A strategy that wins by a few pips per trade lives or dies on spread, commission and how fast the order reaches the market.
That is why we built MitraNet™, our proprietary technology designed for execution under 30 milliseconds with direct access to Tier-1 liquidity. Our aim is to give retail traders, scalpers and algorithmic traders conditions that are usually reserved for professionals, together with MetaTrader 5 compatibility, advanced charting and algorithmic trading support.
We also believe costs should be visible so you can model them honestly. Our commission and markup are published, there is no minimum deposit, and deposits are instant. When your backtest uses the real numbers, the result you see is much closer to the result you trade.
Partners
Trade your tested EA with us
Once your EA has passed backtesting and a demo forward test, you need an account that supports the way it trades. We offer Edge and Standard accounts for forex, commodities, indices and crypto CFDs, MetaTrader 5 access, instant deposits and withdrawals, no minimum deposit and a rewards program based on trading volume.

Compare account types and published costs on our accounts page, or see which markets you can trade. If you are still deciding between platforms, our comparison of MT5 and cTrader covers the differences.
FAQ
Can I trade automatically in MT5?
Yes. MT5 is built for it: you attach an Expert Advisor to a chart and it can analyze prices and send orders to the trading server by itself. Automated trading must be allowed in the EA settings and in the platform options, and it must not be disabled for your account on the server side.
Can ChatGPT write a trading algorithm for MT5?
It can draft MQL5 code that compiles and follows a clear specification, and it can fix errors when you give it specific feedback. It cannot tell you whether your strategy is profitable or anticipate live-account edge cases you did not describe. Backtest and demo test the result like any other EA.
What is the difference between an EA, a script and an indicator?
An EA stays attached to a chart and reacts to events such as new ticks, so it can manage trading continuously. A script performs a single action once. A custom indicator only analyzes and draws, and cannot trade.
Which Strategy Tester modeling mode should I use?
Use open prices only or 1 minute OHLC for quick screening, and every tick based on real ticks for the final test, especially if your EA scalps or uses tight stops. Real ticks are slower but are the closest the tester gets to live conditions.
How long should I forward test before going live?
There is no official number, but several weeks on demo, covering ordinary days and news events, gives you a useful comparison with your backtest. Judge whether behavior is similar rather than expecting identical results, and start live with small size.
Sources
- Algorithmic Trading, Trading Robots - MetaTrader 5 Help
- Testing Trading Strategies - MQL5 Reference
- MQL5 Reference
- Trade Permission - MQL5 Reference
- How to Create an Expert Advisor or an Indicator - MetaTrader 5 Help
- Expert Advisors and Custom Indicators - MetaTrader 5 Help
- Testing Report - MetaTrader 5 Help
- Can ChatGPT Actually Write an MT5 EA? - MQL5 blog
- How to Use Strategy Tester in MT5 to Backtest EAs
- How to Backtest an EA in MT5: Strategy Tester Guide 2026
- How to Read MT5 Backtesting Reports
- How to Backtest Forex in MT5
- MT5 Strategy Tester Guide for EA Backtesting
- Why Your EA’s Backtest Doesn’t Match Live Results