start learning →
intermediate15 min read

Expert Advisors and trading bots: how automated forex trading really works

A trading bot is a set of rules that a computer follows without getting tired or scared. That is useful, and it is also why a bad bot can lose money faster than you can. Here is how they work and what to check.

key takeaways
  1. An Expert Advisor (EA) or cBot is a program that runs inside a trading platform and places, manages and closes trades according to fixed rules.
  2. Automation removes hesitation and fatigue, but it does not create an edge. A bot is only as good as the rules it follows and the conditions it runs in.
  3. Backtests of EAs routinely look better than live trading, because of overfitting, optimistic cost assumptions and the gap between simulated and real execution.
  4. Grid and martingale bots can show long runs of small gains and then lose a large part of an account in one move.
  5. Any bot sold with promises of steady monthly returns, verified profits or no losing months should be treated as a likely scam.

An Expert Advisor (EA) is a program that runs inside MetaTrader and trades automatically: it reads prices, applies a set of rules and opens, manages and closes positions without you clicking anything. cBots do the same job on cTrader, and "trading bot" is the general term for any such program. A bot can execute a strategy consistently and around the clock, but it cannot make a losing strategy profitable, and it can repeat a mistake hundreds of times before anyone notices.

This guide explains how EAs and bots work, where they run, why their backtests so often disappoint, the designs that carry hidden risk, and how to spot the scams built around selling them.

What an Expert Advisor actually is

Strip away the marketing and an EA is a short list of instructions written in code. A typical one answers five questions:

  1. When to enter. For example: buy when the 20-period moving average crosses above the 50-period average on the one-hour chart.
  2. How much to trade. A fixed lot size, or a size calculated from account balance and stop distance.
  3. Where to put the stop-loss and take-profit. A fixed number of pips, a multiple of recent volatility, or a level from recent price structure.
  4. How to manage the trade. Move the stop to break-even after a certain gain, trail it, close part of the position.
  5. When not to trade. Outside certain hours, when the spread is wider than a threshold, around scheduled news, or after a certain number of losses in a day.

The platform calls the program every time a new price arrives (a tick), or on a timer, and the program decides whether to do anything. That is all. There is no intelligence beyond what the author wrote, even when the product description says "AI" or "neural network". Some bots do use statistical or machine-learning models, but the model still produces a rule, and the rule can still be wrong.

EAs, scripts, indicators and cBots

The vocabulary differs by platform:

  • MetaTrader 4 and 5. Programs are written in MQL4 or MQL5. An Expert Advisor trades automatically and keeps running. A script runs once and stops, for example to close all open positions. A custom indicator draws on the chart but cannot trade. MT4 and MT5 code is not interchangeable; our guide to MetaTrader 4 vs MetaTrader 5 covers the differences and why MT5's strategy tester matters.
  • cTrader. Automated programs are called cBots and are written in C#, a mainstream programming language. Custom indicators exist too. See cTrader and TradingView for how that platform compares.
  • TradingView. Pine Script strategies can be backtested on the chart and can send alerts. Turning those alerts into live orders usually needs a broker integration or a third-party bridge, which adds another link that can fail.
  • Broker APIs. Some brokers offer programming interfaces that let a program written in any language trade directly. This is the most flexible route and the one that needs the most technical care.

The glossary entry for Expert Advisor gives the short definition if you need to send it to someone.

Where bots come from

There are three broad sources, and they carry different risks.

  • Ones you write yourself. You know exactly what the rules are, which is a large advantage. The risks are coding errors and testing errors, both of which are common.
  • Ones you commission. A freelance developer turns your rules into code. Make sure you receive the source code, not just a compiled file, and test it as if you had never seen the rules before. Misread instructions are a frequent source of losses.
  • Ones you buy or rent. Marketplaces, independent vendors and social media channels sell thousands of EAs, usually as compiled files that hide the logic. You are trusting the seller's description of what the program does. This is where most of the problems described later in this guide live.

Where a bot runs, and why that matters

An EA only works while the platform it is attached to is open and connected. Close your laptop and the EA stops managing its trades, although stop-loss and take-profit orders already placed on the broker's server remain in force.

That is why many automated traders use a virtual private server (VPS): a remote computer, usually in a data centre, that keeps the platform running 24 hours a day. Some brokers provide one at no charge above a monthly trading volume; otherwise it is a monthly bill. Our glossary entry on VPS explains the basics, and the cost belongs in your list of hidden broker fees.

A VPS physically close to the broker's servers reduces the delay between the EA's decision and the order reaching the broker. For most strategies a few milliseconds make no difference. For very short-term strategies that aim for a few pips, they can, and those strategies are also the most sensitive to costs and slippage.

Things that go wrong in practice:

  • The VPS or platform restarts for an update and the EA does not reload, or reloads with default settings.
  • The internet connection drops and the EA misses its exit signal.
  • Two copies of the same EA end up running on two machines against one account, doubling every trade.
  • The broker changes a symbol name, contract size or trading hours and the EA stops working or behaves differently.

None of these is exotic. They are the ordinary maintenance burden of automation, and someone has to check.

What automation does well

There are honest reasons to automate.

  • Consistency. A bot does not skip a valid signal because the last three trades lost, and it does not double the size because the last three won. Many of the problems covered in our guide to trading psychology come from humans not following their own rules.
  • Speed and stamina. It can watch twenty pairs on several timeframes at once, through the night.
  • Precise risk rules. Position size can be calculated exactly on every trade. A properly written EA can apply the position sizing maths more reliably than a tired person with a calculator.
  • Testability. Because the rules are explicit, you can test them on historical data, which is impossible with a vague discretionary approach.

What automation does not do

  • It does not create an edge. If the rules lose money before costs, executing them faster loses money faster.
  • It does not adapt unless told to. Markets change. A rule tuned for a quiet range can be badly wrong in a trending, news-driven market, and the bot will keep applying it.
  • It does not understand context. It does not know a central bank is meeting at 13:00, that liquidity is thin on a holiday, or that spreads usually widen at rollover, unless someone has coded those conditions in. See why spreads widen.
  • It does not remove risk. Leverage, gaps and losing streaks affect automated accounts in exactly the same way as manual ones.

Backtests versus live results

Almost every EA is sold, or chosen, on the strength of a backtest: a simulation of how the rules would have traded on historical prices. Our guide to how to backtest a strategy covers the method in detail. Here we focus on why EA backtests in particular are so often misleading.

Overfitting

A typical EA has many adjustable inputs: moving average lengths, stop distances, trading hours, filters. An optimiser can try thousands of combinations and report the one that did best on the past. That combination is usually the one that best fitted the noise in that particular stretch of data, not a durable pattern. The more inputs and the more combinations tried, the more impressive the backtest and the less it means.

A warning sign is a parameter set that only works in a narrow band. If a stop of 23 pips is excellent and 20 or 26 pips is poor, the result is probably luck.

Simulated ticks and execution

Testers have to guess what happened inside each bar if they do not have real tick data. On MT4, the default method builds artificial ticks from one-minute bars. For an EA with a 5-pip target, the order in which a bar reached its high and low decides whether a trade won or lost, and the tester is guessing. MT5 can test on real tick data where the broker supplies it, which helps, but even real ticks do not reproduce slippage, requotes or rejected orders.

Costs

Many backtests assume a fixed spread, sometimes the broker's minimum rather than its typical spread, no commission and no swaps. A strategy that makes 3 pips per trade before costs can easily lose money after them.

Worked example: the same EA, three sets of assumptions

Illustrative numbers only. Suppose an EA trades EUR/USD about 400 times a year and its backtest shows an average gain of 2.5 pips per trade, before costs, with a 1-lot position (roughly 10 units of account currency per pip on EUR/USD).

  1. Backtest as advertised. Fixed 0.5-pip spread already included, no commission. Result: 400 × 2.5 pips × 10 = 10,000 in gross gains over the year, on paper.
  2. Realistic costs. Use a typical spread of 1.0 pip instead of 0.5 (an extra 0.5 pip per trade) and add a commission equivalent to 0.7 pips per round trip. Net gain per trade falls to 2.5 − 0.5 − 0.7 = 1.3 pips. Result: 400 × 1.3 × 10 = 5,200.
  3. Live execution. Add an average of 0.5 pips of negative slippage per trade, because the EA enters on fast moves and exits with market orders. Net gain falls to 0.8 pips. Result: 3,200, before any swap costs on trades held overnight, and before any effect from overfitting.

In this example, a third of the headline figure survives reasonable cost assumptions, and that is before asking whether the 2.5-pip edge was real in the first place. Short-term EAs are the most exposed because costs are large relative to the average trade. Use our guide to how to compare trading costs to build realistic inputs, and remember swap and overnight financing for anything held past rollover.

Forward testing

The answer is to run the EA on a demo account, then on a very small live account, for long enough to see a meaningful number of trades, and compare the results with the backtest over the same period. If the live results are clearly worse than the backtest predicted for the same weeks, something in the simulation was wrong. Our guide to moving from demo account to live trading covers what a demo hides, including fills that are often kinder than live ones.

Bot designs that hide risk

Some EA designs produce results that look excellent for months and then fail badly. Knowing the patterns helps you read a performance chart.

Martingale

A martingale EA increases the position size after each loss, often doubling it, so that one winning trade recovers all previous losses plus a small gain. The equity curve looks like a smooth upward line, because most sequences end with a win. The problem is the sequence that does not end soon enough.

Illustrative example: an EA starts with 0.01 lots and doubles after each loss. After seven consecutive losses it is trading 1.28 lots, 128 times the original size, and the total exposure across the sequence is 2.55 lots. A losing streak of seven is not rare for a strategy that wins half its trades, and on an account sized for 0.01-lot trades, the margin required for the eighth step may not exist. When the account runs out of margin, the broker's stop-out closes the positions and the losses are realised in one go. Our guide to margin call and stop-out explains that mechanism.

Grid

A grid EA places orders at fixed intervals, for example every 20 pips, and adds positions as price moves against it, closing the whole basket when price retraces a little. In a ranging market this looks very consistent. In a strong trend the grid keeps adding losing positions, and the open loss grows until either price comes back or the account is stopped out.

No stop-loss, or a very distant one

Some EAs show a high win rate because they rarely close a losing trade. They hold losers and wait. The win rate is real; the risk is concealed in the open positions. Always look at equity (balance plus or minus open trades), not just balance.

Why the charts look so good

All three designs exchange many small, likely gains for a small chance of a very large loss. That shape is attractive in a sales chart covering six months and disastrous over a long enough period. Our guide to drawdown and recovery shows why a 50% loss needs a 100% gain to get back to where you started. Weekend and news gaps make it worse, because price can jump past every level in a grid at once; see gap risk and weekend risk.

Reading an EA's track record

If you are evaluating a bot, ask for evidence and read it critically.

  • Live, not demo or backtest. A live account with real money shows real fills. A demo record or a backtest proves very little.
  • Long enough. A few months can show almost anything. Look for a period that includes different market conditions and a large number of trades.
  • Equity and drawdown, not only gains. Maximum drawdown and the largest open loss matter more than the average return. A smooth balance line with deep equity dips points to grid or martingale behaviour.
  • Consistency with the backtest. If the live record looks nothing like the backtest, ask why.
  • Deposits and withdrawals. Large deposits can disguise losses in a growth figure. Check whether the reported percentage accounts for them.
  • Third-party verification is limited. Tracking sites connect to an account with an investor (read-only) password and report what they see, which is better than a screenshot. But a seller can run many accounts and show only the one that survived, and track records can be selected after the fact.

Past results, even genuine ones, do not tell you what will happen next. They tell you how the rules behaved in the conditions that happened to occur.

Scams built around trading bots

Bots are a favourite product for fraudsters because the buyer cannot see inside them and because "the software trades for you" sounds like effortless income. Our guide to forex scam red flags covers fraud in general. Patterns specific to bots:

  • Promises of steady returns. Phrases such as a fixed percentage per month, "no losing months", "verified profits" or "guaranteed" are the clearest warning. No honest seller can promise returns from trading.
  • Lifetime licence plus a recommended broker. Some sellers earn more from referring you to a particular broker than from the EA itself. Ask whether they are paid per client or per lot you trade, and be wary if the EA only works with one unregulated firm.
  • The bot that needs your account login. A seller who asks for your trading password, rather than giving you a file to run, has control of your money. Some "managed bot" schemes are simply unlicensed account management.
  • Fake platforms. In more serious frauds, the "bot" runs on a website or app that shows invented profits. When you try to withdraw, you are asked for fees or taxes first. The money was never traded.
  • Crypto "arbitrage" and "AI" bots. Schemes promising returns from an automated system that exploits price differences or uses artificial intelligence have been the subject of repeated regulator warnings. The technology language changes; the structure does not.
  • Upsells and recovery offers. After a loss, a different "service" may contact you offering a better bot or to recover your money for a fee. Treat it as a second scam.

Before you trade with any firm a bot seller points you to, check its licence on the regulator's own register; see how to check a broker licence.

A sensible process if you want to automate

  1. Write the rules down in plain language first. If you cannot describe the strategy precisely, a program cannot follow it.
  2. Backtest with realistic costs and on data the optimiser has not seen.
  3. Check sensitivity. Small changes to parameters should not turn a good result into a bad one.
  4. Forward test on demo for a meaningful number of trades.
  5. Go live small, with a position size you could lose entirely without consequence, and compare live fills with the demo.
  6. Add safeguards in the code: a maximum position size, a maximum number of open trades, a daily loss limit after which the EA stops, and a spread filter.
  7. Monitor it. Check the journal and open positions daily, record results in a trading journal, and decide in advance what level of drawdown means you switch it off.

The same applies whether you are automating your own rules or following someone else's trades through a copy service; our guide to copy trading covers the second case.

Common mistakes

  • Buying on the basis of a backtest. It is the easiest evidence to manipulate and the least reliable.
  • Running an EA without reading its settings. Default lot sizes and risk inputs may not suit your account.
  • Ignoring equity. A rising balance with a growing open loss is not a rising account.
  • Turning off the safeguards after a few good weeks to "let it run".
  • Leaving it unattended. Platform updates, broker changes and connection problems all need checking.
  • Assuming the broker or platform vets the bot. Marketplaces host products; they do not guarantee results. Execution quality depends on the broker, which is covered in our guide to ECN, STP and market maker execution.

Frequently asked questions

Do forex trading bots work?

A bot does exactly what its rules say, so the real question is whether the rules have an edge after costs. Many do not. Bots that look excellent in backtests often perform far worse live, and some designs such as martingale and grid systems carry a risk of large losses that short track records do not show. Like any trading, automated trading carries a high risk of losing money.

Are Expert Advisors legal?

Yes. Using an EA on your own account is legal and most brokers allow it, though some restrict particular techniques, such as strategies that exploit price feed delays. Selling an EA is different from managing money: someone who trades your account for you, or controls it through a bot, may need authorisation, and a seller who asks for your login is a warning sign.

Do I need to know how to code to use an EA?

Not to run one: you attach it to a chart and set its inputs. But without reading the code you are trusting the seller's description. If you plan to rely on automation, learning enough MQL5, C# or Pine Script to read the logic is worth the time, or work with a developer who hands over the source code.

Do I need a VPS to run an EA?

Only if the EA has to run when your own computer is off or disconnected. Strategies that hold trades for days and use server-side stop-loss orders can sometimes manage without one. Short-term EAs usually need continuous connection. A VPS is a cost to include in your sums.

Why does my EA perform differently live than in the backtest?

The usual causes are overfitting during optimisation, wider spreads and commission than the test assumed, slippage on entries and exits, swaps on overnight positions, and differences between the historical price data and your broker's live feed. Forward testing on demo and then small live size is the way to find out how large the gap is.

Can a broker stop me using an EA?

Brokers set their own terms. Most allow automated trading, but some prohibit specific practices, limit the number of orders per second, or do not allow EAs on particular account types. Read the terms before you rely on a bot, and ask the broker in writing if anything is unclear.

Not investment advice. This is general information and education, written without knowledge of your circumstances. It is not a recommendation to buy or sell any instrument. Past performance is not a reliable indicator of future results. Trading leveraged products carries a high risk of losing money. Risk warning