Home · Learn · Running expert advisors
Advanced

Running expert advisors

Installing an EA, choosing settings, and testing it properly before it sees real money.

8Lessons
70 minReading time
FreeNo account needed
0%Your progress
Lesson 01

What an EA can and cannot do

An expert advisor is a program attached to one chart that receives every tick and may place, modify and close orders. It executes rules faster and more consistently than you can, it does not get bored, and it does not widen a stop because it feels sure.

It cannot know anything you did not tell it. It has no view on whether today is unusual, it will trade a thin holiday session exactly as it trades a normal Tuesday, and it will keep doing that while the account drains unless a rule you wrote stops it.

Judge an EA on whether its rules describe something real about the market, not on the equity curve in its advertisement. Any curve can be produced by fitting to the past.

Take away

An EA is consistency, not judgement. It will follow a bad rule perfectly.

Lesson 02

Installing an EA in MetaTrader 5

Use File → Open Data Folder in the terminal, never a path you guessed. Put the .mq5 source in MQL5/Experts and any included headers in MQL5/Include. Compile in MetaEditor; a successful compile writes a .ex5 next to the source.

If the EA does not appear in the Navigator, the usual cause is that the compiled file landed in a different data folder than the terminal you are looking at — portable installations and multiple terminals make this common. Right-click Navigator and choose Refresh before assuming anything is broken.

Then: drag onto a chart, tick Allow Algo Trading in the dialogue, and check the Algo Trading button in the toolbar is green. A smiley face on the chart means attached; a sad face means algo trading is off somewhere.

Take away

Open Data Folder, Experts, compile, refresh Navigator. Smiley face plus green toolbar button, or it is not trading.

Lesson 03

Inputs, and the ones that matter most

Every EA exposes inputs, and they are not equally important. In a pending-order system the two that dominate everything are the distance orders sit from price and the stop distance. Everything else is decoration by comparison.

Distance is where most systems are silently broken. If the code adds the current spread to the requested distance, and then adds a re-hang dead band on top, orders end up sitting several times further from price than the setting implies — and a system designed to be filled constantly is filled almost never.

Change one input at a time and record the result. Changing three and liking the outcome teaches you nothing about which one did it.

Take away

Order distance and stop distance dominate. Check what the code adds to your setting before blaming the setting.

Lesson 04

Backtesting honestly

Use the Strategy Tester with Every tick based on real ticks where the broker provides them. Model-generated ticks flatter systems that trade inside the bar, which is most of them. Set the modelling period to include at least one regime you dislike — a crash, a long range, a low-volatility grind.

Set spread to a realistic value or, better, to the historical spread if available. A grid system backtested at a fixed one-point spread and traded at fifteen is a different system.

Read the drawdown before the profit. A curve that made 300 per cent with a 70 per cent drawdown is not a strategy you can trade, because you will not still be there at the bottom of the drawdown.

Take away

Real ticks, realistic spread, an ugly period included. Read maximum drawdown first.

Lesson 05

Forward testing on demo

A backtest tells you the rules were profitable on data the developer could see. Forward testing on a demo account tells you they survive execution: real spreads, real slippage, real rejections, real gaps, real weekends.

Run it for long enough to include the events that break things — a payrolls release, a rollover, a Sunday open, a month-end. Two weeks is the practical minimum and a month is better.

Compare demo results against the backtest for the same period. A large divergence is the finding, and it is almost always execution: fills you did not get, spreads you did not model, a stops level that blocked your placement.

Take away

Backtest proves the rules. Forward test proves the execution. You need both.

Lesson 06

Broker conditions that break an EA

Four specifications quietly decide whether a system works at all. Stops level and freeze level set the minimum distance for placing and modifying orders — a system designed around a five-cent gap is impossible at a broker with a twenty-cent stops level. Minimum volume and volume step may forbid the size your risk maths produced. Maximum orders and hedging decide whether a basket approach is even legal on the account.

Read them from the code rather than the website: SYMBOL_TRADE_STOPS_LEVEL, SYMBOL_TRADE_FREEZE_LEVEL, SYMBOL_VOLUME_MIN, SYMBOL_VOLUME_STEP. Print them once on startup and you will never guess again.

Execution model matters too. A netting account merges opposite positions into one; a hedging account keeps them separate. A strategy that holds both sides at once requires hedging and will behave completely differently on netting.

Take away

Stops level, freeze level, volume step, hedging. Print them on startup and design around the real numbers.

Lesson 07

Running an EA on a VPS

An EA only trades while its terminal runs. A laptop that sleeps, updates or loses wifi is a system that stops mid-position, sometimes with a client-side trailing stop that was the only thing protecting it.

A VPS near the broker’s server solves both uptime and latency. MetaQuotes offers one inside the terminal; independent providers are usually cheaper. What matters is location relative to the broker, not raw specifications — an EA needs very little CPU.

After migrating, verify on the VPS itself rather than assuming: the terminal is logged in, algo trading is enabled, the chart has the EA attached with the right inputs, and the symbol name matches. Symbol suffixes differ between servers, and an EA on XAUUSD does nothing on an account that quotes XAUUSD+.

Take away

Uptime is a strategy component. Check symbol names after migrating — suffixes differ between servers.

Lesson 08

Monitoring, journals and when to switch it off

Set the EA to write its own state to a file: open positions, pending orders, floating profit, the distances it is actually using, and every closed deal with a timestamp. Reading a file beats reading a screenshot, and it gives you a record when something goes wrong at three in the morning.

Watch three numbers daily — closed profit, maximum drawdown since start, and the number of trades. A sudden change in trade count usually means conditions changed, not that the market did: a widened spread pushing orders out of reach, or a stops level rejection loop.

Decide the switch-off rule in advance and write it next to the risk plan: a drawdown percentage, or a number of consecutive losing days. Deciding it while watching an open drawdown is deciding it at the worst possible moment.

Take away

Make the EA report to a file, watch closed profit and drawdown, and write the switch-off rule before you need it.

Practise this on a demo before it costs anything

Same spreads, same execution, same instruments. Nothing to fund and nothing to cancel.