← Back to Blog

Getting Started with Algorithmic Trading

Algorithmic trading — using computer programs to execute trading strategies automatically — sounds intimidating. But at its core, it's simply the practice of turning a trading idea into a set of rules, testing those rules against historical data, and then letting a machine execute them without emotion or hesitation.

For retail traders in India, algo trading has gone from a distant institutional advantage to something entirely accessible. The tools exist, the broker APIs are available, and the data is there. What's often missing is a structured approach to learning. This post is a starting point.

What Algorithmic Trading Actually Is

Strip away the jargon, and algorithmic trading is three things:

  1. A set of rules — when to buy, when to sell, how much to risk. These rules are defined precisely enough for a computer to follow.
  2. A testing framework — historical data and backtesting software that let you evaluate how those rules would have performed in the past.
  3. An execution pipeline — software that monitors live market data, detects when your rules trigger, and places orders through your broker automatically.

That's it. No magic, no AI predicting the future. Just disciplined, repeatable decision-making.

Why It Matters for Retail Traders

Discretionary trading — making decisions in real-time based on charts and instinct — is hard. Not because the ideas are bad, but because humans are terrible at consistent execution. We hesitate on entries, hold losers too long, cut winners too short, and trade differently when we're up versus when we're down.

Automation solves the execution problem. Once you've validated a strategy, the machine follows the rules every single time. No fear, no greed, no "I'll skip this trade because it doesn't feel right."

But automation also forces clarity. You can't code a vague idea. "Buy when the trend looks strong" isn't a strategy — it's a feeling. Translating it into code means defining exactly what "trend" means, what "strong" means, and what "buy" means (market order? limit? how many shares?). This clarity alone makes you a better trader, even if you never automate a single trade.

The Tools: AmiBroker and AFL

While there are many platforms for algo trading (Python-based frameworks, MetaTrader, NinjaTrader), this blog focuses primarily on AmiBroker — a professional-grade charting and backtesting platform that's been a staple of quantitative traders for over two decades.

AmiBroker uses its own language called AFL (AmiBroker Formula Language). It's purpose-built for financial analysis — compact, fast, and array-oriented. A moving average crossover strategy that might take 30 lines of Python takes 5 lines of AFL.

Here's what a simple moving average crossover looks like in AFL:

// Simple Moving Average Crossover
fastMA = MA(Close, 10);
slowMA = MA(Close, 50);

Buy  = Cross(fastMA, slowMA);
Sell = Cross(slowMA, fastMA);

// Plot for visualization
Plot(Close, "Price", colorDefault, styleCandle);
Plot(fastMA, "Fast MA", colorGreen, styleLine);
Plot(slowMA, "Slow MA", colorRed, styleLine);

That's a complete, runnable strategy. Cross() detects when one array crosses above another. Buy and Sell are built-in variables that AmiBroker's backtester reads directly.

Setting Up Your Environment

Here's a practical checklist for getting started:

  1. Install AmiBroker — download the trial from the official website. The full license is a one-time purchase (no subscription).
  2. Get historical data — you need quality OHLCV (Open, High, Low, Close, Volume) data. For Indian markets, several data vendors provide AmiBroker-compatible feeds. Free data from Yahoo Finance can work for initial learning.
  3. Write your first formula — open the AFL Editor (Analysis → Formula Editor), type in the moving average crossover above, and apply it to a chart. You'll see the buy/sell arrows immediately.
  4. Run your first backtest — open the Analysis window, set your date range and initial capital, and click Backtest. Read the results critically — don't just look at total profit.

The Trap: Curve-Fitting

Here's the single most important concept for any new algo trader: a strategy that looks great on historical data might be completely worthless going forward.

This happens through curve-fitting — optimizing parameters until they perfectly match past price movements. The strategy isn't capturing a real market pattern; it's memorizing history. When the future inevitably differs from the past, the strategy falls apart.

The antidote is walk-forward analysis: split your data into in-sample (training) and out-of-sample (testing) periods, optimize on the training set, and test on data the strategy has never seen. Repeat this across multiple windows. If the strategy holds up out-of-sample, you have something worth investigating further.

A strategy that earns modest returns out-of-sample is worth infinitely more than one that earns spectacular returns only in-sample.

We'll cover walk-forward analysis in detail in a future post. For now, just remember: never trust a backtest that was optimized on the same data it was tested on.

What's Next

This post covered the "what" and "why." Upcoming posts will dig into the "how":

  • Writing your first AFL strategy from scratch
  • Reading backtest reports — which metrics matter and which are misleading
  • Walk-forward optimization — the right way to validate a strategy
  • Connecting AmiBroker to a broker for live execution
  • Risk management — how to size positions and set loss limits

If you're just starting out, focus on one thing: write a simple strategy, backtest it, and study the results. Don't worry about live trading yet. The goal is to build intuition for how strategies behave — where they work, where they break, and why.