Backtesting: How to test and refine your trading strategy

Article By: ,  Financial Writer

What is backtesting?

Backtesting is a method of testing your trading strategy against historical data before using it in a live market. The process can help confirm strong and weak strategies before ever opening a position. Aside from ensuring your strategy will actually net you winning traders, backtesting also allows you to experiment with various adjustments to your trading strategy without risking your open positions.

Trading strategies serve to establish entry and exit points for both winning and losing trades. They also establish your position size and, if applicable, the amount of margin you are using. Essentially, trading strategies cement when you will buy and sell a security ahead of when you actually trade.

Backtesting a trading strategy can be performed manually using a free demo account or done with specialized trading software. However, backtesting does not guarantee your strategy will be successful. You should always use additional risk management when trading.

Manual backtesting involves analysing historical market data to identify when a trading strategy would have been triggered, then noting how trade would have performed. In a backtesting hypothetical, trades are closed out by take profits and stop losses.

Automated backtesting leaves the analysis to software. The automated system performs the same analysis you would when manually backtesting and adds up all winning and losing hypothetical trades to determine if the strategy is profitable.

How to backtest a trading strategy

To manually backtest a trading strategy, you need access to historical data for the market you intend to trade. Traders are advised to use several weeks of historical data for short-term trading strategies and up to several years of data for long-term strategies.

Once you have a wide breadth of historical market data, you can follow these steps to backtest a trading strategy:

  1. Begin looking for entry points: search through your market data and locate the moments your strategy would be triggered
  2. Follow the trade opportunities through their exit points: analyse the price action following those entry points to see how your trades would perform
  3. Record the outcome of all trades: tally the amounts won and lost from every trade to find the gross return of your trading strategy. It’s important you include each and every trade that would have been triggered by your strategy, even those resulting in large losses
  4. Find the net return: Deduct commission fees and other trading costs from the gross return for a more accurate picture of your potential profit or loss
  5. Calculate a percent return for the total period: Compare your net return over the specified timeframe you analysed to the capital or exposure required to make the trades. This will establish the percent gain or loss you can expect over a given period in relation to the capital you used to trade

The percent return should give you an idea to how successful your trading strategy might be. It is important to check if there are any market anomalies that occurred during the timeframe used or are occurring at the time you intend to trade live. If so, even a successful backtest may be ineffective.

Once you’ve successfully backtested your strategy and are happy with percent return, you can implement your strategy with a FOREX.com trading account. Log in here or open an account in minutes.

If you still want to do further testing, try your strategy in a risk-free environment first with a FOREX.com demo account.

How to automate backtesting

You can automate backtesting using specific trading software. This may be more complicated than just manually backtesting, however. For example, most software requires you to have some grasp of programming and feed the market data into the software.

Some traders claim to use AI like ChatGPT to backtest their trading strategies, but to do so they must input their trading strategy along with all necessary historical market data to get a result. These methods create more opportunities for human error, so they may not be seen as better or worse than manual backtesting.

How to backtest using MT4

MetaTrader 4 (MT4) also has backtesting capabilities using the Strategy Tester tool. To use the tool, you need to build an automated trading program using MT4’s Expert Advisors (EAs). You can then launch the program on the Strategy Tester to receive several reports and quantitative data analysing your trading program.  

How to use backtesting in forex trading

Backtesting a forex trading strategy works the same as in other markets, but there are a few considerations to be aware of.

For starters the forex market is open 24/7, but you should only backtest your trading strategy during periods you plan to trade in. Backtesting a forex strategy using all hours of the day is likely to warp results as humans can’t monitor trades 24/7.

Trading on margin is also a major factor of forex trading. Margin requirements vary by currency pair and can change according to your brokerage. Any changes in margin can affect your net return. FOREX.com will notify you in advance if margin requirements for any currency pair are expected to change. 

How to use backtesting in share trading

Backtesting a trading strategy for shares or indices works similar to the steps outlined above. It’s important to take note of any market-specific events that occur during your timeframe. For short-term strategies, you may want to backtest with historical data from the quarter you plan to trade in. for longer-term strategies, it’s advised you make note of any one-off global/political events that affected the markets.

It’s also important to include an accurate representation of stocks, even those of companies that were sold or went bankrupt. If you were to only include data of companies still around today, your backtest would likely produce artificially high returns.

Backtesting vs future testing

Backtesting is sometimes compared with future testing, also known as paper trading. In general, backtesting examines how your strategy would perform in past markets, and paper trading is a method of testing your strategy against live markets. Paper trading can be executed via a demo account or any other method that does not require you putting down capital to open positions.

Paper trading can produce more accurate results that backtesting. It shows you how your strategy would perform in the current moment. However, it can’t be ‘sped up’ that way backtesting can. When you backtest against historical market data, you are able to aggregate the results of all possible trades within a timeframe and calculate a net return. This means you can aggregate many trades at once when backtesting compared to waiting for each trade to complete with paper trading.

Pros and cons of backtesting

We’ve covered some of the benefits and pitfalls of backtesting already, but let’s directly compare the two. Here is a full summary of backtesting your trading strategies:

Pros of backtesting:

  • It can help raise the chance of successful trades by weeding out bad strategies and confirming better ones
  • You gain a deeper knowledge of financial markets while conducting the backtest on historical market data
  • Backtesting is risk free and faster than trading on a demo account. Using past market data, you can analyse the outcome of a trade instantly. This is especially helpful for long-term strategies

Cons of backtesting

  • Backtesting does not guarantee results. A strategy backtested with a positive net return may not perform as well in live markets for a variety of factors
  • Manually backtesting a strategy can be time consuming and requires manipulating large amounts of data
  • The software required to automate backtesting can be costly or require programming knowledge

Backtesting is a useful tool to refine any quantifiable trading strategy. However, it’s no silver bullet to profitable trades. Proper risk management like stop losses and trailing stops are still advised for every trading strategy. So is practicing your trades in a FOREX.com demo account.

When you’re confident in your strategy and ready to trade live markets, log in to your FOREX.com account or open a trading account.

The information on this web site is not targeted at the general public of any particular country. It is not intended for distribution to residents in any country where such distribution or use would contravene any local law or regulatory requirement. The information and opinions in this report are for general information use only and are not intended as an offer or solicitation with respect to the purchase or sale of any currency or CFD contract. All opinions and information contained in this report are subject to change without notice. This report has been prepared without regard to the specific investment objectives, financial situation and needs of any particular recipient. Any references to historical price movements or levels is informational based on our analysis and we do not represent or warranty that any such movements or levels are likely to reoccur in the future. While the information contained herein was obtained from sources believed to be reliable, author does not guarantee its accuracy or completeness, nor does author assume any liability for any direct, indirect or consequential loss that may result from the reliance by any person upon any such information or opinions.

Futures, Options on Futures, Foreign Exchange and other leveraged products involves significant risk of loss and is not suitable for all investors. Losses can exceed your deposits. Increasing leverage increases risk. Spot Gold and Silver contracts are not subject to regulation under the U.S. Commodity Exchange Act. Contracts for Difference (CFDs) are not available for US residents. Before deciding to trade forex, commodity futures, or digital assets, you should carefully consider your financial objectives, level of experience and risk appetite. Any opinions, news, research, analyses, prices or other information contained herein is intended as general information about the subject matter covered and is provided with the understanding that we do not provide any investment, legal, or tax advice. You should consult with appropriate counsel or other advisors on all investment, legal, or tax matters. References to FOREX.com or GAIN Capital refer to StoneX Group Inc. and its subsidiaries. Please read Characteristics and Risks of Standardized Options.

Please note that foreign exchange and other leveraged trading involves significant risk of loss. It is not suitable for all investors and you should make sure you understand the risks involved, seeking independent advice if necessary.

Contracts for Difference (CFDs) are not available to US residents.

FOREX.com is a trading name of GAIN Capital - FOREX.com Canada Limited, 30 Independence Blvd, Suite 300 (3rd floor), Warren, NJ 07059, USA is a member of the Canadian Investment Regulatory Organization and Member of the Canadian Investor Protection Fund. GAIN Capital – FOREX.com Canada Limited is a wholly-owned subsidiary of Stonex Group Inc.

Complaints are taken very seriously at FOREX.com. You can view our complaints procedure here.

Know your advisor

© FOREX.COM 2024