On this page
An Expert Advisor, or EA, is a program that trades by rule. It runs inside the MetaTrader platform, reads prices and sends orders without anyone clicking. This lesson explains what such a program is, how it runs, the ways it fails in operation and what a VPS is for. An EA carries out its instructions exactly, which is not the same as trading well.
What an Expert Advisor is
MetaTrader is made by MetaQuotes, and its programs are written in the company’s own languages: MQL4 for MetaTrader 4 and MQL5 for MetaTrader 5. The two are not interchangeable, so a program compiled for one platform does not run on the other. The platform knows three main kinds of program.
| Program | What it does | Can it trade? |
|---|---|---|
| Expert Advisor | Stays on a chart and reacts to each new price | Yes |
| Indicator | Calculates values from prices and draws them | No |
| Script | Runs once when started, then stops | Yes |
How it runs
An EA is attached to one chart in the trading terminal on the trader’s computer. It does not run on the broker’s server. The terminal calls the program when something happens, and three events matter most.
- Start. When the EA is attached, it runs its set-up code once and reads its settings.
- Each tick. Every time a new price arrives for the chart’s instrument, the EA runs its main routine: it reads prices, checks its rules, and sends, changes or closes orders.
- Stop. When the EA is removed or the terminal closes, it runs its closing code.
Two consequences follow. The EA works only while the terminal is open, connected and allowed to trade automatically. And between ticks it does nothing: in a quiet market it may not run for seconds at a time. Orders already placed are different. A pending order, a stop-loss or a take-profit attached to a position is held on the broker’s server and remains there if the terminal goes offline.
How it fails in operation
Most failures of an automated system have nothing to do with its trading idea.
- Connection loss. With no connection the EA receives no prices and can send nothing. Anything it does in its own code, such as trailing a stop or closing at a set time, stops happening.
- Requotes and rejected orders. A request can be refused, requoted at a new price or filled at a price different from the one asked for. A program that assumes every order succeeds loses track of what it holds.
- Restarts. A computer update or a power cut restarts the terminal. Whatever the EA kept only in memory is gone, and it must work out its position again from the account.
- Version changes. The platform is updated in numbered builds, and the language has changed between them: a large revision of MQL4 in 2014 required many older programs to be corrected. A broker can also change an instrument’s name, its number of decimal places or its contract size, and code that assumed the old values misbehaves.
A well-written EA checks the result of every request and handles each of these cases. Many do not.
What a VPS is for
A virtual private server (VPS) is a computer rented in a data centre that stays switched on and connected. The terminal and its EA are installed there and run around the clock, whatever happens to the trader’s own machine. A server near the broker’s also shortens the time an order takes to arrive.
A VPS removes one class of failure: the home computer, its power and its internet line. It does not remove requotes, version changes or a broker’s server going down, and it adds a regular fee and one more system to watch. An unattended program still needs checking.
Rules, not judgement
An EA does what its code says, including its mistakes, at any hour and at any size it was told to use. It removes hesitation. It does not remove risk, and it can lose money faster than a person would. Whether its rules have any merit is a separate question, and the usual evidence offered for them is a backtest: the subject of the next lesson.
Three questions
Check what you have read
Each answer is in the lesson above. Nothing is timed or graded: when all three are answered correctly, this browser remembers the lesson as completed, and nothing is sent anywhere.
Question 1 of 3
Question 2 of 3
Question 3 of 3
The lesson, in a limerick
A program that trades by the ruleis a diligent, literal tool.If the line should go dead,it does nothing instead:it is neither a sage nor a fool.
Lesson 1 of 2 in Automated trading. A suggested order: nothing here is graded, timed or certified.
