Lesson 7 of 10 0% complete
Lesson 7 12 min read

Algorithmic Trading Basics

Introduction to automated trading systems

Algorithmic trading — using computer programs to execute trading strategies automatically — accounts for an estimated 70-80% of daily forex volume. That doesn't mean retail traders are competing directly against Goldman Sachs's trading algorithms. It means the market you're trading in is shaped by automated systems, and understanding how they work (and how to build simple ones yourself) gives you a practical edge, or at minimum, realistic expectations about what you're up against.

What Algorithmic Trading Is (and Isn't)

At its core, an algorithm is a set of rules translated into code. "Buy when the 50-period SMA crosses above the 200-period SMA, and sell when it crosses below" — that's an algorithm. It doesn't require artificial intelligence, machine learning, or a PhD in mathematics. It requires a clear set of rules and the ability to express them in a programming language.

What algorithmic trading is:

  • Systematic execution of predefined rules
  • Elimination of emotional decision-making
  • Ability to backtest strategies on historical data before risking real money
  • Consistent execution — the algorithm follows the rules every time, without fear, greed, or fatigue
  • Speed — computers can process data and execute trades in milliseconds

What algorithmic trading is not:

  • A guaranteed way to make money
  • Set-and-forget — algorithms need monitoring, maintenance, and periodic adjustment
  • Only for quants and programmers — modern platforms make basic algo development accessible to motivated traders
  • A replacement for understanding markets — bad strategy logic doesn't become good just because a computer executes it

Types of Algorithmic Strategies

Trend following: The most common category for retail algo traders. These systems identify trends using indicators (moving average crossovers, Donchian channel breakouts, ADX filters) and hold positions until the trend reverses. They win small amounts frequently during choppy markets (or lose small), and capture large moves during trending periods. Success depends on the market trending more than it ranges over time.

Mean reversion: Based on the principle that prices oscillate around an average value. When price deviates significantly from the mean (measured by Bollinger Bands, RSI extremes, or z-score), the algorithm bets on a return to the average. Works well in ranging markets, gets destroyed during trends — the opposite of trend following.

Momentum/breakout: Enter when price breaks through defined levels (previous highs/lows, round numbers, ATR-based thresholds) with the expectation that momentum will carry price further. Requires strict stop-losses because many breakouts fail.

Statistical arbitrage: Exploits temporary mispricings between correlated instruments. The correlation-divergence strategy discussed in Lesson 5 is a simplified version. Pairs trading (going long the underperformer and short the outperformer) is the classic example. Requires sophisticated modeling and fast execution.

Market making: Placing both buy and sell limit orders to profit from the spread. Primarily the domain of institutional players and high-frequency traders with ultra-low latency infrastructure. Not realistic for retail traders, but understanding that market makers exist helps you understand market microstructure.

Platforms and Languages for Retail Algo Trading

MetaTrader 4/5 (MQL4/MQL5): The most accessible entry point. Expert Advisors (EAs) are written in MQL, a C-like language. Massive community, thousands of free and paid EAs available, built-in strategy tester for backtesting. Limitation: MQL is proprietary and the backtesting engine, while improved in MT5, has known issues with tick data accuracy.

Python: The dominant language for serious algo development. Libraries like pandas (data manipulation), numpy (calculations), and backtrader or zipline (backtesting frameworks) provide everything you need. Python connects to broker APIs for live execution. Steeper learning curve than MQL but far more flexible, powerful, and transferable as a skill.

cTrader (cAlgo/C#): Uses C#, which is well-structured and readable. Better than MQL for complex strategies. Growing in popularity as cTrader adoption increases.

TradingView (Pine Script): Great for prototyping and visualization but limited for live execution. You can write indicators and strategy alerts in Pine Script, then use third-party bridges to execute trades. Good for testing ideas quickly before coding them properly in Python or MQL.

Building Your First Algorithm

Start with something simple. Seriously. The most common mistake is trying to build a complex, multi-factor system before you can build and test a basic one. Here's a progression:

Step 1 — Define the strategy in plain English:

"Buy when price closes above the 50-period SMA and RSI(14) is above 50. Sell when price closes below the 50-period SMA or RSI drops below 30. Use a 2× ATR(14) stop-loss. Risk 1% per trade."

Step 2 — Code the entry and exit logic:

Translate each condition into code. In MQL4, Python, or your language of choice, each rule becomes an if/then statement. Start with just entries and exits — no fancy money management, no multiple timeframes.

Step 3 — Backtest on historical data:

Run the strategy against at least 5-10 years of data. Look at total return, maximum drawdown, win rate, average win vs. average loss, and Sharpe ratio. If it's profitable in backtesting, proceed cautiously (backtesting results are always better than live results).

Step 4 — Forward test on demo:

Run the algorithm on a demo account for at least 1-3 months. This catches issues that backtesting misses: slippage, requotes, connectivity problems, and edge cases in the logic.

Step 5 — Go live with minimal size:

Start with the smallest possible position size. Watch the algorithm trade for another 1-3 months. If it performs within expected parameters, gradually scale up.

The Reality Check: Why Most Algo Traders Fail

Overfitting: The number one killer. You optimize your strategy until it perfectly fits historical data — catching every turn, avoiding every losing trade in the backtest. Then you run it live, and it immediately loses money because it was molded to past data, not to the underlying market dynamics. The cure: keep strategies simple, use out-of-sample testing (only optimize on part of the data, then validate on the rest), and be suspicious of strategies with very high backtest returns.

Data quality: Garbage in, garbage out. Free historical data often has gaps, missing ticks, and incorrect timestamps. If your backtest uses bad data, your results are meaningless. Invest in quality data from reputable sources.

Survivorship bias: You test 100 strategy variations and find one that works great in backtesting. But with 100 tries, you'd expect some to look good by random chance alone. This is why out-of-sample testing and forward testing on demo are non-negotiable.

Execution differences: Backtesting assumes perfect fills at exact prices. Real markets have spreads, slippage, and latency. A strategy that makes 3 pips per trade in backtesting might lose 1 pip per trade in reality because of execution costs. Always account for realistic trading costs in your backtest.

Market regime changes: A strategy that worked in 2020's volatile COVID markets may fail in a low-volatility 2024 environment. Markets change character, and algorithms need periodic review and adjustment. "Set and forget" is a myth.

Getting Started: A Practical Path

If you're interested in algorithmic trading, here's the realistic path:

  1. Learn to trade manually first — you need to understand the market before automating strategies
  2. Pick a language — MQL4/5 for the easiest start, Python for the most versatile future
  3. Take a structured course on your chosen language (basic programming takes 2-4 weeks to learn)
  4. Code and backtest simple strategies — moving average crossovers, breakout systems, RSI mean reversion
  5. Forward test on demo for months, not days
  6. Go live with minimal capital and realistic expectations

Algorithmic trading is a skill that compounds over time. Your first algorithm will be terrible. Your tenth will be decent. Your fiftieth might actually make money consistently. The journey is longer than Instagram gurus suggest, but the endpoint — a systematic, emotion-free trading approach — is genuinely powerful.

To test EAs and algorithms across different platforms, use our Broker Finder to compare brokers by platform support (MT4, MT5, cTrader). Our Demo Account Guide covers the best demo environments for algo testing.

💡

Key Takeaway

Algorithmic trading removes emotion and enforces consistency, but it doesn't remove the need to understand markets. Overfitting is the primary killer of algo strategies — keep rules simple, always validate on out-of-sample data, and forward test on demo before risking real capital. The journey from first algorithm to consistently profitable system takes months or years, not days.