Understanding Backtesting and Optimization: How to Test and Improve Your Trading Strategy %%page%%



Have you ever written an exam? If you have, it’s safe to say you prepared using past question papers. Most people attempt them under exam conditions. The goal is to determine if the approach and strategy you have been using to study are actually effective. By going through past papers, you can see where your strengths lie and where you need to improve. Backtesting your trading strategy works the same way in trading, which means you take a trading strategy you plan to use, apply it to past market data, and then record the results. This process shows you where your strategy performs well and where it fails, so you refine it before risking real money, the same way past papers help you fix weak areas before your exam day.
In this article, we will cover:
- What is backtesting, and why does it matter?
- How to properly set up a backtesting session.
- How to optimize and refine your trading strategy.
- Common pitfalls to avoid when backtesting.
What is backtesting?
Backtesting is the process of evaluating a trading strategy by applying its rules to historical market data to see how it performed in the past. To do this, you enter trades exactly where your rules tell you to enter, and you exit trades only where your rules define the exit. During this process, you respect your pre-written rules without making changes.
Backtesting helps traders to understand the risks associated with a strategy without using real money. While it doesn’t guarantee future results, it helps traders make informed decisions and prepare for live trading with more confidence.
Example
This is what pre-written rules look like for a trader called Bryan. His rules are to trade only $GBPUSD, enter only after a liquidity sweep above a high or below a low, set a 20-pip stop loss, and an 80-pip take profit. He does not change any of these rules while backtesting. By following them strictly, Bryan can record which trades would have won, which would have lost, and identify patterns in performance across sessions.
How to properly set up a backtesting session
Step 1: Define Your Trading Strategy
| “The essence of strategy is choosing what not to do.” — Michael Porter, renowned American economist and professor at Harvard Business School. |
Before you test anything, your strategy must be clearly stated because defining your trading strategy is a crucial step in your backtesting session. It sets direction for every decision. This step involves outlining the rules and criteria that comprise the trading strategy you wish to test.
For example, consider Bryan. In his backtesting example, he trades GBPUSD using a liquidity sweep strategy. His rules are clear:
- Enter after a liquidity sweep above a high or below a low.
- Set a 20-pip stop loss.
- Set an 80-pip take profit.
By clearly defining his strategy first, Bryan ensures that every trade he records in his backtesting sheet follows consistent rules. This step anchors your session and makes the results meaningful. Without a defined strategy, backtesting becomes random and unreliable.
Step 2: Choose a Backtesting Platform with Quality Historical Data
High-quality market data and the tool you will use to test it are essential for reliable backtesting. Platforms like MetaTrader 4 and 5, TradingView, FX Replay, and TradeZella provide historical price data along with features to replay and analyze it. These tools let you practice entries, exits, and rule execution while ensuring results reflect real market conditions. TradingView works well for new and intermediate traders who want to understand price behavior, market structure, and liquidity. You can replay historical price action and see how your strategy performs across sessions. This ensures that your results are meaningful and reflective of actual market conditions. Choose a tool that is easy to use, fits your level of technical knowledge, and allows you to run repeatable tests.
For higher precision, you can add data from some brokers that provide tick-level data, volume, and depth of market.
| Brokers may include Eightcap, IC Markets, Pepperstone, ThinkMarkets, and FXCM. |
Step 3: Execute the trading strategy
Apply your defined strategy to the historical data, simulating trades as if executed in real time. Here’s how you execute:
- Pick a point on historical price data as your starting moment.
- Follow your entry rules: check if conditions for a trade are met.
- Record the trade: note the pair, session, entry price, stop loss, take profit, and reason.
- Follow exit rules: when your conditions say to exit, record the exit price and result (win/loss).
- Move to the next trade: continue through the historical data without skipping steps or changing rules.
Once trades are executed, it’s time to see where the strategy performs best and where it fails. This is the start of optimization.
How To Optimize and Refine Your Trading Strategy
Optimization is the process of finding where your strategy is lacking after you have executed it on historical data. It involves fine-tuning your strategy using insights from your backtest so it performs more effectively in real market conditions. You take the rules you have already tested and adjust them to find the settings that produce the most profitable results.
Optimizing turns the backtested data into actionable decisions. Step 4 focuses on analyzing these results so you can spot patterns, weaknesses, and areas where your strategy can be refined.
Step 4: Analyze the Results
Analysis is where optimization begins, because you can only improve a strategy once you understand how it performs. To do this, you need a complete record of all trades, which lets you study patterns and see how your rules behave across pairs, sessions, and conditions. Bryan has already executed his strategy in backtesting, following his defined rules consistently. By reviewing his trades, we can see exactly which setups worked, which failed, and under what circumstances. This is what his results look like:
| Trade | Pair | Session | Stop Loss | Take Profit | Reason for Trade | Result |
| 1. | GBPUSD | London | 20 | 80 | Liquidity sweep above high | Win |
| 2. | GBPUSD | London | 20 | 40 | Liquidity sweep above high | Win |
| 3. | GBPUSD | Asian | 20 | 80 | Liquidity sweep above high | Loss |
| 4. | USDJPY | Asian | 20 | 80 | Liquidity sweep below a low | Loss |
| 5. | USDJPY | Asian | 20 | 80 | Liquidity sweep above high | Loss |
| 6. | GBPUSD | London | 20 | 80 | Liquidity sweep above high | Win |
Using Bryan’s results, optimization insights appear quickly. Every time Bryan traded USDJPY instead of his primary pair, he recorded a loss. All his losses occurred during the Asian session. His London session trades produced wins only. One trade used a 40-pip take profit instead of the planned 80 pips, which broke consistency.
This analysis shows where the strategy holds up and where it fails. In Bryan’s case, his wins happened when he followed his planned pair and traded the London session. His losses occurred whenever he deviated from these rules, showing exactly what needs adjustment.
Step 5: Tweak Your Strategy
Tweaking your strategy is applied optimization. You adjust only what the data proves needs adjustment. For Bryan, the optimization path is clear. He should remove the Asian session from his plan. He should focus on his primary pair instead of switching instruments. He should keep his take profit fixed at 80 pips to maintain consistency.
These tweaks improve stability and risk control. They also set realistic expectations. Bryan now understands which conditions support his strategy and which ones damage it. Optimization refines an existing edge. It prepares you to trade with rules you trust and data you understand.
Common pitfalls to avoid when backtesting
1. Lack of a Written Plan.
The first step in any backtesting session is a written plan, as discussed above. You must define what you want to test, which data you will collect, and how you will review performance. To ensure you don’t make this mistake:
| Create a short blueprint you follow every time. Define what you will test, the criteria you will use, and the parameters you will apply. Write this blueprint before you collect any data |
2. Ignoring transaction costs.
Overlooking slippage and commissions is a common mistake. These costs directly affect your results. Ignoring them creates an inflated view of performance and makes your backtesting unreliable. Profits you see without these costs will not exist in live trading. You must treat slippage and commissions as part of the strategy.
| Solution: Build cost assumptions into your test. Use historical data to estimate slippage for each pair. Apply your broker’s real commission rate. This gives you results that behave closer to live conditions. |
3. Insufficient trade samples.
Relying on a small sample size weakens your analysis. You base conclusions on limited data. Many traders review a small number of trades and feel confident. This confidence is false. Small samples hide how a strategy behaves over time.
In Bryan’s case, seven trades are not backtesting. Seven trades show nothing about consistency, drawdowns, or risk. Bryan needs dozens or hundreds of trades to see real performance.
| Solution: Backtest the strategy across many trades and long time periods until the data shows consistent behavior. |
4. Underestimating Psychological & Emotional factors.
When we talk about trading, a huge part of success comes from understanding the psychological & emotional traps that sneak into every backtest and trade review. These factors may distort how you see data and make you believe your system works better than it actually does. You might focus only on trades that went well, ignore losses, or interpret every movement as confirmation of what you already believe. This creates a picture of the market filtered through your personal lens instead of reality. For example, you could log only winning trades, dismiss losses as bad luck, or pick clean, smooth periods to study. Over time, this makes your strategy look consistent on paper but fragile in real conditions.
| Solution: You need strict, consistent processes. Log every trade, wins, and losses, with context. Include setups, conditions, and even your emotional state. Replay charts candle by candle before revealing outcomes to capture true decision-making. |



