How to Backtest a Trading Strategy?
Have you been practicing with diverse trading instruments and techniques on a demo account and have developed a concrete plan? It is time to backtest the strategy with historical data to check how it will perform before trading the live markets.
Backtesting helps you assess the viability of your strategy and tweak it before you start putting capital into trading. Trading strategies that use expert advisors, trading automation algorithms, and those with complex decision trees need extensive backtesting to prove their effectiveness in different market scenarios.
The purpose of backtesting is to get data based on trading techniques utilised to make more informed decisions on accepting or rejecting them.
A few values that are important to verify while backtesting are:
- Net Profit or Net Loss
- Maximum Volatility Percentage - both upside and downside
- Percentage of Average Gains, Losses, and Bars held
- Risk Exposure and Risk to Reward Ratio
- Win-to-Loss Ratio
- Annualized Return Percentage
Things to Keep in Mind Before Backtesting
Since backtesting allows you to control the market conditions, here are some dos and don’ts of the process:
- Test in bull, bear, and ranging markets. This is because market conditions may vary when you enter live trading with capital, and you need to be prepared for all scenarios.
- Test with relevant instruments and timeframes. For instance, a strategy that showed great results for trading commodities might not work well when you start trading forex in live markets.
- Customise the test environment to mimic that provided by the broker. Change the settings for slippage, commissions, tick, lot sizes, margin, and other essential parameters to obtain more realistic results.
- Over-optimise your results. The goal is to get a relatively profitable strategy, as a perfect one is impossible.
- Consider backtesting as a substitute for trading on a demo account. Backtesting uses historical data, which the demo account uses the current market conditions. Using a combination of both will lend your trading strategy more credibility.
- Tweak or skip unfavourable values for a 'feel good' factor. Continuous winning trades is a red flag. It means your strategy is skewed to that particular dataset.
- Use past information to make current decisions. This is known as look-ahead bias. This means you need to refrain from using data that would not have been available at the point your strategy is tested. For instance, if you are testing a trading strategy on a tech stock on the day when it released earnings after the bell, the news should not interfere with your trading decision of the session before data came out.
How to Automatically Backtest Your Strategy
Use a backtest plugin. Here, you only need to set up the trading technique with or without coding, depending on your expertise and time at hand. You can then select the instrument, trading timeframe, indicators, capital committed, and risk tolerance values and you’re good to go. Click start and the results will be available to you within minutes. Often, these tools are also equipped with capabilities to suggest improvements in your trading strategy to enhance the trading performance.
How to Manually Backtest a Trading Strategy on MT5
Both MetaTrader 4 and MetaTrader 5 support manual and automated backtesting. Follow the steps below to start testing:
Step 1: Download the Data
Select the instrument you wish to test. Open the Bars Tab, chose the Instrument, select the timeframe and click Request. Alternatively, if you have some simulated data or an excel sheet, you can go to Import Bars and get your data.
Step 2: Create Spreadsheets
You need two spreadsheets, one for input and another for output.
Create an input sheet with the following columns:
- Open date
- Open time (if day trading)
- Currency pair
- Stop loss price
- Take profit price
- Long or short
- Pips result
- Pips risk
- Pips to profit target
- Open price
- Close price
- Running balance
- % Risk on trade
- Risk multiple results
- $ P/L
- Win %
Create a result sheet with the columns below:
- System name
- System notes
- Chart timeframe
- Test number
- Win Rate
Now you are ready to start testing.
Step 3: Begin
Select the asset you wish to test and add relevant charts and indicators.
Step 4: Pick Timeframes
It is best to pick timeframes that match your trading style. Ensure that you have a good mix of strongly ranging and trending (up and down) markets as well as non-ranging or trending.
Step 5: Backtest
On the chart, scroll back to the timeframe you wish to text and freeze it by turning Autoscroll off so that it does not move to the latest time after every unit elapses.
Set the start point by pressing Enter Key and start moving one candlestick at a time with the F12 key.
Step 6: Record
Without altering your strategy, record the exact results you receive in your result sheet.
Step 7: Repeat
You can repeat this for as long as you want to test the strategy.
Step 8: Review Your Results
This is the time to critically check the numbers in your result sheet and verify if they align with your trading goals. You can then decide to accept or modify the strategy.
Drawbacks of Backtesting
Often traders focus on getting good backtesting results and end up making a complex strategy that works perfectly only for a specific dataset. However, those shining results are of no use as the strategy is very specific and fails in real markets.
At times, traders fall prey to data dredging, where they create many strategies and test them on the same data. They end up picking the one that works best for that data but fails to give results in real markets as it has not been tested properly across market conditions.
To Sum Up
Backtesting is a critical step in developing a sound trading strategy. It can prove instrumental in optimising your trading technique if done correctly and boost your confidence to enter live markets. Choose from manual or automated backtesting according to your level of expertise.
All data, information and materials are published and provided "as is" solely for informational purposes only, and is not intended nor should be considered, in any way, as investment advice, recommendations, and/or suggestions for performing any actions with financial instruments. The information and opinions presented do not take into account any particular individual's investment objectives, financial situation or needs, and hence does not constitute as an advice or a recommendation with respect to any investment product. All investors should seek advice from certified financial advisors based on their unique situation before making any investment decisions in accordance to their personal risk appetite. Blackwell Global endeavours to ensure that the information provided is complete and correct, but make no representation as to the actuality, accuracy or completeness of the information. Information, data and opinions may change without notice and Blackwell Global is not obliged to update on the changes. The opinions and views expressed are solely those of the authors and analysts and do not necessarily represent that of Blackwell Global or its management, shareholders, and affiliates. Any projections or views of the market provided may not prove to be accurate. Past performance is not necessarily an indicative of future performance. Blackwell Global assumes no liability for any loss arising directly or indirectly from use of or reliance on such information herein contained. Reproduction of this information, in whole or in part, is not permitted.