Backtesting a Trading Strategy

Backtesting runs your strategy through historical data before you risk real capital. How to avoid overfitting

TRADING & RISK4 min readBy AlgoSys Editorial TeamPublished Apr 25, 2026Updated Jun 26, 2026
Contents

Backtesting is the process of running a trading strategy through past market data to evaluate its profitability and risk in advance. For the intermediate trader it is a way to move beyond intuition and test hypotheses against real numbers. Running your rules through history shows you how the strategy would have behaved under different conditions, helps you find robust patterns, and cuts out costly mistakes before they cost you real money.

In the crypto market this method is especially valuable. Volatility here is high, and past price action often hints at what to expect from future behavior. By analyzing the history, you either reinforce your confidence in the strategy's logic or honestly see where it needs to be reworked. At its core, backtesting is the foundation of quantitative trading and systematic strategy development.

The greatest practical value is that decisions about capital allocation and trade execution become data-driven rather than gut-driven. A backtest bridges the gap between the theoretical design of a strategy and its real-world application. Mastering it is a key step toward building a disciplined and profitable trading edge.

MECHANICS

At the heart of a backtest is a simple idea: you feed historical price and volume data into a predefined set of rules. Those rules describe when to enter and exit, what size to open a position with, and where to place the stop-loss (the protective exit at a loss) and take-profit (the profit-locking exit). The simulation steps through the history, executes the rules, and tallies the hypothetical result of each trade, accounting for slippage (the difference between the expected and the actual fill price) and commissions, which on many venues run between 0.05% and 0.2% per trade.

Take a concrete example. A strategy opens a long when the 20-period moving average crosses above the 50-period moving average, and closes the position if price falls 2% below the entry or reaches a 5% take-profit. The simulation scrolls through these rules across the full history and accumulates the result. From the output you get the key metrics: total return, win rate, maximum drawdown (the deepest decline in equity from peak to trough), and the Sharpe ratio (return adjusted for risk).

Advanced backtests go further and incorporate conditions close to real trading: the bid-ask spread, order book depth, and execution latency. The more accurately these are modeled, the closer the simulation is to what awaits you in live trading. One simple dependency to keep in mind: the accuracy of a backtest is determined by the quality of the historical data and by how honestly you model your own market impact.

EXECUTION

To run a strategy correctly, follow this sequence of steps:

  1. Define your entry and exit rules precisely, including all technical indicators and price action triggers.
  2. Set your position-sizing methodology: a fixed percentage of equity per trade or a fixed contract size.
  3. Specify your risk management parameters: where the stop-loss goes (for example, 1.5x ATR) and where the take-profit target is.
  4. Choose a reliable source of historical data covering the relevant asset, timeframe, and period.
  5. Select a backtesting platform or write custom scripts that simulate execution.
  6. Run the simulation and carefully record every hypothetical trade, its result, and all costs: commissions and slippage.
  7. Review the results, focusing on the key metrics: total return, drawdown, and win rate.
  8. Iterate on rules, parameters, or data based on the analysis to improve robustness and reliability.

COMMON MISTAKES

The most common trap is overfitting, where rules are fitted to the history so tightly that they lose their market rationale. A strategy that works perfectly on past data but has no logical justification will almost certainly fail going forward. Check yourself: every rule should have a clear market reason behind it, not just a pretty equity curve.

The second mistake concerns costs. If the backtest does not account for commissions, fees, and potential slippage, its profit is illusory. A strategy that is profitable before costs can easily become unprofitable once they are included, so build in expenses from the start rather than leaving them for later.

The third trap is a narrow sample. Testing a strategy in just one market regime gives you false confidence. Use a sufficient volume of varied data that covers bull, bear, and sideways markets; otherwise the first unfamiliar regime will deliver an unpleasant surprise.

RISK FRAMEWORK

Size positions so that a single trade hitting its stop-loss costs no more than 1-2% of total trading capital. With this threshold, even a losing streak will not wipe out the account, and you retain room to recover.

Place stop-losses at logical points based on market structure or volatility, for example at 1.5x-2.5x Average True Range (ATR, average true range). This gives price room for normal fluctuations while keeping a clear exit point in place.

Keep leverage at a conservative level, typically no higher than 3x-5x for strategies with clearly defined stops. Excessive leverage amplifies not just profit but loss as well, raising the risk of a margin call and forced liquidation.

Finally, run stress tests: put the strategy through extreme historical events or hypothetical adverse scenarios. This reveals the realistic maximum drawdown and shows how well the strategy holds up under pressure, not just in calm conditions.

FAQ

What is the difference between backtesting and forward testing?

Backtesting runs a strategy through historical data, while forward testing launches it in real time on simulated or small live capital. A forward test is needed to confirm backtesting results and account for live execution factors that a historical simulation captures imperfectly: latency, slippage, and the market's reaction to your orders.

Can backtesting guarantee future returns?

No. A backtest shows how a strategy would have behaved on past data, but that is not a promise about the future. Markets change, and patterns that worked before may stop working. Backtesting reduces risk and builds confidence in the logic, but it offers no guarantees whatsoever.

How much historical data is needed for a reliable backtest?

It depends on the trade frequency and volatility. The general rule is that the data should cover several years and include different market phases (bull, bear, sideways). If a strategy has only seen a rising market, its confident numbers are misleading: the first prolonged downturn will reveal its true resilience.

What is overfitting and how do you recognize it?

Overfitting (curve-fitting) happens when you tweak parameters until you get a perfect result on past data, but the strategy loses its meaning outside that sample. The sign: the rules have no market rationale, and even a minor change in the test period sharply destroys the returns. A healthy strategy performs consistently across different stretches of data, even if more modestly.

Why is backtesting without accounting for fees and slippage dangerous?

Because pre-cost profit and post-cost profit are different numbers. A commission of 0.05-0.2% per trade plus slippage on every order can turn a paper-profitable strategy into a money-loser in practice, especially when trade frequency is high. Costs need to be built in from the very start, not dealt with later.

Put this to work in the terminal

Live charts, derivatives, on-chain and macro data, free.

Open terminal →