Backtesting & Strategies

Backtesting: what it is and how to test a strategy before risking money

A step-by-step guide to validating a setup on historical data, reading the right metrics and avoiding the traps that fool most traders.

By Equipe TessTradePublished 5 min read
Backtest: teste uma estratégia passo a passo

Watch the lesson: Backtest: teste uma estratégia passo a passo

Every trader has felt they found the perfect setup: a few great-looking charts, three or four entries that worked and the certainty that it simply works. The problem is that a handful of hand-picked examples says almost nothing about what will happen over the next hundred trades. That is exactly the gap a backtest fills.

In this guide you will learn what backtesting is, how to run an honest test, which numbers to read in the report and which mistakes make a strategy look far better than it really is.

What is backtesting

A backtest is a simulation of a trading strategy on historical price data. You define objective rules for entries, exits and risk management, apply them candle by candle to the past and record the result of each trade as if it had really been taken.

The goal is not to predict the future but to answer questions intuition cannot: how often does this strategy win? How much does it make on average when it wins and lose when it loses? What was the worst losing streak? Does it work in different market phases or only in one specific period?

Why test before trading

Trading without testing means using your own money as a lab. A backtest lets you fail cheaply: you find out in minutes that an idea does not hold up, instead of finding out over months and at a loss.

  • It removes memory bias: we remember the trades that went very well and forget the repeated small losses.
  • It shows the worst phase before it happens: knowing the strategy has already been through eight losses in a row helps you not abandon it at the first stumble.
  • It turns opinion into numbers: "I think it works" becomes "profit factor of 1.4 over 320 trades".

How to backtest in 6 steps

1. Write rules that leave no room for interpretation

"Buy when price is strong" is not testable. "Buy at the close when the 9-period moving average crosses above the 21-period one" is. Every entry, exit, stop and target condition must be objective enough that two different people reach exactly the same result.

2. Choose the instrument, timeframe and a long enough period

The test must cover rising, falling and sideways markets. A period with only one strong trend will favor any trend-following strategy and hide how it behaves when the market moves sideways.

3. Include real costs

Commissions, fees and especially slippage (the difference between the price you wanted and the price you got) eat into results, above all in strategies with many trades and short targets. A strategy that makes little per trade can become a loser once costs are included.

4. Run the test and record every trade

The final result is not enough. The trade list shows whether profit came consistently or from two or three exceptional trades that are unlikely to repeat.

5. Keep data aside for validation

Develop and tune the strategy on one part of the history and confirm the result on another part you did not use while tuning (out-of-sample testing). If performance collapses on the new data, the strategy was probably fitted too closely to the past.

6. Test robustness

Change the parameters slightly: instead of 9 and 21, try 8 and 20, 10 and 22. A robust strategy stays reasonable with small variations. If the result is only good for one exact combination, that is a sign of luck, not of an edge.

The metrics that matter

  • Number of trades: fewer than 30 is too small a sample for conclusions. The more, the better.
  • Win rate: the percentage of winning trades. On its own it does not tell you whether the strategy is good.
  • Payoff ratio: average win divided by average loss. A strategy with a 35% win rate can be excellent if the payoff is high.
  • Profit factor: gross profit divided by gross loss. Above 1 the strategy made money in the period; the more margin, the better.
  • Maximum drawdown: the largest drop in equity from a peak. It is the number that tests discipline the most and defines how much capital the strategy needs.
  • Expectancy per trade: (win rate × average win) − (loss rate × average loss). How much the strategy made, on average, per trade.

These metrics are explained in depth in the guide on win rate, payoff and drawdown.

The mistakes that make a backtest lie

  • Overfitting: tweaking parameters until the equity curve looks perfect. The result becomes a description of the past, not a strategy.
  • Look-ahead bias: using information in the test that would not have been available at decision time, such as the close of a candle that has not closed yet.
  • Ignoring costs and slippage: the most common mistake in day trading strategies with short targets.
  • A short or biased period: testing only the last three months, or only a bull run.
  • Picking the best of hundreds of tests: if you test many variations, some will look great by pure chance.

A backtest is a filter, not a guarantee

A good backtest does not guarantee future profit: markets change, liquidity changes and real execution always has frictions a simulation cannot fully capture. Its role is to quickly discard ideas that do not even hold up in the past and to give statistical confidence to those that survive an honest test. After that, the natural path is to trade the strategy on a demo account or with reduced size before increasing exposure.

How to test on TessTrade

On TessTrade you apply community indicators and strategies to the chart, run backtests on historical data and read the report with win rate, payoff, drawdown and the full trade list. Indicators on the marketplace are written in Python, so you can understand exactly what each rule does before testing it. A good starting point are the trend indicators, whose rules are usually simple to turn into a test. See the features on plans and pricing.

Educational content. Past results, including backtests, do not guarantee future results. Nothing in this article is investment advice.

Educational content. Not investment advice. Trading involves risk of loss, and past results do not guarantee future results.