Skip to main content
Skip to main content
Version: 1.0 (Current)

Backtesting Basics

Learn how to test your trading strategies against historical data before risking real capital. This tutorial covers everything from running your first backtest to interpreting results and identifying strategy weaknesses.

What is Backtesting?

Backtesting simulates how your strategy would have performed using historical market data. It answers the critical question: "Would this strategy have been profitable in the past?"

Why Backtest?

  • Validate Strategy Logic: Ensure your rules work as intended
  • Estimate Performance: Get realistic expectations for returns and drawdowns
  • Identify Weaknesses: Find flaws before losing real money
  • Build Confidence: Trade with conviction knowing your strategy has edge
  • Optimize Parameters: Find the best settings for your strategy
Important

Past performance doesn't guarantee future results, but it's the best tool we have for strategy validation.

Your First Backtest

Step 1: Navigate to Backtests

  1. Log in to your x3Algo dashboard
  2. Click Backtests in the sidebar
  3. Click New Backtest button

Step 2: Select Algorithm

Choose the algorithm you want to test:

Algorithm: My First MA Crossover

Step 3: Configure Backtest Parameters

Date Range

Start Date: 6 months ago
End Date: Today

Guidelines:

  • Minimum: 3 months (too short = unreliable)
  • Recommended: 6-12 months (good balance)
  • Maximum: 2-3 years (more data = better)
Date Range Selection
  • Include different market conditions (trending, ranging, volatile)
  • Avoid cherry-picking profitable periods
  • Test through market crashes if possible
  • More data = more reliable results

Initial Balance

Initial Balance: ₹100,000

Use your actual intended trading capital for realistic results.

Symbols

Symbols: NSE:RELIANCE

Start with one symbol, then expand to multiple.

Slippage

Slippage: 0.1%

Slippage is the difference between expected and actual execution price.

Realistic Values:

  • Liquid stocks (RELIANCE, TCS): 0.05-0.1%
  • Mid-cap stocks: 0.1-0.2%
  • Small-cap stocks: 0.2-0.5%
  • Commodities: 0.1-0.3%
Don't Ignore Slippage

Backtests without slippage are unrealistic. Always include it!

Commission

Commission: 0.03% per trade

Typical Broker Fees:

  • Discount brokers: 0.03-0.05% per trade
  • Full-service brokers: 0.1-0.3% per trade
  • Add STT (0.025% for intraday, 0.1% for delivery)
  • Add GST (18% on brokerage)

Example Total Cost:

Brokerage: 0.03%
STT: 0.025%
GST: 0.005%
Total: 0.06% per trade

Step 4: Run Backtest

Click Run Backtest and wait for results (usually 10-30 seconds).

Understanding Backtest Results

Performance Metrics

Total Trades

Total Trades: 42

Interpretation:

  • < 20 trades: Not enough data, unreliable
  • 20-50 trades: Acceptable for initial validation
  • 50-100 trades: Good statistical significance
  • > 100 trades: Excellent, very reliable

Win Rate

Win Rate: 52%

Formula: Winning Trades / Total Trades × 100

Interpretation:

  • < 40%: Poor, strategy needs work
  • 40-50%: Acceptable for trend-following
  • 50-60%: Good
  • 60-70%: Excellent (mean reversion)
  • > 70%: Suspicious, check for overfitting
Win Rate Context
  • Trend-following: 40-50% is normal
  • Mean reversion: 55-65% is normal
  • High win rate doesn't guarantee profitability
  • Need to consider average win vs average loss

Profit Factor

Profit Factor: 1.85

Formula: Gross Profit / Gross Loss

Interpretation:

  • < 1.0: Losing strategy
  • 1.0-1.5: Marginal, needs improvement
  • 1.5-2.0: Good
  • 2.0-3.0: Excellent
  • > 3.0: Suspicious, check for errors

Example:

Gross Profit: ₹18,500
Gross Loss: ₹10,000
Profit Factor: 18,500 / 10,000 = 1.85

Total Return

Total Return: +15.2%

Interpretation:

  • Compare to buy-and-hold return
  • Adjust for time period (annualize if needed)
  • Consider risk-adjusted returns (Sharpe ratio)

Annualized Return:

6-month return: 15.2%
Annualized: 15.2% × 2 = 30.4%

Maximum Drawdown

Max Drawdown: -8.5%

Definition: Largest peak-to-trough decline in account value.

Interpretation:

  • < 10%: Excellent, low risk
  • 10-20%: Good, acceptable
  • 20-30%: High, requires strong conviction
  • > 30%: Very high, most traders can't handle

Example:

Peak: ₹115,000
Trough: ₹105,000
Drawdown: (105,000 - 115,000) / 115,000 = -8.7%
Psychological Impact
  • Most traders abandon strategies after 15-20% drawdown
  • Your max drawdown will likely be 1.5-2× backtest drawdown
  • Ensure you can psychologically handle 2× the backtest drawdown

Sharpe Ratio

Sharpe Ratio: 1.65

Definition: Risk-adjusted return (return per unit of risk).

Formula: (Return - Risk-Free Rate) / Standard Deviation

Interpretation:

  • < 0.5: Poor risk-adjusted returns
  • 0.5-1.0: Acceptable
  • 1.0-2.0: Good
  • 2.0-3.0: Excellent
  • > 3.0: Exceptional (rare)

Average Win vs Average Loss

Average Win: ₹850
Average Loss: ₹420
Ratio: 2.02

Interpretation:

  • < 1.0: Losing more than winning (bad)
  • 1.0-1.5: Acceptable
  • 1.5-2.5: Good
  • > 2.5: Excellent

Relationship with Win Rate:

Win Rate: 45%, Avg Win/Loss: 2.0 → Profitable
Win Rate: 60%, Avg Win/Loss: 1.2 → Profitable
Win Rate: 35%, Avg Win/Loss: 3.0 → Profitable

Equity Curve Analysis

The equity curve shows your account balance over time.

Healthy Equity Curve

Characteristics:
- Steady upward slope
- Smooth progression
- Drawdowns recover quickly
- No extended flat periods

Problematic Equity Curve

Warning Signs:
- Erratic, choppy movement
- Long flat periods (no growth)
- Deep drawdowns that don't recover
- All profits from one lucky trade

Trade Distribution

Winning Trades Distribution

Small wins: 15 trades (₹200-500)
Medium wins: 8 trades (₹500-1000)
Large wins: 3 trades (₹1000+)

Healthy Distribution:

  • Mix of small, medium, and large wins
  • Not dependent on a few outliers
  • Consistent profit-taking

Losing Trades Distribution

Small losses: 12 trades (₹200-400)
Medium losses: 4 trades (₹400-800)
Large losses: 0 trades (₹800+)

Healthy Distribution:

  • Most losses are small
  • Few medium losses
  • No large losses (stops working)

Identifying Strategy Weaknesses

Problem 1: Low Win Rate (<40%)

Possible Causes:

  • Entry conditions too loose
  • No trend filter
  • Entering counter-trend
  • Poor timing

Solutions:

  • Add confirmation candles
  • Require trend alignment
  • Add volume filter
  • Use higher timeframe confirmation

Problem 2: Low Profit Factor (<1.5)

Possible Causes:

  • Stops too tight (getting stopped out)
  • Targets too close (not letting winners run)
  • Poor risk-reward ratio

Solutions:

  • Widen stops (use ATR)
  • Extend targets
  • Implement trailing stops
  • Use multiple profit targets

Problem 3: High Drawdown (>20%)

Possible Causes:

  • Position sizes too large
  • No daily loss limit
  • Too many concurrent positions
  • No stop losses

Solutions:

  • Reduce position size
  • Implement daily loss limit
  • Limit open positions
  • Always use stop losses
  • Add circuit breaker

Problem 4: Too Few Trades (<20)

Possible Causes:

  • Entry conditions too strict
  • Testing period too short
  • Symbol not active enough

Solutions:

  • Relax entry conditions
  • Extend backtest period
  • Add more symbols
  • Use shorter timeframe

Problem 5: Inconsistent Results

Possible Causes:

  • Strategy depends on market regime
  • Overfitted to specific period
  • Few large wins skew results

Solutions:

  • Test across different periods
  • Add regime filters
  • Use walk-forward optimization
  • Run Monte Carlo simulation

Common Backtesting Pitfalls

1. Look-Ahead Bias

Problem: Using future information not available at trade time.

Example:

❌ Bad: Use today's close to calculate today's signal
✅ Good: Use yesterday's close to calculate today's signal

How x3Algo Prevents This:

  • Signals calculated on previous candle close
  • No future data leakage
  • Realistic execution simulation

2. Survivorship Bias

Problem: Only testing on stocks that still exist today.

Example:

❌ Bad: Test on current NSE 50 stocks
✅ Good: Test on historical NSE 50 composition

Impact:

  • Inflates returns (excludes delisted losers)
  • Unrealistic performance expectations

3. Curve Fitting (Overfitting)

Problem: Optimizing parameters until backtest looks perfect.

Example:

❌ Bad: Test 100 parameter combinations, pick best
✅ Good: Use logical parameters, validate out-of-sample

How to Avoid:

  • Use walk-forward optimization
  • Test on out-of-sample data
  • Keep parameters simple
  • Require logical reasoning for settings

4. Ignoring Transaction Costs

Problem: Not including slippage, commissions, taxes.

Impact:

Without costs: +25% return
With costs: +12% return
Reality: Costs cut returns in half!

Always Include:

  • Slippage (0.1-0.2%)
  • Brokerage (0.03-0.05%)
  • STT (0.025-0.1%)
  • GST (18% on brokerage)

5. Cherry-Picking Periods

Problem: Only testing during favorable market conditions.

Example:

❌ Bad: Test only during 2020-2021 bull market
✅ Good: Test through 2018 correction, 2020 crash, 2021 rally

Solution:

  • Test minimum 6-12 months
  • Include different market regimes
  • Test through crashes if possible

Backtest Checklist

Before trusting your backtest results:

  • Sufficient trades: Minimum 30 trades
  • Adequate period: Minimum 6 months
  • Realistic costs: Included slippage and commissions
  • Multiple symbols: Tested on 2-3 stocks minimum
  • Different periods: Tested across various market conditions
  • Logical parameters: Settings make sense, not overfitted
  • Acceptable drawdown: Can psychologically handle 2× the max drawdown
  • Positive expectancy: Profit factor > 1.5
  • Consistent equity curve: Steady growth, not one lucky trade
  • Reasonable win rate: Appropriate for strategy type

Next Steps

1. Run Multiple Backtests

Test variations:

  • Different symbols (NSE:TCS, NSE:INFY)
  • Different periods (2022, 2023, 2024)
  • Different parameters (EMA 9/21 vs 12/26)

2. Optimize Parameters

Find optimal settings:

  • Test parameter ranges systematically
  • Use walk-forward optimization
  • Validate on out-of-sample data

Learn more: Strategy Optimization

3. Paper Trade

Validate in real-time:

  • Run paper trading for 2-4 weeks
  • Compare to backtest results
  • Check for execution issues
  • Monitor slippage

Learn more: Paper to Live Transition

4. Go Live Carefully

When ready:

  • Start with small position sizes
  • Monitor closely for first week
  • Track actual vs expected performance
  • Scale up gradually

Summary

You've learned how to:

  • ✅ Run your first backtest
  • ✅ Configure realistic parameters (slippage, commissions)
  • ✅ Interpret performance metrics (win rate, profit factor, Sharpe ratio)
  • ✅ Analyze equity curves and trade distributions
  • ✅ Identify strategy weaknesses
  • ✅ Avoid common backtesting pitfalls
  • ✅ Validate results before going live

Key Takeaways:

  • Backtesting is essential but not perfect
  • Always include realistic costs
  • Need minimum 30 trades for reliability
  • Past performance ≠ future results
  • Use backtesting as one tool among many
  • Validate with paper trading before going live

Remember: A good backtest is necessary but not sufficient. Always paper trade before risking real capital!

Ready to optimize your strategy? Check out the Strategy Optimization Walkthrough next!