We have reached the final lesson on complete strategies. After covering multi-timeframe analysis, breakouts, buying at support, moving averages, and combining indicators without redundancy, one decisive question remains: do these rules actually work? Backtesting a trading strategy on historical data separates an idea that merely looks logical on a chart from a statistical edge you can rely on. At the end of this lesson, we move on to the next course, on the trading plan and trader psychology.
What Is Backtesting and Why Does It Matter?
Backtesting means applying predefined entry and exit rules to past data, recording every trade that would have occurred, and then calculating the results. Its goal is not to prove that the strategy is profitable, but to try to break it and expose its weaknesses before the market exposes them with your real money.
Charts deceive the eye: we remember the beautiful trades and forget the ones we skipped and the losers. Systematic testing forces honesty because numbers do not flatter anyone.
How Do You Turn an Idea into Testable Rules?
You cannot test any rule that involves personal judgment, such as "strong trend" or "convincing bounce." Every rule must be convertible into an objective condition. Write your strategy in five parts:
- Trend filter: for example, price closing above the 50-period moving average, or the 20 and 50 averages being in the right order.
- Setup condition: for example, price approaching a defined support zone, using a numeric rule.
- Entry trigger: for example, a candle closing above the previous candle's high, with confirmation from a single indicator.
- Exit: a stop loss (for example, below the latest swing low or at a multiple of the Average True Range) and a target or trailing stop.
- Position size: a fixed percentage of capital risked on every trade.
Remember the lesson on combining indicators: every condition must add new information, because repeating the same information inflates false confidence and reduces the number of trades for no benefit.
Which Metrics Should You Use to Judge the Results?
Win rate alone is misleading. A strategy that wins 35% of its trades can be excellent if the average win is twice the average loss. Watch these metrics together:
| Metric | Meaning | How to read it |
|---|---|---|
| Expectancy | Average profit or loss per trade, in R units of risk | Should be positive, with a margin that covers costs |
| Profit factor | Gross profit ÷ gross loss | Ideally above 1 by a safe margin after costs |
| Maximum drawdown | Largest peak-to-trough drop in equity | Can you tolerate it psychologically and financially? |
| Longest losing streak | Largest number of consecutive losses | A test of your discipline before it is a test of the system |
| Number of trades | Sample size | A small sample proves nothing |
The basic expectancy formula is: win rate × average win − loss rate × average loss. A purely hypothetical example: a 40% win rate with a 2R average win and a 60% loss rate with a 1R average loss gives an expectancy of 0.2R per trade. The system is positive but marginal, and it is highly sensitive to commissions and slippage.
Which Methodological Mistakes Ruin Backtest Results?
Overfitting
The more you tweak parameters to fit the past (indicator periods, stop multiples), the better the historical results become and the worse the future expectations, because you are memorizing noise rather than capturing an edge. The warning sign: excellent results only at one specific parameter value that collapse with a small change. A robust strategy stays acceptable across a wide range of neighboring values.
Look-Ahead Bias
This means using information that was not available at the moment of decision, such as entering at the closing price while assuming the signal was known before it, or using support levels drawn after the move happened.
Survivorship Bias
Testing only on stocks that exist today ignores those that declined or were delisted, so results look better than reality.
Ignoring Costs
Commissions, the bid-ask spread, and slippage can turn a system that is profitable on paper into a losing one, especially for high-frequency strategies or illiquid stocks.
How Do You Test Out of Sample and Check Robustness?
Split your data into two parts: a development sample on which you build the rules, and an out-of-sample set that you do not touch until the rules are finally frozen. If performance deteriorates sharply on the out-of-sample set, the system is probably overfitted. More advanced tools include:
- Walk-forward analysis: you recalibrate on one window, test on the window that follows, and repeat.
- Testing across different markets and timeframes: a real edge shows up, to varying degrees, in more than one asset.
- Splitting performance by market regime: uptrend, downtrend, sideways. Know where the system earns and where it bleeds.
- Monte Carlo simulation: randomly reshuffling the trades to estimate the distribution of likely maximum drawdown, since the historical sequence is just one possibility.
How Do We Apply This Lesson on the Chart?
Before coding anything, visually check how the rules behave on the daily chart. Start with the next image to identify the general context in which the strategy will operate.
In this image, the 20 and 50 moving averages act as the trend filter: the faster average above the slower one, with both sloping upward, means a market suited to buy rules in the direction of the trend, while frequent crossovers mean a sideways market full of false signals. Count how many times the order changes in the image, which gives you a feel for the number of trades and the quality of the filter before you run the automated test.
Here you can see the green support line and the red resistance line. Ask yourself: can these levels be defined by a fixed numeric rule (such as the lowest low over a set number of candles), so that code produces the same level you drew by hand? If not, the rule is subjective and unfit for testing. Also notice how candles and volume behave at each touch, so you can define the confirmation condition.
Below the chart is the RSI panel. It represents price momentum, and it is read by comparing its position with the overbought and oversold zones and its direction at the moment of the signal. Test whether the RSI condition genuinely improves trade expectancy or merely reduces the number of trades. If it does not improve the metrics, remove it, because simplicity is sturdier.
Steps to Apply This with BullMarkets Tools
- Open My Strategies and build the five rules (trend, setup, trigger, exit, position size), then run the test on historical data, keeping the most recent portion of the data unused for out-of-sample validation.
- Use the Technical Scanner to find stocks that currently meet the same conditions, and to confirm that the strategy produces a reasonable number of opportunities rather than very rare signals.
- Review the Signal Log to compare the results of actual signals with what the backtest produced; the gap between them is an honest measure of how overfitted you are.
What Are the Common Mistakes When Backtesting Strategies?
- Adjusting the rules after seeing out-of-sample results, which turns that data into a development sample.
- Judging a system on only twenty trades; a sample large enough to give statistical confidence is better.
- Ignoring maximum drawdown and focusing on total return.
- Believing that a good backtest guarantees the future; it raises the probability, not the certainty.
- Jumping to full capital instead of a trial phase with small size.
- Changing the strategy after a normal losing streak that was already within the backtest's own results.
Frequently Asked Questions
How many trades do I need to backtest a trading strategy?
The larger the sample, the greater the confidence. Dozens of trades are the minimum for a preliminary judgment, and hundreds are better. The sample should also cover different market regimes, not just one rising period.
Is a historical backtest enough to start trading real money?
No. After it comes a paper trading phase, then trading with very small size to measure slippage, execution, and the psychological side, and then you increase size gradually.
What is the difference between in-sample and out-of-sample testing?
In-sample is the data you used to build and refine the rules, and out-of-sample is data you have not seen. The second is the real test because it simulates the unknown future.
What if the results look too good?
Be suspicious. Perfect results are often a sign of look-ahead bias, overfitting, or neglected costs. Try to break the system before you trust it.
Conclusion
- Backtesting is a tool for breaking an idea, not for confirming it.
- Turn every rule into an objective numeric condition before testing.
- Judge by expectancy, profit factor, maximum drawdown, and number of trades, not by win rate alone.
- Beware of overfitting, look-ahead bias, survivorship bias, and ignored costs.
- Test out of sample, with walk-forward analysis, and across different markets and regimes.
- After testing, move to paper trading and then to small size, and you will be ready to build the complete trading plan in the next course.
Disclaimer: This content is purely educational and is not a recommendation to buy or sell any asset. Past results do not guarantee future results.
