Skip to content
MQL Labs
MetaTrader 5

How to automate a MetaTrader 5 strategy with MQL5

Prepare your MT5 Expert Advisor specification, from signals and position handling to Strategy Tester and demo acceptance checks.

MQL LabsUpdated 2 min read

To automate a strategy in MetaTrader 5, start by writing down the rules you currently interpret on the chart. The first beta should let you compare specific Expert Advisor decisions with your expected behavior.

Specify the signal with an example

A “bullish crossover” might mean the fast moving average moves from below the slow moving average to above it across two consecutive closed bars. It might also be evaluated while a bar is still forming. Specify the applied price, periods, timeframe and exact evaluation event.

Include one example that should trade and a similar example that should be skipped. Document any session, spread or position-state restrictions that are part of the rule.

Document order and position handling

Specify whether the EA should open additional positions, close an existing position or ignore a new signal. Netting and hedging accounts can handle trades on the same symbol differently. Identify your target account type and define the expected behavior if it changes.

For a migration from MT4, keep reproducible examples from the original version. Compare decisions and position behavior before comparing aggregate statistics.

Verify behavior in historical and demo runs

In the Strategy Tester, record the period, symbol, inputs and modeling mode. Use visual mode and the EA’s logs to compare individual decisions against the brief. Give particular attention to the modeling mode if your logic depends on intrabar price movements.

Then test startup, reconnects, volume constraints and broker errors in a demo account. Track these acceptance cases separately from historical strategy metrics.

The official MetaTrader 5 strategy testing documentation explains modeling and simulation options.

/ CUSTOM DEVELOPMENT

MQL5 Development for MetaTrader 5

Explore the service

Keep reading