What is back testing in trading? 

Backtesting is a fundamental methodology for post-test evaluation, allowing the historical performance of a trading strategy or model to be evaluated. By applying the strategy to past market data, its viability can be accurately determined. Successful backtesting results provide traders and analysts with increased confidence in the strategy’s potential for future implementation. 

Understanding Backtesting, And How It Works 

Backtesting provides a rigorous methodology for simulating trading strategies against historical data, allowing for a comprehensive assessment of potential risk and profitability before risking any actual capital. 

A robust backtest that produces favorable results lends credibility to the underlying principles of the strategy, indicating a higher probability of success in live trading. Conversely, unfavorable backtest results require the strategy to be altered or rejected altogether. 

Any quantifiable trading concept is amenable to backtesting. Implementation often requires working with a skilled programmer to translate the strategy into executable code within the trading platform’s native programming language. 

This process facilitates the incorporation of user-defined parameters, allowing traders to tweak the performance of the system. For example, consider the Simple Moving Average (SMA) crossover system. Programmable input variables allow the lengths of the SMA to be adjusted, allowing traders to backtest to determine which moving average lengths would have performed best on historical data. 

Common Backtesting Measures  

  • Net Profit/Loss: This represents the absolute financial result of the simulated trading strategy, reflecting the total profit or loss achieved during the backtesting period. 
  • Return: Measures the total percentage change in the value of the portfolio, providing a direct measure of overall performance. 
  • Risk-Adjusted Return: Evaluates the return generated relative to the level of risk assumed. This critical measure allows for comparative analysis of strategies with diverse risk profiles. 
  • Market Exposure: Tracks the portfolio’s allocation across different market sectors, revealing the strategy’s sensitivity to specific asset classes or sectors. 
  • Volatility: Measures the magnitude of price fluctuations, indicating the level of risk inherent in the strategy’s returns. 

How to backtest a trading strategy? 

1-Define the trading strategy 

Define a precise, rule-based trading strategy. This strategy should include clear entry and exit triggers, precise position sizing algorithms, and comprehensive risk management protocols. All parameters should be clearly defined. 

2- Obtain historical data 

Collect reliable, high-fidelity historical market data for the target instruments. This data set should contain accurate price, volume, and any additional data required to simulate the strategy. 

Then, define a specific backtesting period. The duration of this backtesting period should be proportional to the strategy’s time frame and desired statistical significance. 

3- Execute the strategy 

Implement the trading strategy formulated according to historical data, simulating the trade execution in real time. Adherence to pre-defined entry and exit criteria is paramount. 

4- Track and Record Results 

 Keep an accurate record of all backtesting process, including exact entry and exit points, trade duration, profit/loss, and any relevant transaction data. 

5- Analyse the results 

Perform a comprehensive performance evaluation based on recorded trading data. Calculate key metrics, including net profit, risk-adjusted returns (e.g., Sharpe ratio), win/loss ratio, and maximum drawdown. 

6- Refine and optimise the strategy 

Based on the analysis of the backtest results, identify areas for strategic improvement. Adjust strategy parameters, refine rules, and improve risk management protocols to maximize performance. 

7- Validate the strategy 

Validate the improved strategy by performing out-of-sample backtests on distinct data sets or time periods. This step is essential to ensure the strategy is robust and performs consistently under diverse market conditions. 

Backtesting vs forward testing  

Forward Testing (Paper Trading) Backtesting Feature 
Prospective performance verification Retrospective performance analysis Purpose 
Real-time, live market data Historical market data Data Source 
Simulated trades in real-time market environment Simulated trades based on historical data Execution 
No actual capital deployed No actual capital deployed  Capital Risk 
Viability and robustness under live conditions Potential performance based on past data Assessment 
Validates strategy in dynamic market conditions Identifies historical performance patterns Key Benefit 
Doesn’t account for psychological impact of real money Does not account for real time slippage, or latency Limitation 

Backtesting vs. Scenario Analysis 

Scenario Analysis Backtesting Feature  
Hypothetical datasets, simulated outcomes Empirical historical market data Data Source 
Model potential future market outcomes Evaluate historical strategy efficacy Purpose 
Simulates specific changes in key market drivers Analyzes past performance based on actual data Methodology 
Prospective risk assessment and stress testing Retrospective performance analysis Focus 
Projecting portfolio impact of adverse events Assessing strategy viability based on history Use Case 
Quantifies potential losses under stress scenarios Identifies historical performance patterns Risk Management 
Hypothetical changes in interest rates, volatility, etc. Actual price movements, volume, etc. Key Drivers 

Manual backtesting on MT4  

– When installing a new MT4, make sure you have enough historical data for the required timeframes (daily, weekly, monthly). Use the History Center (F2) to download or import the required currency pair data. Optimize your data acquisition process by selectively downloading only the necessary timeframes, saving storage and processing resources. (For example, a daily chart backtesting requires only daily data.) 

– Disable auto-scroll to enable manual navigation of the chart history. Use mouse drag or left arrow key to return the chart to its normal position. 

– Learn the basic hotkeys in MT4: F12 (forward one candlestick), Shift+F12 (backward one candlestick).  

Go to the desired historical point and move the chart (F12) until a trading setup appears that matches the strategy criteria. (For example, Morning Star candlestick pattern). 

– When backtesting a new trading strategy manually in MT4, some traders draw entry, stop loss and take profit levels at each trade setup (as I did in the image above). However, this can be tedious – especially if you plan to do a hundred or more backtests. 

The quickest way to backtest is to skip drawing or measuring anything at all unless you need to. Stick to your rules. If the price goes straight to your stop loss, you obviously consider it a loss. If it goes straight to your take profit, you consider it a win. 

When the result of the trade is obvious, there is no need to do anything else. When the result is not so obvious, you can simply measure using the crosshair in MT4 (click the mouse wheel or Ctrl+F). 

In the image above, you can see the same trading setup as before. This time, I simply measured the pips from my entry to my stop loss and then doubled them to get my take profit. 

In both examples, it is easy to see that my trades did not reach the full take profit level. However, by measuring with just the crosshairs, I was able to determine the outcome faster and move on to the next trade. 

What is automated backtesting?  

Automated backtesting involves the use of computer algorithms, also referred to as software, expert advisors (EAs), or robots, to simulate a trading strategy on historical market data. These algorithms are typically coded using the trading platform’s proprietary programming language, such as MQL5, with many platforms offering customization options. 

The basic components of automated backtesting include a manually defined trading strategy, a matching trading robot, and specific execution instructions. This methodology automates the manual backtesting process, allowing traders to efficiently analyze extensive data sets with minimal manual intervention. The procedural steps are as follows: 

  • Robot development: 

Code or customize a trading robot that accurately reflects the defined manual trading strategy. 

  • Instruction specification: 

Provide the robot with precise instructions to execute the strategy and retrieve target performance data. 

  • Platform implementation: 

Deploy the trading robot to the trading platform and initiate the backtesting process. 

  • Performance evaluation and Optimization: 

Analyze the generated results and iteratively refine the trading strategy to achieve optimal performance. 

In conclusion, backtesting is an indispensable tool for any trader aiming for success. Whether done manually or automatically, understanding and mastering this process can provide you with a significant competitive edge in the financial markets. Remember, backtesting is not a guarantee of profit, but it is a crucial step in your journey towards informed and profitable trading. 

Start trading now with a free demo account with Naqdi. 

Related Articles