Backtesting: How to test and refine your trading strategy

Graphic of trading data chart
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.

Related tags: Insights trading Forex

Open an account today

Experience award-winning platforms with fast and secure execution.

Web Trader platform

Our sophisticated web-based platform is packed with features.
Economic Calendar