Quantitative··5 min read

An Anti-Overfit Protocol for Strategy Backtesting on TradingView

0 references, link-verifiedEditor of record: Shane CantyStandards review editorial standard · audit log

Abstract. Most retail backtests fail in a predictable way: parameters get tuned until history looks profitable, and the future disagrees. This paper describes a testing lab for NQ futures strategies built around TradingView's Strategy Tester, whose entire design exists to make that failure hard: repaint-proof code patterns, a pre-registered optimization budget, a validation window that may be read exactly once, and an adversarial verdict step with written pass/fail rules. The lab is methodology; no strategy tested in it has a published verdict yet.

The problem

A strategy tester will happily reward you for overfitting. With enough parameter combinations, any random ruleset shows a beautiful equity curve on the data it was tuned on. The two classic contaminations are lookahead (the code peeks at information that did not exist yet, often through repainting constructs) and selection (dozens of silent tries, with only the winner remembered). Both produce backtests that are true and strategies that are worthless.

Method

Every strategy enters the lab as Pine Script v6 written to a fixed house pattern:

strategy("CRT Sweep Reversal [NQ 1H]", overlay = true,
     commission_type = strategy.commission.cash_per_contract, commission_value = 1.25,
     slippage = 1, process_orders_on_close = true, calc_on_every_tick = false, ...)

Three rules do most of the anti-lookahead work: all logic computes on the chart timeframe (no higher-timeframe security calls, which are the usual repainting vector), orders process on confirmed bar closes only, and costs (commission plus a tick of slippage per side) are in the header, never zero. Each file carries a train/validation date split as an input, so the tester can be pointed at either window but never silently at both.

The optimization protocol is where discipline lives:

  1. Record the baseline with default parameters, including the first date the tester actually covered.
  2. Optimize on the training window only, from a pre-declared grid, with a hard cap of thirty logged combinations. Every try is written to the strategy log, including the failures - unlogged tries are how selection bias hides.
  3. Read the validation window once, with parameters locked. There is no second attempt: a failed validation is a failed strategy, and the next idea must be materially different rather than a re-tune of the corpse.

A final judge step applies written rules before any strategy is called good: validation profit factor of at least 1.15 after costs, no single trade contributing more than 30% of net profit, at least sixty training trades, and train-to-validation degradation under 50%. The judge is required to argue the case against the strategy before passing it.

Results

The lab currently holds three coded strategies (a liquidity-sweep reversal on 1H, a VWAP band fade on 5m, and a confluence-scoring system on 15m) and a ten-idea research backlog spanning mechanical, ICT-derived, and volatility-regime styles. None has completed the protocol, so none has a verdict, and this paper reports none. On the free TradingView tier the honest tested window is roughly one to two years on 1H charts and months on 5m - shorter than ideal, and always reported as what it is rather than what was wished for.

Limitations

The Strategy Tester fills orders at bar granularity, which flatters strategies that rely on intrabar precision; the house pattern avoids such strategies but cannot fix the simulator. Costs are modeled, not measured. A thirty-try cap reduces selection bias but does not eliminate it, and a single validation read is only as honest as the person holding the log. The protocol makes self-deception harder, not impossible.

Full implementation available on request.

Key definitions

Lookahead bias - An error in backtesting where the code accesses information that did not exist at the time a trading decision was made, typically through repainting or higher-timeframe data lookups.

Overfitting - The tuning of strategy parameters until historical results appear profitable on the dataset used for optimization, without evidence the parameters will perform on unseen data.

Repainting - A behavior in some charting libraries where indicator values recalculate on historical bars as new data arrives, causing backtests to show signals that would not have appeared in real time.

Selection bias - The contamination that occurs when multiple strategy variants are tested silently, and only the best-performing variant is reported, ignoring the failed attempts that preceded it.

Profit factor - The ratio of gross profit to gross loss over a strategy's trade history; a ratio of 1.15 indicates total wins are 15% larger than total losses.

Pine Script v6 - TradingView's proprietary scripting language for writing custom indicators and trading strategies on its charting platform.

Train/validation split - A methodological division of historical data into a training window (used for parameter optimization) and a validation window (used for out-of-sample testing without parameter adjustment).

References


Educational research on historical data only - not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Drafting uses AI assistance; every citation is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Last reviewed by the PropLedger research pipeline: 2026-08-26. Educational research on historical data; not financial advice.

Educational research on historical data only. Not investment advice, not a signal, and never a performance promise. Past results do not predict future performance. Every reference is link-verified before publication and every paper is re-audited weekly against the library's editorial standard. Found an error? Email support@prop-ledger.org and the paper is corrected or withdrawn.