Cara Backtest di TradingView – Panduan Lengkap 2026
📌 Yang akan Anda pelajari
- Cara setup strategy backtest di TradingView (gratis)
- Membaca metrics: net profit, win rate, drawdown, profit factor
- Mengidentifikasi overfitting dan curve-fitting
- Walk-forward analysis untuk validasi robust
- Realistic expectations dari backtesting
Daftar Isi
Mengapa backtest critical?
Trading strategi tanpa backtest = gambling dengan extra steps. Backtest memberikan jawaban data-driven untuk pertanyaan:
- Apakah strategi ini memiliki edge positif?
- Berapa win rate historis?
- Apa maximum drawdown yang harus saya siap?
- Berapa lama losing streak yang mungkin?
- Risk/reward ratio yang realistis?
Tanpa backtest, Anda trade berdasarkan hope. Dengan backtest, Anda trade berdasarkan data historis.
⚠️ Important caveat
Backtest tidak menjamin masa depan. Pasar berubah. Strategi yang menang di 2020-2024 mungkin tidak menang di 2026+. Tetapi strategi tanpa backtest positif HAMPIR PASTI akan rugi.
Setup strategy di Pine Script
Perbedaan key antara indicator dan strategy:
| Indicator | Strategy |
|---|---|
indicator() | strategy() |
| Plot signals di chart | Eksekusi simulated trades |
| Tidak ada P/L tracking | Full performance metrics |
| Untuk visualisasi | Untuk backtest |
Template strategy lengkap:
//@version=5
strategy("EMA Cross Strategy - Backtest", overlay=true,
initial_capital=10000,
default_qty_type=strategy.percent_of_equity,
default_qty_value=1.0,
commission_type=strategy.commission.percent,
commission_value=0.05,
slippage=2)
// Inputs
fast_length = input.int(9, "Fast EMA")
slow_length = input.int(21, "Slow EMA")
stop_loss_pct = input.float(1.5, "Stop Loss %")
take_profit_pct = input.float(3.0, "Take Profit %")
// Calculations
fast_ema = ta.ema(close, fast_length)
slow_ema = ta.ema(close, slow_length)
// Conditions
long_condition = ta.crossover(fast_ema, slow_ema)
short_condition = ta.crossunder(fast_ema, slow_ema)
// Strategy logic
if long_condition
strategy.entry("Long", strategy.long)
if short_condition
strategy.entry("Short", strategy.short)
// Stop loss & Take profit (in %)
long_stop = strategy.position_avg_price * (1 - stop_loss_pct / 100)
long_target = strategy.position_avg_price * (1 + take_profit_pct / 100)
short_stop = strategy.position_avg_price * (1 + stop_loss_pct / 100)
short_target = strategy.position_avg_price * (1 - take_profit_pct / 100)
if strategy.position_size > 0
strategy.exit("Exit Long", "Long", stop=long_stop, limit=long_target)
if strategy.position_size < 0
strategy.exit("Exit Short", "Short", stop=short_stop, limit=short_target)
// Plots
plot(fast_ema, "Fast EMA", color.blue)
plot(slow_ema, "Slow EMA", color.orange)Komponen utama strategy:
- initial_capital: Modal awal untuk simulasi ($10.000 default)
- default_qty_type: percent_of_equity (% akun per trade)
- default_qty_value: 1.0% = 1% risk per trade
- commission_type/value: Realistic broker commission
- slippage: 2 ticks untuk realistic execution
Strategy Tester: cara membaca hasil
Setelah Add to chart, klik tab Strategy Tester di bawah chart. Ada 4 tabs:
Tab 1: Overview
Summary statistik kunci:
- Net Profit: Total profit/loss dari semua trades
- Total Closed Trades: Jumlah trades selesai
- Percent Profitable: Win rate
- Profit Factor: Gross profit / gross loss
- Max Drawdown: Decline maksimum dari peak
Tab 2: Performance Summary
Breakdown long vs short, average trade size, dll.
Tab 3: List of Trades
Setiap trade dengan entry, exit, size, P/L. Berguna untuk pattern recognition.
Tab 4: Properties
Konfigurasi yang digunakan untuk backtest.
Metrics yang penting
1. Net Profit (Total P/L)
Apa yang baik: Positive setelah commission dan slippage
Apa yang dipertanyakan: 1000%+ “returns” sering indicator overfitting
2. Win Rate
Realistic ranges:
- Trend following: 35-45%
- Mean reversion: 55-70%
- Breakout: 40-55%
- Scalping: 55-65%
Red flag: Win rate >80% sering indikator overfitting atau strategy yang kompleks excessively.
3. Profit Factor
Ratio gross profit / gross loss. Target: >1.5 minimum, >2.0 ideal.
4. Max Drawdown
Decline maksimum dari peak akun. Target: <25%, ideal <15%.
Drawdown lebih tinggi = lebih banyak psikologis stress saat trading live.
5. Sharpe Ratio
Risk-adjusted return. >1.0 = bagus, >1.5 = sangat bagus, >2.0 = elite.
6. Average Trade
Net P/L per trade. Harus positif setelah commission. Jika negatif, strategy losing per trade.
Overfitting: musuh utama backtest
Overfitting (curve-fitting) adalah ketika strategy dioptimasi terlalu spesifik untuk data historis, sehingga tidak akan bekerja di data masa depan.
Tanda-tanda overfitting:
- 🚩 Parameter “magic numbers” yang sangat spesifik (e.g., EMA 17.5, RSI threshold 33.7)
- 🚩 Win rate >80% di backtest
- 🚩 Strategy menggunakan 10+ kondisi kompleks
- 🚩 Performance dramatically berubah dengan parameter kecil
- 🚩 Hanya bekerja di 1 pair/timeframe spesifik
Cara menghindari overfitting:
- Use round numbers: EMA 21, RSI 30/70, MACD default
- Test di multiple pairs: jika strategi hanya bekerja di EUR/USD tapi tidak GBP/USD = suspect
- Test di multiple timeframes: bagus jika bekerja di H1 dan H4
- Out-of-sample testing: optimize di 2020-2022, validasi di 2023-2024
- Walk-forward analysis: rolling re-optimization
⚠️ Test ini
Setelah backtest yang “sempurna”, ubah salah satu parameter secara signifikan (e.g., EMA 21 → EMA 20). Jika hasil dramatically berbeda, strategy overfitted. Jika robust, hasilnya akan similar (mungkin sedikit lebih buruk).
Walk-forward analysis
Walk-forward adalah gold standard untuk validasi backtest:
Konsep:
- Bagi data historis menjadi periods (e.g., 6 bulan masing-masing)
- Optimize parameter di Period 1
- Test di Period 2 (out-of-sample) dengan parameter terbaik
- Re-optimize untuk Period 3 menggunakan Period 1+2
- Test di Period 4
- Continue rolling
Cara melakukan di TradingView:
TradingView tidak memiliki built-in walk-forward, tetapi Anda dapat manual:
- Set chart range ke Jan 2020 – Jun 2020 (6 bulan)
- Optimize strategy parameters dengan trial-and-error
- Catat parameters terbaik
- Set chart range ke Jul 2020 – Dec 2020
- Apply parameters dari step 3
- Lihat performance
- Repeat untuk periods berikutnya
Jika strategy konsisten positif di out-of-sample periods, edge mungkin nyata. Jika hanya menang di in-sample, overfitted.
Realistic expectations
📊 Real backtest results untuk strategi retail
- Net profit tahunan: 15-40% (good strategy)
- Win rate: 40-65% tergantung style
- Max drawdown: 10-25%
- Profit factor: 1.3-2.0
- Sharpe ratio: 0.8-1.5
Jika backtest Anda menunjukkan:
- 500%+ return per tahun = overfitted, tidak akan bekerja live
- Drawdown < 5% = terlalu bagus untuk dipercaya, kemungkinan bug atau curve-fit
- Win rate > 85% = highly suspect, periksa logic strategy
Backtest → Live transition:
Realistic degradation: live performance biasanya 50-70% dari backtest. Strategi yang menunjukkan +30%/tahun di backtest mungkin hanya +15-21%/tahun di live (karena slippage real, eksekusi imperfect, market changes).
Plan untuk drawdown 1.5-2x maksimum backtest drawdown saat live trading.
FAQ
Minimum 1-2 tahun, ideal 3-5 tahun. Lebih lama = lebih banyak market regimes (trending, ranging, volatile). Strategi yang menang di 3+ tahun lebih reliable.
Ya. Strategy Tester sama di Free dan Pro. Yang berbeda hanya jumlah simultaneous strategies dan extended data history.
Set commission 0.05-0.1% per side (untuk forex retail) dan slippage 2-5 ticks. Untuk crypto: 0.1-0.2% per side. Beberapa broker mahal: 0.5%+ per side.
