Ready to go further
Next: how the spread eats an edge
See how fixed and live spreads change a result.
What is included
- What it is, in plain words
- The formula or mechanism, with exact arithmetic
- How it hits grid, martingale and DCA bots
- A check you can run before you switch a bot on
Who it is for
- People who run or plan to run a trading bot
- Anyone reading a backtest or a bot sales page
- Readers who want the numbers, not the pitch
- Not advice, and not a signal service
Key facts
- MQL5 is a platform where a bot or strategy is written, tested and run. This page explains the general method, not the product's current features.
- A bot is only as trustworthy as its test. Before relying on any result here, check costs, fills, data and timing, and keep a stretch of data the rule never saw.
- The worked example on this page uses made-up numbers, checked in node on 31 Oct 2026. It shows the arithmetic, not how any product performs.
- Prices, fees, markets, versions, limits and supported languages change and belong to the vendor. We state none of them. Check the vendor's current pages.
- Start on a simulated account, keep stops where they still work if the bot stops, and move to real money only in very small steps, if at all.
What it is
MQL5 is the programming language of the MetaTrader 5 platform. Its general style resembles C++. A program written in it that trades automatically is called an expert advisor, or EA, and it runs inside the platform attached to a chart. The same family also includes scripts, which run once, and custom indicators, which draw.
MetaTrader 5 also includes a Strategy Tester that replays history through your EA. The platform, the broker's server and the language are separate things: the broker decides which instruments, spreads and contract sizes your account has, and the vendor and broker decide the terms. Check both for current details. For the general idea of an EA see expert advisor. This page explains how it works in general terms. We have not tested it for this page. Check the vendor's current terms.
How a bot connects here
The connection style is built-in scripting, with the platform acting as the bridge to the broker's server. The EA runs on the machine where the platform runs, as long as the platform is open and connected.
- Event handlers. An EA reacts to events such as a new tick, a timer or a trade update. Your code decides what to do in each.
- Trade functions. The code sends order requests to the broker and must check the result code of each. An unchecked request that failed looks like a trade that never happened.
- Inputs. EAs expose settings the tester can vary. Every one you vary adds to the optimization problem.
- Machine on. It stops if the computer sleeps or the platform closes. Many people use a hosted always-on computer. See forex VPS.
Worked example: the spread the tester used
The tester can use a fixed spread or the spread recorded in the data, depending on mode and data quality, so read which one your run used. Take a made-up bot that makes 3.0 pips per trade before the spread, over 200 trades, on 0.10 lot of a pair where a pip is worth $1.00 at that size. The spread is paid on every trade. Numbers are made up and checked in node.
| Spread assumption | Gross pips | Spread pips | Net pips | Net per trade | 200 trades |
|---|---|---|---|---|---|
| Fixed spread of 1.0 pip in the test | 3.0 | 1.0 | 2.0 | $2.00 | $400 |
| Average live spread of 2.2 pips | 3.0 | 2.2 | 0.8 | $0.80 | $160 |
| Wide spread of 3.0 pips | 3.0 | 3.0 | 0.0 | $0.00 | $0 |
At a fixed 1.0 pip the bot nets $2.00 a trade and $400 over 200 trades. At 2.2 pips it nets $0.80 and $160. At 3.0 pips it nets nothing. Short-term bots are the most sensitive, because their gross edge per trade is small next to the spread. Spreads also widen around news and at rollover, so an average hides the worst moments. Compare the tester's spread with the spread your account actually shows. See spread and the MT5 strategy tester.
What to verify before trusting a backtest here
These checks apply to any platform of this kind. The answers come from the vendor's current documentation and from your own tests, not from this page.
| Check | Why it matters |
|---|---|
| Tester mode | Modes range from fast approximations to one that replays every tick. A faster mode can be wrong for short-term logic. |
| Quality of the history | Check how the data was built and its coverage. |
| Spread, commission and slippage | Enter costs that match your account. |
| Lot size and contract specification | Pip value, minimum lot and step come from your broker, not from this page. |
| Result codes handled in the code | The EA should check every order request result and log failures. |
| Out of sample and forward test | See forward testing and walk forward testing. |
How bots break on this kind of platform
- Spread widening. A rule built on small moves stops paying.
- Rejected or requoted orders. The code assumed success.
- Platform closed or disconnected. The EA stops with positions open.
- Optimization on many inputs. A rule fitted to the past. See overfitting.
- Broker differences. The same EA behaves differently on another account because the contract details differ.
A safe order of work
Backtest with honest costs, forward test on new data, run on a simulated account for weeks, then trade a very small size and compare each step with the one before. See forward testing and paper trading.
What this page does not tell you
It does not tell you whether the product is suitable, what it costs, or how it behaves today. Those change and belong to the vendor. It does not give a strategy to trade. This page explains how it works in general terms. We have not tested it for this page. Check the vendor's current terms.
Keep Going
Related Tools and Guides
Keep exploring
FAQ
Frequently Asked Questions
What is MQL5 used for?
Writing programs for MetaTrader 5: expert advisors that trade, indicators that draw, and scripts that run once.
Is an MQL5 backtest the same as live trading?
No. The tester replays history with its own spread, fill and data assumptions. Live trading has real delays, widening spreads and rejected orders.
Does a good MQL5 backtest mean a bot will make money?
No. A backtest shows how a rule behaved on past data under its assumptions. Costs, fills, data and luck can all make live results different.
Should I test on a simulated account before real money?
Yes, as a general practice. A simulated account tests your code and your plumbing. Its fills are usually kinder than real ones, so it does not prove a rule works.
Have you tested MQL5?
No. This page explains how it works in general terms and we have not tested it for this page. Check the vendor's current terms.
Are the numbers on this page real?
Example numbers are made up to show how the maths works, and the page says so. A figure only counts as exact when the page says it was calculated on a stated date. Nothing you enter in a calculator leaves your browser.
Can I use this to decide whether to run a bot?
It can show whether a bot's numbers hold together and how much an account can lose. It cannot say what the market will do, and it is not advice. Use it to ask better questions, then read the terms of your own broker or exchange.
Is this financial advice?
No. It is general education. The numbers are made up and it does not consider your situation.
Know the Risk Before You Run It
Free calculators and guides, added every week. Leave your details and we will email you when new ones go up.
Trading carries a risk of loss