Backtesting praktyka — framework krok po kroku
Krzysztof rok 1: live trading bez backtest. 8 mies. -€5k losses. Mies. 10: discovered backtesting framework. 60h investment learning + testing. Strategy backtest 5 lat = 60% WR, +20% rocznie. Forward demo 6 mies. confirmed. Live rok 2: +€12k profit. Difference: backtest framework adoption. Tu pokazujemy 7-step process.
Backtesting = test PRZED live
7-step framework
- Define strategy rules: entry, exit, SL, TP all specific objective
- Select historical data: min 5 lat, ideal 10+
- Choose tool: MT4 Strategy Tester, TradingView Pine, Python backtrader
- Run backtest: minimum 100 trades statistical significance
- Analyze metrics: WR, expectancy, Sharpe, max DD, profit factor
- Walk-forward analysis: anti-curve-fit validation
- Forward test demo: 3-6 mies. real-time before live
Tools comparison
Key metrics analysis
- Win Rate (WR): wins / total trades. Target 50-70%
- Expectancy €: average P/L per trade. Target > €15
- R-multiple expectancy: P/L w R-units. Target > 0.3R
- Sharpe ratio: return / std dev. Target > 1.0
- Sortino ratio: return / downside dev. Target > 1.5
- Profit Factor: gross profit / gross loss. Target > 1.5
- Max DD: peak-to-trough %. Target < 20%
- Avg win / avg loss: ratio. Target 1.5+
5 critical pitfalls
Krzysztof framework adoption
MT4 Strategy Tester setup
- Open MT4 → View → Strategy Tester (Ctrl+R)
- Select EA (Expert Advisor)
- Symbol: EUR/USD
- Model: Every tick (accurate), Control points (faster), Open prices (fastest)
- Time period: 5+ lat back
- Spread: current OR custom (use 1.5 pips realistic)
- Optimization: off initial, on dla parameter sweep
- Start → analyze results
TradingView Pine Script
Easy syntax, visual results. Example breakout strategy 30 lines:
- //@version=5 strategy("Breakout Strategy")
- Entry: ta.crossover(close, ta.highest(close, 20))
- Exit: ta.crossunder(close, ta.lowest(close, 10))
- SL: strategy.exit("exit", "long", stop=close * 0.98)
- Apply chart, Strategy Tester tab pojawi się
- Free tier 5,000 bars = 50+ days M15
„Backtest NIE 'shall I trade live?' question. Backtest = 'how does strategy behave historically + ile może live realistic'. Plan around 50% backtest performance dla live. Pleasant surprises rare."
Python backtrader (advanced)
- Free open-source
- Programmatic full control
- Advanced metrics (Sharpe, Sortino, Calmar ratios native)
- Walk-forward analysis customizable
- Monte Carlo overlay integration
- Multi-asset portfolio testing
- Steep learning curve (months Python)
- Pro standard quants
Wnioski
Backtesting = testowanie strategy na historical data PRZED live trading. Essential.
7-step framework: define rules, select data, choose tool, run backtest, analyze metrics, walk-forward, forward test demo.
Tools: MT4 Strategy Tester (free, beginner), TradingView Pine (free tier, easy), Python backtrader (advanced, full control).
Key metrics: WR 50-70%, expectancy > €15 OR 0.3R, Sharpe > 1.0, profit factor > 1.5, max DD < 20%.
5 critical pitfalls: curve-fitting, lookahead bias, survivorship bias, ignoring spread/slippage, insufficient data.
Krzysztof case: 60h framework adoption = €17k swing year 2. ROI massive.
MT4 Strategy Tester: beginner-friendly, EA-based, free.
TradingView Pine Script: easy syntax, visual, free tier 5,000 bars sufficient.
Python backtrader: advanced, walk-forward built-in, Monte Carlo integration.
Realistic expectation: live = backtest × 0.5. Plan accordingly.
Time investment: 40-100h dla quality strategy. NIE shortcut.
Powiązane: walk-forward analysis validation, Monte Carlo complement, expectancy formula baseline.
Źródła i bibliografia
-
Robert Pardo Evaluation and Optimization of Trading Strategies · classic textbook www.amazon.com ↗
-
Python backtrader Open-source backtest library · tools reference www.backtrader.com ↗
-
TradingView Pine Script + Bar Replay · platform docs www.tradingview.com ↗
Najczęstsze pytania
7-step framework details?
Pełny 7-step framework: Step 1: Define strategy rules. Każda zasada specific + objective: entry signal (e.g. "RSI < 30 + price above 200 EMA"), exit signal, SL placement (e.g. "1.5× ATR below entry"), TP placement, position sizing rules. NIE subjective ("look feels right"). Code-able rules. Step 2: Select historical data. Minimum 5 lat dla credibility. 10+ lat ideal. Multiple timeframes if needed. Use real broker data ideally (Tickstory MT4 historical, Dukascopy free). Step 3: Choose tool. MT4 Strategy Tester: free, beginner-friendly, MT4 historical data. TradingView Pine Script: easy syntax, visual backtest report. Python backtrader: free, programmatic, full control, advanced analytics. NinjaTrader/TradeStation: pro platforms with walk-forward built-in. Step 4: Run backtest. Minimum 100 trades dla statistical significance. Common: 500-1000 trades on 5 years M15 data. Settings: starting capital, position sizing, broker fees, slippage assumption. Step 5: Analyze metrics. WR %, expectancy €, Sharpe, max DD, profit factor (gross profit / gross loss), avg win / avg loss, R-multiple distribution. Step 6: Walk-forward analysis. Anti-curve-fit validation. IS optimization, OS test. Step 7: Forward test demo. 3-6 mies. real-time market conditions. Validates backtest assumptions. Total time investment: 40-100 hours dla quality strategy. NIE shortcut.
MT4 Strategy Tester setup?
MT4 Strategy Tester = beginner-friendly tool. Steps: (1) Open MT4. (2) View → Strategy Tester (Ctrl+R). (3) Select Expert Advisor (EA) coding strategy in MQL4 lub use existing free EA. (4) Select symbol (EUR/USD). (5) Select model (Every tick most accurate, Control points faster, Open prices fastest). (6) Time period (start - end dates). (7) Spread (current OR custom). (8) Optimization (off dla initial backtest, on dla parameter sweep). (9) Start. Results show: graph equity curve, statistics tab (total trades, WR, profit factor, expected payoff), report tab (detailed trade list). Coding EA basics: MQL4 syntax. Free EA templates dostępne online. Example simple RSI EA: 50 lines of code. Beginners use existing then modify. Historical data download: Tools → History Center (F2). Download EUR/USD M15, M30, H1, H4 data 5+ years. MT4 default data sometimes incomplete — supplement with Tickstory ($30 download) lub Dukascopy free. Limitations MT4: only EAs (no manual strategy backtest), MT4 historical data quality varies, slow dla large datasets. Speed tip: "Open prices" model 10× faster than "Every tick", but less accurate. Use Open dla initial parameter sweep, Every tick dla final validation. Backtest report: save HTML report dla future reference. Compare backtests over time.
TradingView Pine Script backtest?
TradingView Pine Script = popular dla retail. Pros: easy syntax (close JavaScript), visual results, free tier sufficient many cases, Bar Replay manual backtest possible. Cons: limited data history (free 5k bars, paid 20k bars), TradingView fees commission less granular than MT4, NIE walk-forward built-in. Steps: (1) Open chart EUR/USD. (2) Pine Editor bottom panel. (3) Click "Indicators" → "New Strategy". (4) Code strategy in Pine. (5) Apply to chart. (6) Strategy Tester tab pojawi się. (7) View Performance Summary + List of Trades. Example Pine Script breakout strategy: 30 lines of code. //@version=5 strategy("Breakout Strategy"). Define entry: ta.crossover(close, ta.highest(close, 20)). Exit: ta.crossunder(close, ta.lowest(close, 10)). SL: strategy.exit("exit", "long", stop=close * 0.98). 5 min coding simple strategies. Free vs paid: Free tier = 5,000 historical bars (M15 = 50+ days, Daily = 13+ years). Paid Pro ($14.95/mies.) = 10,000 bars. Pro+ ($29.95) = 20,000 bars. Premium ($59.95) = unlimited. Year 1 = free OK. Bar Replay manual backtest: TradingView tool replay historical data. Step through bars, simulate trade decisions manually. Best dla discretionary traders backtesting visual setups. NIE quantitative metrics, ale realistic experience.
Common pitfalls avoidance?
5 main backtest pitfalls + solutions: (1) Curve-fitting (over-optimization): testing 100+ parameter combinations finds spurious "best". Backtest 80% WR → live 45% WR. Solution: walk-forward analysis, OS validation, parameter stability check. WFE > 50% required. (2) Lookahead bias: accidentally using future data. E.g. SL based on tomorrow's high. Subtle, hard to detect. Solution: code review carefully, separate IS/OS strictly, NIE use information NOT available at trade time. (3) Survivorship bias: backtesting only currently-existing pairs. EUR/USD always exists. But would strategy work on currencies discontinued? Solution: backtest on stable mainstream pairs only OR include delisted historical data. (4) Ignoring spread + slippage: backtest assumes perfect fills at quoted prices. Reality: spread 0.5-2 pips + slippage 0.5-3 pips. EUR/USD scalping 5 pips target = spread costs eat 30-50% profit. Solution: include realistic spread (1-2 pips) + slippage (0.5-1 pip) w backtest. Conservative > optimistic. (5) Insufficient data: 6 months backtest = noise. Strategy worked one regime. Solution: minimum 5 years, 10+ years ideal. Multiple market regimes (low vol, high vol, trending, ranging, crisis). Realistic expectation: backtest performance 30-50% better than live typically. Plan around backtest × 0.5 = live expected. Pleasant surprises rare.