Home › Guides › Automation › How an EA works

How an EA works under the hood

By Luis Sanches y Milton Bertillo, mentors at SHEFA Trading Academy · Updated on 21 September 2026 · Reading time: 7 min

Knowing what an EA does from one tick to the next removes a lot of the fear and solves half the problems. An EA is not a black box: it is a program that the terminal notifies when something happens. Here is the complete path, from attaching it to the chart to sending an order, with the official references so you can verify it.

The lifecycle: which events it responds to

MetaTrader 5 calls a series of expert functions depending on what happens in the terminal. Almost all the work of an EA lives in OnTick (official documentation).

FunctionWhen it runsWhat it is used for
OnInit()Once, when the EA is loaded onto the chartPrepare variables, validate parameters, create indicator handles
OnTick()Every time a new tick for the symbol arrivesThe heart: read data, decide and, if it is time to, send orders
OnTimer()At the interval set with EventSetTimer()Periodic tasks: refresh a panel, check schedules, publish data
OnTradeTransaction()When something changes in trades or positionsReact to executions, partial closes or cancellations
OnDeinit()When the EA is unloaded from the chartClean up objects, release resources, leave a trace
Practical consequence: if there are no ticks, there is no OnTick. An EA that is very active on M1 can spend a long time without running on an index with spaced-out ticks, and that is not a bug: it is how the terminal works.

What it looks at on each tick

Before deciding anything, an EA reads from the terminal. All the information comes from query functions (symbol specification and time series):

How a trade is sent

To trade, the expert builds a request and sends it to the server with OrderSend() (official documentation). The request carries the symbol, volume, price, stop, target and the magic number. The server can accept or reject it, and that is where most surprises lie:

The logic, in four lines

Stripped of frills, almost every risk management expert does this on every tick. Seeing it written down helps to understand why the order of the steps matters:

1 · Do I already have a position of my own? → if I do, manage it (trailing, time, target).
2 · Is my entry condition met and am I not outside trading hours? → continue.
3 · Calculate the lot size using risk and distance to the stop. If it comes out below the minimum, DO NOT trade.
4 · Send the order with stop and target; if the server rejects it, log the reason and do not keep retrying in a loop.

Step 3 is what separates a risk-controlled bot from an account-burning machine. An expert that sends “0,10 lots” for no reason is ignoring the one thing that really should be automated: position size.

Why it sometimes ‘does nothing’

Before suspecting the strategy, rule out these causes. In our experience, most queries about ‘my EA doesn't trade’ are resolved here:

SymptomCommon cause
The smiley face does not appear on the chartThe button Algorithmic trading is disabled, or the expert doesn't have permission to trade on the ‘Common’ tab
Smiley face but zero tradesTime filter, spread above the maximum allowed or entry condition not met
Numeric errors in the logVolume below the minimum, stop shorter than the symbol minimum or insufficient margin
Indicators with strange values or the expert calculates nothingSymbol history not downloaded: the terminal does not yet have enough candles
It is trading on demo and not live (or vice versa)Permissions on the expert's “Common” tab
A serious EA leaves a trail: it logs why it enters, why it does not enter and why it closes. If your expert says nothing, you are not automating: you are guessing.

How to check that it does what you think

  1. “Experts” tab of the terminal: messages from Print, errors when sending and warnings.
  2. Strategy Tester in visual mode: you see it trading on the chart, entry by entry, with the list of trades alongside.
  3. Demo account with the same broker over a period that includes bad days: that is where the real rejections, slippage and the spread for each hour appear.
  4. Results report in R, not in money: to compare the system with yourself when the size changes (how it is measured).

Frequently asked questions

What is OnTick and how often does it run?

It is the function called every time a new tick arrives for the chart symbol. It does not run at fixed intervals: it depends on the real tick frequency of the instrument, which on synthetics can be several per second or one every few seconds depending on the index.

Why does my EA do nothing even though the market is open?

Almost always for reasons unrelated to the strategy: “Algorithmic trading” disabled, symbol with no history, lot below the minimum, stop below the minimum allowed, spread above the filter, a position already open, or the instrument's daily pause. The Experts log says which one.

Can an EA trade several symbols at once?

Yes. An expert only receives ticks from the chart it is on, so two approaches are used: query the other symbols from a single chart, or open an instance on each chart with a magic number different one so that each manages only its positions.

How do I know what my EA is doing at any given moment?

With Print to the “Experts” tab, with the Strategy Tester in visual mode and with the terminal's “Trades” tab. An expert that leaves no trail is impossible to audit.

Does it work the same live as in the tester?

No. The tester reconstructs the past with a simplified execution model: with no real latency, with approximate slippage and with a spread that does not reflect every hour of the day. That is why it is also tested on demo before risking money.

Understanding what it executes, before letting it loose

At the academy, what the expert does and why is reviewed first, and only then is it allowed to trade. If you cannot explain a trade in the log, the problem is not the market.

See access plans →

Keep reading

Risk warning. An expert can execute losses just as effectively as it executes wins. Synthetic indices and CFDs are leveraged products with a high risk of loss and most retail accounts lose money. Educational content, not financial advice.