MT5 Expert Advisors: Build, Evaluate, Test, and Deploy
An MT5 Expert Advisor (EA) is an MQL5 program that can analyze market data and send trade requests through MetaTrader 5. Its behavior depends on its code, account permissions, broker specifications, and operating environment. Automation executes a policy; it does not demonstrate that the policy has an advantage.
A useful EA evaluation follows the same chain whether you buy or build it: specify the rules, inspect execution behavior, test with suitable data, and monitor the deployed version against those expectations.

Understand the Program and Account Model
An .ex5 extension identifies a compiled MQL5 program, not necessarily an EA; indicators and scripts also use it. An EA normally remains attached to a chart and handles events according to its implementation.
| Program responsibility | Questions to answer |
|---|---|
| Initialization | Are inputs valid, indicator handles available, and account requirements satisfied? |
| Signal calculation | Does it use completed bars, current prices, or multiple symbols? |
| Position management | Which symbol and strategy identifier does it own? What happens to manual trades? |
| Execution | How are rejection, partial fill, spread, stop distance, and volume constraints handled? |
| Recovery | Can it reconstruct positions and pending orders after a restart? |
OnTick receives new-tick events for the attached chart symbol. Events are processed sequentially; a new tick is not queued when a NewTick event is already queued or being processed. An EA therefore should not assume its handler observes every individual market tick. Timer and trade events have their own handlers; they are not simply extra calls between every pair of ticks.
MT5 supports netting and hedging account models. In netting, a symbol has one net position; in hedging, multiple positions can coexist. An EA written for one model can behave incorrectly on the other. Confirm the account mode before installation and include it in test records.
MT4 programs do not run unchanged as MT5 programs. A port requires review of indicator access, order/position handling, and other language or platform differences. Available instruments depend on the broker; neither a platform name nor an EA label guarantees access to an asset class.
Compare Strategy Risks Without Treating Labels as Results
| Approach | Rule to identify | Stress scenario |
|---|---|---|
| Trend following | How a trend starts and ends | Repeated reversals in a range |
| Mean reversion | Why and when a deviation is traded | A persistent move away from the assumed mean |
| Breakout | Which level and confirmation define entry | False breaks, gaps, and poor fills |
| Scalping | Expected gross movement and holding time | Spread, commission, latency, and execution rejection |
| Grid | Price spacing and maximum combined exposure | Multiple open positions during a one-way move |
| Martingale sizing | How size increases after losses | A loss sequence reaching the volume or margin limit |
| Machine learning | Training data, target, and update policy | Leakage, overfitting, and changed market conditions |
Grid placement and martingale sizing are different mechanisms; a grid need not double position size. Both still require an explicit exposure policy. A position-count cap limits one dimension of exposure but cannot by itself guarantee a maximum loss.
Evaluate an Existing EA
Ask for the exact version, settings, supported symbols, account modes, dependencies, license terms, and a complete test report. A third-party account record can help establish what happened in that account; it does not prove the same result is available with your broker, costs, or capital.
Separate balance from equity, inspect open losses, and check deposits or withdrawals before interpreting a growth chart. Examine whether a high win rate is supported by many small wins and occasional very large losses. If source is unavailable, document that limitation and test observable behavior instead of claiming a code audit.
A practical acceptance list includes duplicate signals, missing history, disconnected trading, rejected orders, terminal restart, spread expansion, and an existing position at startup. For each case, write the expected behavior before running the test. Fees and prop-firm restrictions must be checked against the specific current provider and account agreement.
Build an EA from an Explicit Specification
An illustrative research rule is: evaluate completed H1 bars, detect a 50/200 EMA upward crossover, and require RSI above 55. This is an unvalidated example. It still needs an entry price convention, exit rules, stop placement, sizing, and a policy for existing positions.
- Create an Expert Advisor project in MetaEditor and expose the settings that the specification actually needs.
- Validate inputs and create indicator handles during initialization. Stop initialization when a required dependency fails.
- Read the intended bars and check data availability. For a completed-bar strategy, compare the two most recent completed observations instead of treating a current-bar fluctuation as final.
- Separate signal decisions from sizing and trade requests. Log the inputs that produced each decision.
- Check symbol volume steps, minimum/maximum volume, tick size, stop constraints, and available margin.
- Interpret the trade server's return code and subsequent transactions. A successful OrderSend call does not by itself establish that an order has filled.
- Compile, review warnings, and test failure paths before optimizing parameters.
Pineify can assist with MQL5 code generation and compiler feedback. Its TradingView visual editor and Pine strategy workflow are separate from MT5 execution. Generated output still needs the same review and terminal tests. The MQL5 coding article includes a small observation-only example for understanding completed-bar calculations.
Select a Suitable Backtest and Holdout
MT5 distinguishes generated Every tick data from Every tick based on real ticks. Select a model appropriate to the strategy and inspect data availability. The official Strategy Tester documentation describes the available modes, forward testing, and execution-delay settings.
Record the symbol, broker history, dates, deposit, leverage, commission, spread behavior, modeling mode, and execution assumptions. Intrabar stops or pending orders can make a bar-open approximation unsuitable. Real tick data improves the historical representation but does not reproduce every live liquidity or execution condition.
Choose training and reserved evaluation periods before searching parameter combinations. Save the baseline, search ranges, optimization criterion, and all candidates considered. Compare neighboring parameters and different market regimes; selecting only the most profitable combination conceals the cost of the search.
A forward split in the tester is historical out-of-sample evaluation. A live demo test evaluates ongoing signals and terminal operation. Neither has a universal passing threshold such as three months, 100 trades, or a Sharpe ratio above one. Assess observation count, dependence between trades, costs, and drawdown alongside the objective set before testing.
Monte Carlo resampling explores outcomes under its sampling assumptions. It cannot create market regimes absent from the input data or prove a maximum possible loss. Keep its results separate from observed test results.
Deploy and Monitor the Same Version
Before deployment, save the executable, source when available, input set, terminal build, broker symbol settings, and test report. Check the EA's licensing and external-service requirements on the intended machine.
Measure CPU, memory, connection stability, and order-response behavior under the actual chart and symbol load. A fixed VPS specification or a particular ping is not sufficient evidence of execution suitability. Trading logic, broker processing, network conditions, and dependencies all matter.
When moving execution to a VPS, prevent an old terminal instance from independently opening duplicate trades. Confirm what migrates and what the hosting service supports; do not assume a virtual host duplicates arbitrary desktop dependencies. Monitor positions, equity, rejected requests, restart events, and the gap between intended and actual execution.
Capital requirements depend on contract size, minimum trade volume, stop distance, margin, and tolerable aggregate loss. There is no general “20 times historical drawdown” rule that makes an EA safe. Historical drawdown can be exceeded, and fixed-lot and equity-scaled strategies respond differently to changes in account size.
Extensions Need Separate Validation
Adding symbols or strategies changes shared margin and aggregate exposure. Correlations can change during stressed markets, so a collection of individually tested EAs still needs portfolio-level evaluation.
MetaQuotes documents a MetaTrader5 Python package for communicating with the terminal. That is different from an assumed built-in MQL5 function named PythonExecute(). External Python processing needs its own process, connection, error, and restart design. Do not treat a platform release or numerical library as proof that a particular model runs faster or trades better.
Can MT4 EAs run directly on MT5?
No. Port the logic to MQL5 and retest the indicator interface, account model, and execution behavior. Changing a file extension is insufficient.
Does Every tick mean the test uses real historical ticks?
No. MT5 has a separate Every tick based on real ticks mode. Record the selected model and check the history used.
How much capital does an EA need?
Evaluate minimum position size, contract specifications, stops, margin, and combined exposure. Historical drawdown alone cannot establish a safe capital amount.
Does passing a backtest justify increasing position size?
A backtest supports a result under stated historical assumptions. Scaling also changes exposure, margin requirements, and potentially execution. Define limits and assess those changes separately.
