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 City Index 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 City Index 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. City Index 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 City Index demo account.

When you’re confident in your strategy and ready to trade live markets, log in to your City Index account or open a trading account to gain access to over 13,500 global markets.

This report is intended for general circulation only. It should not be construed as a recommendation, or an offer (or solicitation of an offer) to buy or sell any financial products. The information provided does not take into account your specific investment objectives, financial situation or particular needs. Before you act on any recommendation that may be contained in this report, independent advice ought to be sought from a financial adviser regarding the suitability of the investment product, taking into account your specific investment objectives, financial situation or particular needs.

StoneX Financial Pte. Ltd., may distribute reports produced by its respective foreign entities or affiliates within the StoneX group of companies or third parties pursuant to an arrangement under Regulation 32C of the Financial Advisers Regulations. Where the report is distributed to a person in Singapore who is not an accredited investor, expert investor or an institutional investor (as defined in the Securities Futures Act), StoneX Financial Pte. Ltd. accepts legal responsibility to such persons for the contents of the report only to the extent required by law. Singapore recipients should contact StoneX Financial Pte. Ltd. at 6826 9988 for matters arising from, or in connection with the report.

In the case of all other recipients of this report, to the extent permitted by applicable laws and regulations neither StoneX Financial Pte. Ltd. nor its associated companies will be responsible or liable for any loss or damage incurred arising out of, or in connection with, any use of the information contained in this report and all such liability is hereby expressly disclaimed. No representation or warranty is made, express or implied, that the content of this report is complete or accurate.

StoneX Financial Pte. Ltd. is not under any obligation to update this report.

Trading CFDs and FX on margin carries a high level of risk that may not be suitable for some investors. Consider your investment objectives, level of experience, financial resources, risk appetite and other relevant circumstances carefully. The possibility exists that you could lose some or all of your investments, including your initial deposits. If in doubt, please seek independent expert advice. Visit www.cityindex.com/en-sg/terms-and-policies for the complete Risk Disclosure Statement.

ALL TRADING INVOLVES RISKS. LOSSES CAN EXCEED DEPOSITS.

City Index is a trading name of StoneX Financial Pte. Ltd. (“SFP”) for the offering of dealing services in Contracts for Differences (“CFD”). SFP holds a Capital Markets Services Licence issued by the Monetary Authority of Singapore for Dealing in Exchange-Traded Derivatives Contracts, Over-the-Counter Derivatives Contracts, and Spot Foreign Exchange Contracts for the Purposes of Leveraged Foreign Exchange Trading. SFP is also both Derivatives Trading and Clearing member of the Singapore Exchange (“SGX”). SFP is a wholly-owned subsidiary of StoneX Group Inc.

The information provided herein is intended for general circulation. It does not take into account the specific investment objectives, financial situation or particular needs of any particular person. You should take into account your specific investment objectives, financial situation or particular needs before making a commitment to invest, including seeking advice from an independent financial adviser regarding the suitability of the investment, under a separate engagement, as you deem fit. No representation or warranty is given as to the accuracy or completeness of this information. Consequently, any person acting on it does so entirely at their own risk.

The information does not represent an offer of, or solicitation for, a transaction in any investment product. Any views and opinions expressed may be changed without an update. To understand the risks and costs involved, please visit the section captioned “Important Information” and the “Risk Disclosure Statement”.

The information herein is not directed to, or intended for distribution to or use by, any person or entity who is a citizen or resident of or located in any locality, state, country or other jurisdiction where such distribution, publication, availability or use would be contrary to law or regulation.

StoneX Financial Pte. Ltd. 1 Raffles Place, #18-61, One Raffles Place Tower 2, Singapore 048616. Tel: 6309 1000. Co. Reg. No.: 201130598R.

This advertisement has not been reviewed by the Monetary Authority of Singapore.

© City Index 2024