Audit TradingView Strategy Tester reports—Net Profit, Max Equity Drawdown, Profit Factor, trade count—model realistic costs, eliminate request.security() repainting, and link to walk-forward rules. Once Lesson 609's strategy() hits your chart, TradingView's Strategy Tester immediately computes performance metrics and an equity curve. Yet most systems that fail after going live fail not because the market changed, but because unexamined execution assumptions or subtle look-ahead leakage inflated the backtest.
This capstone brings the statistical and execution-audit rules of Lesson 583, Lesson 585, and Lesson 586 directly into your TradingView code review.
1. Auditing Strategy Tester tabs: returns, drawdown, PF, and sample size
Inspect Strategy Tester across all three tabs—Overview, Performance Summary, and List of Trades—and never evaluate a single headline metric in isolation:
| Strategy Tester Metric | Audit Standard | Common Interpretation Trap |
|---|---|---|
| Net Profit vs. Buy & Hold | Compare return and risk relative to passive benchmark | +85% net profit during a +160% bull market with similar DD adds no edge |
| Max Equity Drawdown % | Audit intra-trade equity DD, not closed-trade DD alone | Closed trades can look smooth while open intra-trade losses breach risk caps |
| Profit Factor (PF) | Gross Profit ÷ Gross Loss (target ≥ 1.4–1.5 net of costs) | Tiny sample sizes let 1 or 2 lucky outliers inflate PF above 3.0 |
| Win Rate × Avg Win/Avg Loss | Verify positive expectancy: (W × Payoff) − (1 − W) | A 75% win rate collapses if occasional unstopped losses wipe −5R |
| Total Closed Trades | Minimum sample size (prefer 30–100+ trades across regimes) | 12 trades over 3 years is noise indistinguishable from chance (Lesson 588) |
2. Transaction costs, calc_on_every_tick, and close-fill traps
Three execution flags routinely turn mediocre systems into deceptive backtest superstars (Lesson 585, Lesson 586):
- Zero commission / zero slippage: Omitting
commission_value=0.05(0.10% round-trip) andslippage=2ticks flatters high-turnover strategies that lose money once real market friction applies. calc_on_every_tick=truetrap: Historical bars contain only 4 OHLC prints, forcing TradingView to simulate an assumed intra-bar path when tick evaluation is enabled—rarely matching live order fills.process_orders_on_close=truetrap: Assumes you observe the exact 16:00:00 closing print, finish your calculation, and fill at that exact closing print with zero gap (Lesson 583, Lesson 586). Leaving the default (false, filling at the next bar's open) keeps end-of-bar rules honest; use Bar Magnifier when auditing intra-bar stop sequencing.
3. The #1 Pine Script bug: preventing request.security() repainting
The single most destructive bug in Pine Script is multi-timeframe repainting inside request.security(). Pulling a Weekly ("W") series onto a Daily chart via request.security(syminfo.tickerid, "W", close, lookahead=barmerge.lookahead_on) leaks future information across historical bars (Lesson 583).
Here is why: a Weekly bar opens Monday, yet its close does not exist until Friday at 16:00 ET. Without a [1] offset, lookahead=barmerge.lookahead_on stamps Friday's finished weekly close onto Monday, Tuesday, Wednesday, and Thursday's historical daily bars. In real-time trading, those same signals flicker on and off mid-week until Friday closes.
To lock strictly confirmed prior-week data across both history and live execution, pair close[1] (or expr[1]) with gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, and gate current-chart signal evaluations with barstate.isconfirmed:
//@version=6
indicator("Non-Repainting Weekly Trend Filter Example", overlay=true)
// [BUGGY — DO NOT USE] lookahead_on without [1] leaks Friday's weekly close onto Monday's daily bar
// badWeeklyClose = request.security(syminfo.tickerid, "W", close, lookahead=barmerge.lookahead_on)
// [SAFE PATTERN A] Prior confirmed weekly close ([1]) + lookahead_on stays identical Mon-Fri
safeWeeklyClose = request.security(
syminfo.tickerid, "W", close[1],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on
)
safeWeeklySma20 = request.security(
syminfo.tickerid, "W", ta.sma(close, 20)[1],
gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on
)
// [SAFE PATTERN B] Always gate current-chart signal checks with barstate.isconfirmed
htfBullOK = not na(safeWeeklySma20) and safeWeeklyClose > safeWeeklySma20
dailyTrig = close > ta.sma(close, 20) and htfBullOK and barstate.isconfirmed
plot(safeWeeklySma20, "Confirmed Prior Weekly 20 SMA", color=color.blue, linewidth=2)
4. Linking Strategy Tester results to walk-forward validation (Lessons 588–595)
Even with zero repainting and full transaction costs, TradingView's Strategy Tester executes a single in-sample pass across the chart window. Complete the validation framework in Lesson 588–Lesson 595 before putting capital at risk:
- Out-of-Sample & Walk-Forward splits (Lesson 590): Add
input.time()start/end boundaries to optimize parameters strictly on the first 60–70% window and evaluate untouched on the remaining 30–40% holdout window. - Parameter plateau check (Lesson 588, Lesson 591): Test neighboring lookbacks (e.g.,
45 / 50 / 55 SMA,1.8 / 2.0 / 2.2 ATR). Reject sharp isolated peaks; keep only broad parameter plateaus. - Multi-regime & tail-risk stress (Lesson 592, Lesson 594): Audit performance across bull rallies, rate-hike bear markets (2022), and liquidity shocks (2020) rather than cherry-picking one friendly cycle.
- Manual trade audit & validation log (Lesson 595): Spot-check 10 trades in List of Trades directly against candles, log your verified metrics, and deploy strictly via bar-close alerts (Lesson 607).
Try it yourself
- A Strategy Tester report shows
120trades per year,40%win rate,+$1,250average win, and−$500average loss on$50,000average position notional. Calculate expectancy per trade (in dollars and inR), then compute total annual friction if you add0.05%one-way commission and0.02%one-way slippage. - Explain why
weeklyTrend = request.security(syminfo.tickerid, "W", close > ta.sma(close, 20), lookahead=barmerge.lookahead_on)repaints on a daily chart, and rewrite that line cleanly using the non-repainting pattern. - Comparing two reports under Lessons 588–595 standards, which is more credible and why? Report A: +140% Net Profit, 14 trades, 28% Max Equity DD, PF 2.40, zero costs, single in-sample window. Report B: +92% Net Profit, 118 trades, 11% Max Equity DD, PF 1.62, 0.05% commission + 2 ticks slippage, 2020–2024 OOS verified.
Answers
- Payoff ratio is
$1,250 ÷ $500 = 2.50R, giving gross expectancy of(0.40 × $1,250) − (0.60 × $500) = +$200(or+0.40R) per trade, or+$24,000annually. Round-trip cost is(0.05% + 0.02%) × 2 = 0.14%, equal to$70per trade—deducting120 × $70 = $8,400/year(35%of gross profit) and leaving+$15,600net. - Without the
[1]shift,lookahead=barmerge.lookahead_onstamps Friday's finished weekly comparison onto Monday–Thursday daily bars across history. Rewrite cleanly as:weeklyTrend = request.security(syminfo.tickerid, "W", (close > ta.sma(close, 20))[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on). - Report B is far stronger. Report A suffers from a statistically tiny 14-trade sample, zero transaction costs, unverified in-sample tuning, and a steep 28% drawdown, whereas Report B pairs a robust 118-trade sample with realistic costs, controlled 11% drawdown, and out-of-sample confirmation.
Related lessons
- Lesson 583. Look-ahead bias and point-in-time data: matching decision time and execution time
- Lesson 585. Transaction cost models: commissions, spreads, market impact and turnover
- Lesson 586. Execution-assumption traps: closing fills, unfilled limit orders and tradable size
- Lesson 590. Designing walk-forward tests: splitting periods, reselecting and preventing leakage
- Lesson 609. Coding Complete Trading Rules in Pine Script: Breakout Entries, ATR Stops & 1R Position Sizing

![Multi-timeframe repainting vs. non-repainting timeline in Pine Script v6: showing how unshifted request.security with lookahead_on leaks Friday's weekly close onto Monday's daily bar, contrasted against safe close[1] + lookahead_on and the 5-point Strategy Tester audit.](/en/courses/overseas-stocks/610/figure_01.png)