What is algorithmic trading, and how does it work?
Algorithmic trading means a computer places trades by following rules written in advance. Here is how that works, from the price feed to the order, and what automation can and cannot do for you.
Based on our team’s research and live testing since 2018.
Algorithmic trading, or algo trading, means using a computer program to place trades by following rules written in advance. The program watches prices, checks its rules, and sends orders to a broker when the conditions are met. Nobody clicks “buy”. The program does it, the same way every time.
That is the whole idea. This guide explains how it works in practice, which kinds of strategies get automated, where the programs run, and the limits that sales pages tend to leave out.
What does “algorithm” mean in trading?
An algorithm is a list of exact instructions. In trading, it answers the questions a manual trader answers by eye: When do I enter? How much do I risk? Where is my stop? When do I exit? What do I do when something goes wrong?
The key word is exact. “Buy when the trend is strong” is not an algorithm. “Buy when the 20-period EMA closes above the 50-period EMA on the H1 chart, and risk 1% of equity with a stop 1.5 × ATR(14) below the entry” is. A computer can only follow the second one.
How does an algo trading system work, step by step?
Every trading program, simple or complex, runs the same loop:
- Data. The program receives prices from the broker or exchange: every tick, or each new bar.
- Signal. It checks its entry and exit rules against that data.
- Risk check. Before any order, it works out the position size and checks its limits: daily loss, maximum spread, number of open trades.
- Execution. It sends the order through the platform or the broker’s API. The fill price can differ from the price the program saw.
- Management. It moves stops, takes partial profits and closes trades by its exit rules.
- Logging. It records what it did and why, so you can check it later.
Here is step 2 as real code: a simplified MetaTrader 5 Expert Advisor that buys when a fast moving average crosses above a slow one on a closed bar.
1// One complete entry rule, written as code (simplified: no stops or sizing yet)2#include <Trade\Trade.mqh>3CTrade trade;4int fastMA, slowMA;5 6int OnInit()7{8 fastMA = iMA(_Symbol, _Period, 20, 0, MODE_EMA, PRICE_CLOSE);9 slowMA = iMA(_Symbol, _Period, 50, 0, MODE_EMA, PRICE_CLOSE);10 if(fastMA == INVALID_HANDLE || slowMA == INVALID_HANDLE) return INIT_FAILED;11 return INIT_SUCCEEDED;12}13 14void OnTick()15{16 double fast[], slow[];17 if(CopyBuffer(fastMA, 0, 1, 2, fast) != 2) return; // the last two CLOSED bars18 if(CopyBuffer(slowMA, 0, 1, 2, slow) != 2) return; // [0] = older, [1] = newer19 20 bool crossedUp = fast[0] <= slow[0] && fast[1] > slow[1];21 if(crossedUp && !PositionSelect(_Symbol))22 trade.Buy(0.10, _Symbol); // market buy, 0.10 lots23}The entry logic takes about ten lines. A real EA is mostly the other steps: sizing from the stop, spread filters, rejected orders, restarts and broker differences. That is where most of the development time goes, and it is most of what we do in custom EA development.
Where does algorithmic trading run?
The platform usually depends on what you trade and which broker you use.
| Platform | Language | Typical use |
|---|---|---|
| MetaTrader 4 / 5 | MQL4 / MQL5 | Expert Advisors for forex, gold and index CFDs at retail brokers and many prop firms |
| TradingView | Pine Script | Indicators, strategy backtests and alerts. It does not place orders in MetaTrader by itself |
| Your own server | Python | Bots that connect to broker or exchange APIs, plus research and data work |
| cTrader | C# or Python | cBots at brokers that offer cTrader |
If you are deciding between the two most common choices, read MQL5 vs Python for algo trading.
What kinds of strategies are automated?
| Type | The idea | Where it struggles |
|---|---|---|
| Trend following | Buy strength, sell weakness, and stay in while the move lasts | Sideways, choppy markets, where it is stopped out again and again |
| Mean reversion | Price stretched far from an average tends to come back | Strong trends, where “stretched” keeps stretching |
| Breakout | Trade when price leaves a range or a session’s high or low | False breakouts and wide spreads at session opens |
| Grid and martingale | Add positions, often larger ones, as price moves against you | One long move in the wrong direction; see grid and martingale risks |
| Arbitrage and high-frequency | Small price differences, captured by speed | Needs infrastructure that retail traders do not have |
| Execution algorithms (VWAP, TWAP) | Split one large order into many small ones | Used by institutions to execute orders, not to find an edge |
What are the real advantages?
- Consistency. The program follows the rules every time. It does not hesitate after a loss or get greedy after a win.
- Testability. Exact rules can be tested on years of past data. A feeling cannot.
- Hours. On a VPS, a program can watch a 24-hour market without you.
- Risk control. Limits such as a daily loss stop can be checked on every tick, which matters a lot on prop-firm accounts.
- Scale. One program can watch many symbols at once.
What can algorithmic trading not do?
- It does not create an edge. Automating a losing idea just loses on schedule.
- Markets change. Rules that suited one period can fail in the next.
- Software fails. Disconnects, restarts, rejected orders and bugs all happen. Someone still has to watch the logs.
- Backtests flatter. A test without real costs and real tick data usually looks better than live trading. The usual reasons are in why an EA works in the backtest but not live.
This is also why bought robots so often disappoint. We go through that honestly in do Expert Advisors actually work?
Is algorithmic trading only for big institutions?
No. Retail traders have run Expert Advisors on MetaTrader for many years, and brokers that offer MetaTrader usually provide it at no charge. The difference is what you compete on. Institutions compete on speed and size. Retail traders should not try to. Retail algorithms usually work on slower timeframes, where being a few milliseconds late does not change the result.
The rules on who may automate, and how, depend on your country and your broker. In India, for example, retail algo trading through broker APIs has its own framework; see is algo trading legal in India?
How do you get started?
The short version: write your rules down, test them on past data with real costs, run them on a demo account for one to three months, then go live at the smallest size. The full plan is in how to start algorithmic trading, and the budget side is in how much money you need for algo trading.
If you already have rules but not the time to code them, we build MT4/MT5 Expert Advisors, Python trading bots and Pine Script tools from your specification.
Summary
- Algorithmic trading is trading by exact, written rules that a program follows.
- Every system runs the same loop: data, signal, risk check, execution, management, logging.
- The entry rule is a small part of the code. Risk handling and failure handling are most of it.
- Automation gives consistency and testability. It does not create an edge.
Quick answers
Is algo trading the same as a trading bot?
In everyday use, yes. A trading bot is the program; algorithmic trading is the practice of trading with one. On MetaTrader the bot is called an Expert Advisor (EA).
Is algorithmic trading profitable?
It can be, but automation does not create the profit. The strategy, its costs and its risk control decide that. A program that follows weak rules loses money more consistently, not less.
Is algo trading the same as high-frequency trading?
No. High-frequency trading is one small, specialised part of algo trading that competes on speed. Most retail algorithms trade on minute, hourly or daily charts, where a few milliseconds do not matter.
Can I run an algorithm on my own computer?
Yes, for testing. For live trading, the computer must stay on and connected while the market is open, which is why many traders use a VPS.
Do I need to be a programmer?
No. You need exact rules. You can learn to code them, use a visual builder, or have a developer build them for you.