Expert Advisors (EA): The Complete Guide for Traders

By the Victoryalgo team · · 14 min read

An Expert Advisor (EA) is a program that trades for you inside MetaTrader. You give it clear rules. It watches the market and acts when those rules are met.

This guide is the starting point for everything about EAs on our blog. Each section explains the basics in simple words, then links to a detailed guide or service page if you want to go deeper.

What Is an Expert Advisor?

An Expert Advisor is a small program that runs on a chart in MetaTrader 4 (MT4) or MetaTrader 5 (MT5). MT4 EAs are written in a programming language called MQL4. MT5 EAs are written in MQL5.

You can think of an EA as a very strict assistant. It reads prices and indicator values, checks your conditions, and then opens, changes or closes trades. It does exactly what the code says, nothing more and nothing less.

An EA comes as a file. There are two kinds:

  • Source file (.mq4 or .mq5): the code a developer can read and edit.
  • Compiled file (.ex4 or .ex5): the file MetaTrader runs. It cannot be properly edited.

If you want an EA changed later, the developer needs the source file. So always ask for it and keep a copy in a safe place.

Want the full route from an idea to a working EA? Read How to Turn Your Trading Strategy Into an MT5 EA.

How an EA Works Inside MT4 and MT5

You do not need to code to use an EA. But a basic picture of how it works helps you brief a developer and understand problems when they happen.

Events: OnInit, OnTick and OnDeinit

An EA does not run like a normal app that is busy all the time. MetaTrader runs parts of the code when something happens. These moments are called events:

  • OnInit runs once when you attach the EA to a chart. It checks the settings and gets everything ready.
  • OnTick runs each time a new price (a tick) arrives for the chart's symbol. This is where most of the trading logic usually sits.
  • OnTimer can run at a fixed interval, such as every few seconds, if the EA needs it.
  • OnDeinit runs when you remove the EA, change the chart or close the terminal.

This has two simple results. When no new ticks arrive, for example at the weekend, OnTick does not run. And when MetaTrader is closed, nothing runs at all.

Inputs: The Settings You Can Change

Inputs are the settings you see when you attach the EA to a chart. Common examples are lot size, risk percent, stop loss, take profit, trading hours and a maximum spread. In the code, they are marked with the word input.

Good inputs let you adjust the EA without asking for a new version of the code. You can save a group of inputs to a .set file and load it again later.

Orders: How the EA Places Trades

When your rules are met, the EA builds a trade request. The request says which symbol, buy or sell, the lot size, the stop loss and the take profit. The terminal sends it to your broker's trade server, and the server fills it or rejects it.

A request can be rejected for several reasons. The stop loss may be too close to the price, there may not be enough free margin, or the market may be closed. A well-written EA checks the result of every request and writes a clear message in the Experts tab, so you can see what happened.

Each EA also marks its trades with an ID called a magic number. This lets the EA find its own trades and leave your manual trades, or trades from other EAs, alone.

What EAs Can and Cannot Do

What an EA Can Do

  • Follow your rules the same way every time, without getting tired or emotional.
  • Watch several symbols and timeframes at the same time.
  • React to a price change faster than a person can click.
  • Manage open trades: move the stop loss to break-even, trail it, close part of a trade, or close a group of trades.
  • Apply risk limits, such as a maximum lot size, a maximum number of trades or a daily loss limit.
  • Send alerts to your phone or email.

What an EA Cannot Do

  • It cannot fix a weak strategy. It only automates the rules you give it.
  • It cannot think or change its own rules. If the market changes, the EA keeps doing the same thing until you change it.
  • It cannot trade while MetaTrader is closed. The terminal must be open and connected to your broker.
  • It cannot control prices. Spreads, slippage and order fills come from the broker and the market.
  • It cannot follow rules that are not written down. A "feeling" about a trade cannot be coded until you turn it into an exact condition.

A bot follows your rules, but results depend on your strategy and the market. You can lose money with any EA, so always test on a demo account first.

Types of Expert Advisors

Not every EA opens trades by itself. Here are four common types. One EA can also mix several of them.

Strategy EAs

A strategy EA opens and closes trades on its own, based on your entry and exit rules. The rules can use indicators, price action, candle patterns or time. This is what people usually mean when they say "an EA". See our MT5 EA development and MT4 EA development services.

Trade Managers

A trade manager does not decide when to enter. You open the trade by hand, and the EA manages it with your exit rules. Common features are break-even, trailing stop, partial close and closing a basket of trades at a set level. A trade manager suits traders who want to keep their own entries but automate the exits.

Risk and Prop Firm Guards

A risk guard watches your account, not the chart. It can block new trades, or close open trades, when equity reaches a level you set or when a daily loss limit is near. These guards are often used on funded accounts with strict loss rules. Read Prop Firm EA: How to Code Daily Drawdown and Max Loss Rules or see our prop firm EA service.

Indicators and Alerts

Strictly speaking, an indicator is a different kind of program. It draws lines, arrows or zones on the chart and can give alerts, but it cannot place trades.

Some traders start with a custom indicator that alerts them to a setup. They watch the signals for a while, then turn the same logic into an EA. Alerts can be a pop-up, a sound, an email or a push message to the MetaTrader mobile app. On TradingView, indicators and alerts are written in Pine Script. See TradingView Pine Script.

The EA Lifecycle: From Rules to Live Trading

A well-built EA goes through six stages. If you skip one, the problems usually show up later, on a real account.

1. Write Clear Rules

Every EA starts with rules a computer can follow. "Sell when the price is too high" is not a rule. A rule uses numbers and exact conditions: which indicator, which settings, which timeframe, and whether it is checked on a closed candle. Our guide How to Turn Your Trading Strategy Into an MT5 EA shows a full example rule sheet.

2. Code the EA

A developer turns your rules into MQL4 or MQL5 code. They also add inputs for the settings you want to change, checks for errors, and clear messages for the log. Expect questions at this stage. Good questions now mean fewer surprises later.

3. Test in the Strategy Tester

The Strategy Tester runs the EA on past prices. Its first job is to check that the EA really follows your rules. It also shows how the rules acted in different market periods, but it is not a forecast. Read How to Backtest an EA in the MT5 Strategy Tester for settings, modelling modes and the danger of over-optimisation.

4. Forward Test on a Demo Account

Next, run the EA on a demo account with live prices. This shows real spreads and real order execution, which a backtest can only estimate. If you have never attached an EA to a chart before, follow How to Install and Run an EA on MT5 (Step by Step).

5. Go Live on a VPS

An EA only works while the terminal is open and connected. A VPS is a remote computer that stays on day and night, so the EA keeps running when your own PC is off. Read Do You Need a VPS to Run Your EA? A Simple Guide.

When you move to a live account, use the same settings you tested on demo. Do not change many things at the same time, or you will not know which change caused a problem.

6. Monitor and Update

An EA is not something you can set up once and forget. Check it regularly:

  • Read the Experts and Journal tabs for errors.
  • Compare live trades with your rules and with your demo results.
  • Watch for broker changes, such as new symbol names, trading hours or contract sizes.
  • After a MetaTrader update or a VPS restart, check that the EA is still on the chart and active.

If you change a rule, test the new version in the Strategy Tester and on demo again before it goes live. Keep the old version too, so you can go back if needed.

Choosing a Platform: MT4, MT5, TradingView or Python

The right platform depends on what your broker or account offers and on what your strategy needs. Here is a quick comparison.

PlatformLanguageWhere it runsCan it place trades by itself?
MT4MQL4Inside the MT4 terminalYes
MT5MQL5Inside the MT5 terminalYes
TradingViewPine ScriptOn TradingView's serversNot by itself. It sends alerts, which a webhook bridge can turn into orders
PythonPythonOn your PC or a server, outside the terminalYes, through a broker API or the MetaTrader 5 Python package

MT4 vs MT5

MT4 and MT5 use different languages, so an MT4 EA does not run on MT5. It has to be rewritten. MT5 has a stronger Strategy Tester and supports both hedging and netting accounts. Read MT4 vs MT5: Which Is Better for Your Expert Advisor?

TradingView

TradingView is good for charts, custom indicators, alerts and strategy tests. To trade the same logic automatically in MT5, it is either rewritten in MQL5 or sent through a webhook bridge. Read Can You Convert a TradingView Strategy to MT5?

Python

A Python bot runs outside MetaTrader. It can suit strategies that need outside data, custom tools or a broker API. Read Python vs MQL5: Which Is Better for Your Trading Bot? or see our Python trading bot service.

Risks and Limits of EAs

An EA removes some manual mistakes, but it brings other kinds of risk. Know them before you go live.

  • Strategy risk. If your rules lose money in a market, the EA loses money too, and it does not stop to think.
  • Over-optimisation. Settings tuned to fit past data can behave very differently on new data.
  • Trading costs. Spread, slippage, commission and swap all affect results. Spreads can get wider around news and in quiet market hours.
  • Technical problems. A lost connection, a VPS restart or a closed terminal can stop the EA, sometimes while a trade is open.
  • Coding mistakes. A small bug can open the wrong lot size or skip a stop loss. This is why testing matters so much.
  • Broker and account differences. Symbol names, minimum stop distance, lot steps and account type (hedging or netting) differ between brokers. An EA tested on one account may need changes for another.
  • Leverage. Higher leverage makes every price move count more on your account, in both directions.
Remember: A bot follows your rules, but results depend on your strategy and the market. No one can promise results from an EA. You can lose money, so test on a demo account before you trade live.

How to Brief a Developer

A clear brief saves time and avoids an EA that does something you did not mean. The full list of what to send is in How to Turn Your Trading Strategy Into an MT5 EA. Here are some points that are easy to forget:

  • Special cases. What should happen if a new signal comes while a trade is open? After a weekend gap? When the spread is very wide?
  • Time zone. Say whether your trading hours are in your local time or the broker's server time.
  • Platform and account type. MT4 or MT5, and hedging or netting.
  • Existing code. If you want an old EA fixed, send the .mq4 or .mq5 source file. A compiled file alone cannot be properly edited.
  • Inputs. List the settings you want to change yourself.
  • Account rules. Any loss limits, news rules or lot limits you must follow.

You never need to share your trading password with a developer. Testing can be done on a demo account, and you can stay in control of your own login during setup.

EA Glossary

Here are short meanings of words you will see in EA guides and settings.

  • Backtest: running an EA on past prices to see how its rules would have acted.
  • Drawdown: a fall in the account from a high point to a later low point, often shown as a percent.
  • Equity: your balance plus or minus the result of open trades. Balance only changes when a trade closes.
  • Forward test: running an EA on live prices, usually on a demo account, after the backtest.
  • Lot: the unit for trade size. On a typical forex account, 1 standard lot is 100,000 units of the base currency and 0.01 is a micro lot. Contract sizes depend on the broker and the symbol.
  • Magic number: an ID number the EA puts on its trades, so it can tell them apart from other trades.
  • Netting and hedging: two account modes in MT5. Netting allows one position per symbol. Hedging allows several positions on one symbol, including a buy and a sell at the same time.
  • Optimisation: testing many input values in the Strategy Tester to see how results change. Too much of it leads to curve fitting.
  • Repainting: when an indicator changes its past signals after new candles form. A repainting signal can look perfect on history but behave differently in real time.
  • Slippage: the difference between the price you asked for and the price you got.
  • Spread: the difference between the buy (ask) price and the sell (bid) price. It is a trading cost and can change during the day.
  • Tick: a single price update from the broker. Each new tick can run the EA's OnTick code.
  • VPS: Virtual Private Server, a remote computer that stays on, so your terminal and EA can run all the time.

Get Your EA Built

Victoryalgo is a software development company. We code traders' own strategies into MT5 and MT4 Expert Advisors, TradingView Pine Script and Python bots. We code your rules; we do not give trading advice, signals or broker recommendations.

Have a strategy you want to automate? Send us your strategy on WhatsApp for a free consultation. The Victoryalgo team will read your rules, ask questions and explain which platform and type of EA fit them.

Victoryalgo is a software development company, not registered with SEBI or any financial regulator. This guide is general education about software, not investment advice. Forex and CFD trading is high risk. Indian residents may trade forex only through RBI-authorised channels.

Frequently Asked Questions

What is an Expert Advisor in simple words?

An Expert Advisor is a program that runs inside MT4 or MT5 and follows your trading rules. It can open, manage and close trades when your conditions are met.

Do I need to know coding to use an EA?

No. You attach the EA to a chart and change its inputs. To get a custom EA made, you explain your rules in plain words and a developer writes the code.

Can an MT4 EA run on MT5?

No. MT4 uses MQL4 and MT5 uses MQL5, so an MT4 EA has to be rewritten before it can run on MT5.

Does my computer need to stay on for the EA to trade?

Yes. The EA only runs while the terminal is open and connected. A VPS lets it keep running when your own PC is off.

Is trading with an EA safe?

An EA removes some manual mistakes, but it does not remove trading risk. Results depend on your strategy and the market, and you can lose money, so test on a demo account first.

More Guides

Want your strategy coded?

Send your rules on WhatsApp. Free consultation, clear quote.

WhatsApp Your Strategy

Risk & Regulatory Notice

  • We are NOT registered with SEBI or any financial regulator. We do not give investment advice, tips or signals, recommend brokers, manage money or trade for you.
  • Software only: we code the rules you give us. Nothing on this page is investment advice.
  • A bot follows your rules. It can't promise profit, and past or backtest results don't show future results.
  • Trading forex, gold, indices and CFDs is high risk. You can lose money, so always test on a demo account first.

Victoryalgo · Software development company · Based in India, working globally

Regulatory status, risk disclosure & policies
Chat with us