7 min read

The Ultimate Guide to Backtesting

Backtesting Trading Guide

Backtesting is a methodical approach where traders evaluate the effectiveness of a trading strategy by applying the rules to historical data to see how the trading strategy would have performed. This technique allows traders to simulate a strategy's performance without risking actual capital to find potentially profitable trading strategies.

The process of backtesting involves selecting relevant historical data, applying the rules of the trading strategy, and then analyzing the outcomes to gauge its potential winrate and profitability.

Backtesting is a very important part of the journey of a trader because it serves as a risk-free testing ground for strategies, offering insights that are crucial for informed decision-making in live trading. It enables traders to identify the strengths and weaknesses of their approach, fine-tune parameters, and develop confidence in their strategy before applying it in real-time market scenarios.

The importance of backtesting for traders cannot be overstated. It is a cornerstone in developing and validating trading strategies, ensuring they are robust and adaptable to various market conditions, and helps traders build confidence in their approach. Moreover, backtesting provides empirical evidence to support or refute the effectiveness of a trading strategy, which is invaluable in a field where objective analysis and data-driven decisions are key to success.

 

Benefits of Backtesting

Backtesting is a great way to spend your time as a developing trader and especially three benefits stand out.

 

Risk-free strategy assessment: Performing a backtest does not require a lot of time and within an afternoon, you can easily perform a complete backtest of a strategy to assess the potential performance. Many traders try their strategy on a demo account first but, in my opinion, a backtest is preferable because it takes much less time. Of course, backtest results will never replicate live trading but it is the first important step when it comes to evaluating the potential profitability of a trading strategy.

 

Getting to know the strategy: Within a few hours, you can go through 30 to 50 trades during your backtest. This way, you can quickly improve your pattern recognition and observe the price action of your trading strategy. This is a great way to get to know your strategy and develop a deep understanding of price behavior.

 

Improve your confidence: After you have placed 50 backtest trades, you will have a fairly good understanding of what to expect from your strategy. You have collected performance results on your strategy and get a feeling for how it will play out. This is invaluable for your live trading because you already know what to expect. Knowing the average winrate, holding time, and how frequent losing streaks are can boost your confidence and help you push through drawdowns with a strong mindset.

 

Preparing for Backtesting

Before you get started with your backtest, you have to define a few important parameters.

 

Historical data: The first question that always comes up when backtesting is how much data you should backtest and how far back you have to go. Here we can simply differentiate between the two broad trading strategy types. When you are backtesting a day trading strategy (15-minute timeframe or lower), it is usually enough to go back two to three months and start your backtest there. When you are backtesting a strategy on a higher timeframe, you will have to go back 6 to 12 months.

Ideally, you want to end up with 30 to 50 trades in your backtest to get a meaningful sample size. Anything below 30 trades does not have enough explanatory power.

 

Markets: Whereas some trades just backtest one specific market or instrument to evaluate a trading strategy that only performs well on that market, most traders will typically backtest more than one instrument. When you are backtesting multiple instruments, I recommend choosing non-correlated instruments. Correlated instruments will often show a similar performance during a backtest, and it might skew your results.

 

Trading rules: The goal of a backtest is to evaluate the performance of a trading strategy and, therefore, it is necessary to have a clear plan in mind when it comes to the rules and parameters of your trading strategy. All your backtested trades should look relatively similar and follow the same rules. Before you start backtesting, write out all your trading rules; even better, put them into a checklist format.

You can also search for one perfect trade setup with your chosen rules before you start your backtest. Printing the screenshot of the perfect trade helps you understand what you are looking for.

 

Different exit approaches: This is my favorite tip and a huge time saver that will make your backtesting so much more efficient. Instead of just backtesting one single trading approach, come up with a few different exit scenarios. For example, you can simultaneously test a 2:1 Reward:Risk Ratio, 3:1, 4:1, and a trailing stop loss approach with the same entry rules. Afterward, you can compare which exit strategy would have performed best. This does not require more effort during your backtest but will already help you find a good exit strategy.

 

Backtesting Environment

I like to keep it simple when it comes to my backtesting setup. For the actual backtesting, I use Tradingview´s Bar Replay function. And although it has some limitations (mostly when it comes to testing multiple timeframes), you can usually find a workaround.

With the Bar Replay feature, you can define any previous historical starting point and then just go forward candle by candle. I also like to use Tradingview directly because you can apply all your normally used trading indicators and charting tools.

 

Backtesting Tradingview

 

I find it very important to save screenshots from all the backtested trades for later evaluation. In Tradingview, you can simply save a screenshot with one click and it is automatically downloaded to your computer.

You want to, have at least, save two screenshots per trade. One screenshot from the entry condition and one from the time of the exit. I just create a new folder for each backtest that I perform and then store them on my hard drive.

 

Backtesting Screenshots

 

Now, to the most important part of your backtest: tracking your results.

You can make it as complicated or simple as you´d like but in the beginning, to just get started, I recommend setting up a simple Excel spreadsheet.

I record the date of the trade, the hour of the day, and the type of trading setup of each trade (columns A, B, and C in the screenshot below). Then, I set up multiple columns for the different exit approaches.

In the screenshot below, I have backtested four different exit approaches from 3:1 Reward:Risk Ratio with passive trade management, trailing the stop loss at the 13-period Moving Average, trailing the stop loss at the 30 EMA, and exiting the trade on a price divergence (row 4, columns D - H).

If you are using the Edgewonk trading journal, you can also save your backtest trades with screenshots in there. You will also be able to get a lot more insights into your backtest performance. But if you just want to get into the flow of backtesting, a simple Excel sheet is a great start.

 

Backtesting Results1

 

Evaluating Backtesting Results

When it comes to evaluating the results of your backtest, we can focus on a few important performance and trading metrics. However, it is important to remember that a sample size of at least 30 (ideally 50) trades is necessary to get statistically significant results.

 

R-Multiple: The first and most important question is whether the backtest would have made money. When a backtest shows negative results, the strategy cannot be considered going forward.

You also want to avoid strategies that are barely profitable during a backtest. Your backtest results will always be better than the actual live trading results.

 

Winrate: Although a trading strategy made money during a backtest, if the results show a low winrate, it might be mentally hard to trade such a strategy. A low winrate means more losing trades and the more losses a trader realizes the more likely he is to make mental mistakes. When comparing two backtesting results with similar performance, I would typically go for the one with the higher winrate – even if the results are slightly worse.

 

Holding time: Many traders struggle with holding onto winning trades. A trading strategy with a long holding time is typically harder to trade and traders are more likely to make errors. I would, therefore, advise going for a trading strategy that has a shorter holding time.

 

Growth curve: Finally, I look at the growth curve of the backtested strategy performance. The steadier a growth curve is, the better. In the image below, we see two growth curves side by side. Although the performance of the right one is slightly better, it also shows more volatility. The right strategy has longer sideways periods when the account doesn’t grow and then suddenly makes a leap higher. Such a strategy relies on outliers and large winning trades. The left graph shows a steadier growth which is mentally easier to trade.

 

Backtesting Results2

 

Common Pitfalls in Backtesting

Although backtesting is mostly straightforward, traders need to be aware of some common pitfalls to make sure their backtest provides accurate and helpful results.

 

Overfitting: Overfitting occurs when you backtest the same historical period multiple times and each time you change your trading rules based on your last backtest. Traders will look at their losses and come up with rules on how to avoid them and then backtest the same period again. You will end up with a trading strategy that performs well on your backtesting period, but then fails once you trade it on new data; the strategy is too sensitive and overfitted.

A better approach is to analyze your backtest results, come up with some improvements to your rules, and then backtest the adjusted rules on a completely new historical data period. This is a more robust way of approaching your backtest.

 

Overlooking losses: Being too optimistic and overlooking losses during a backtest can skew your results. The goal of a backtest is to fully test the rules and sort out all the unprofitable and underperforming strategies; the goal of a backtest is not to “win” a backtest and realize paper profits.

I would rather be too pessimistic when it comes to backtesting than end up with a profitable backtest that immediately falls apart during live trading.

 

Time of day: When tracking the backtest results, it is always recommended to track the time of the day for each entry and then verify if the entry would have fallen into your active trading times. When the entry time falls into your nighttime or when you are at work, you cannot count the trade in your backtest since you would not be able to take the trade.

 

Relying on outliers: Looking at the backtest results in the image below, I highlighted a few orange cells. Although the strategy in column F would have realized 16.1 R-Multiple (row 1), 90% of the performance comes from two trades (rows 17 and 29). If a trader misses such outliers, the whole performance falls apart. We already talked about the importance of a steady growth curve previously and relying on outliers for your trading strategy should be avoided.

 

Backtesting Results Outliers

 

Losing streaks: If a trading strategy shows long losing streaks during a backtest, this can also be a red flag. After a long losing streak, emotions will take over, and staying on top of your trading game becomes increasingly harder. I would, therefore, always look for losing streaks in a backtest and avoid strategies with extremely long losing streaks.

 

Conclusion

In conclusion, backtesting stands as a critical component in the toolkit of any trader. It is not just about validating strategies but also about understanding and mitigating potential risks before they manifest in live trading.

However, it's important to approach backtesting with a healthy dose of skepticism and awareness of its limitations. Overfitting, optimism, and skewed performance are just a few pitfalls that can lead to misleading results.

It's also crucial to recognize that backtesting, while valuable, cannot fully replicate the psychological pressures of real-time trading. As such, it should be complemented with other tools and techniques for a more holistic trading strategy. Ultimately, backtesting is about learning and evolving as a trader, continually refining strategies to adapt to the dynamic world of online trading.

The best trading journal

3 min read

Best Trading Journals of 2024: Which One Should You Choose?

Choosing the right trading journal is essential for traders wanting to analyze performance, refine strategies, and improve consistency. In this...

Read More
Continuation Chart Patterns

4 min read

The Best Trend Continuation Chart Patterns

Trading successfully depends on recognizing market structures and patterns that indicate whether an existing trend will continue. Trend continuation...

Read More

3 min read

Turning Losses into Lessons and Building Better Habits (podcast)

No matter how good you are as a trader and how great your trading strategy is performing, sooner or later, you will experience losing trades. What...

Read More