Day 1 | 12 days to Backtesting Mastery

Day 1: Introduction to Backtesting and Setup
Objective: Master the fundamentals of backtesting, set up TradingView for strategy testing, and conduct your first manual backtest.
1. What is Backtesting?
Definition:
Backtesting is the process of applying a trading strategy to historical market data to determine how it would have performed if executed in the past. It is a critical step in trading because it quantifies the viability of a strategy before risking real capital.
Why It Matters:
- Emotional Discipline: Removes impulsive decisions by forcing you to follow predefined rules.
- Validation: Tests whether a strategy’s logic (e.g., “buy when RSI is oversold”) holds over time.
- Risk Assessment: Reveals worst-case drawdowns, win rates, and risk/reward ratios.
Key Limitations:
- Overfitting: Optimizing a strategy to work perfectly on historical data but failing in live markets (e.g., using too many parameters).
- Survivorship Bias: Testing on assets that have survived market crashes (e.g., ignoring delisted stocks).
- Market Regimes: A strategy that works in a bull market may fail in a bear or sideways market.
Example:
If you backtest a “buy when the S&P 500 rises 2% in a day” strategy from 2010–2020, it may show profits. However, in 2022’s volatile market, this strategy could fail due to different macroeconomic conditions.
2. TradingView Setup for Backtesting
Step 1: Chart Configuration
- Asset Selection: Start with liquid markets (e.g., BTC/USD, EUR/USD, SPX).
- Action: Type
BTC/USD
in the TradingView search bar and select the “Bitcoin vs US Dollar” pair.
- Action: Type
- Timeframe: Use 1-hour (1H) candles for intraday strategies.
- Action: Click the timeframe toolbar at the top and select “1H.”
- Indicators: Add SMA (Simple Moving Average) and RSI (Relative Strength Index).
- Action: Click “Indicators” > Search “SMA” > Set length to 20 > Repeat for SMA 50.
Step 2: Strategy Tester Tool
- Accessing the Tester:
- Action: Click the “Strategy Tester” tab at the bottom of the TradingView interface.
- Selecting a Strategy:
- TradingView’s library includes prebuilt strategies (e.g., “Moving Average Cross”).
- Action: Click “Open” under “Strategies” > Search “Moving Average Cross” > Input SMA 20 and SMA 50.
- Setting the Date Range:
- Start with 3 months of data to minimize overfitting.
- Action: Adjust the backtest date range to “Last 90 days.”
Step 3: Interpreting Results
- Key Metrics:
- Net Profit: Total profit/loss after all trades.
- Win Rate: Percentage of profitable trades.
- Max Drawdown: Largest peak-to-trough loss during the test.
- Profit Factor: (Gross Profit / Gross Loss). A ratio >1 means the strategy is profitable.
3. Manual Backtesting Exercise
Example Strategy: SMA 20/50 Crossover
- Rules:
- Buy: When SMA 20 crosses above SMA 50.
- Sell: When SMA 20 crosses below SMA 50.
- Position Size: Risk 1% per trade (e.g., 1,000account=1,000account=10 risk per trade).
Steps to Backtest Manually:
- Use Replay Mode:
- Action: Click the “Replay” icon (clock with arrow) on the toolbar. This lets you simulate live trading by advancing candles one at a time.
- Track Trades:
- Advance the chart candle-by-candle using the right arrow key.
- When a crossover occurs, note:
- Entry date/price
- Exit date/price (when the reverse crossover happens)
- Profit/loss (P&L)
- Document in a Spreadsheet:
- Action: Create columns for Entry, Exit, P&L, Reason for Trade, and Notes.
10 Things to Do
- Set Up BTC/USD Chart:
- Open TradingView > Search “BTC/USD” > Set timeframe to 1H.
- Add SMA 20 and SMA 50:
- Use the Indicators menu to apply both SMAs.
- Activate Replay Mode:
- Start at the beginning of the 90-day period.
- Simulate 10 Trades:
- Advance candles manually. Enter/exit trades based on crossovers.
- Log Trades in Spreadsheet:
- Record entry price, exit price, P&L, and trade duration.
- Calculate Performance:
- Total Net Profit = Sum of all P&L.
- Win Rate = (Winning Trades / Total Trades) x 100.
- Run Automated Test:
- Use the Strategy Tester with the same SMA crossover rules.
- Compare Results:
- Identify differences between your manual log and automated results.
- Adjust Stop-Loss:
- Edit the strategy in Strategy Tester to include a 2% stop-loss. Rerun the test.
- Reflect on Limitations:
- Write down 3 flaws in this backtest (e.g., no commissions, ideal fills).
Test Yourself
Q: Why might a strategy show a 60% win rate in backtesting but lose money in live trading?
Hint: Consider execution quality and market friction.
Q: How does the “Replay” mode simulate real-time trading psychology?
Q: How does the “Replay” mode simulate real-time trading psychology?
Q: Your manual backtest shows 7 winning trades, but the Strategy Tester reports 10. List 3 technical reasons for this discrepancy.
The Answers
A: Live trading includes slippage (difference between expected and actual fill price) and commissions, which backtesting often ignores. Emotional factors like fear of missing out (FOMO) may also alter decision-making.
A: “Replay” forces you to make decisions with only the data available up to that point, mimicking the uncertainty of live trading.
A:
- The Strategy Tester might use 1-minute data for higher precision, while your manual test used 1H candles.
- Timezone settings could misalign crossover signals.
- The automated test may include after-hours data excluded in your manual test.
Key Takeaway
Backtesting is not a guarantee of future success, but it is a tool to identify probabilities. Today, you learned to set up TradingView, manually track trades, and analyze results. Tomorrow, we’ll dive into strategy optimization and avoiding overfitting.