Trend-Following Strategy Backtesting Framework Based on Three-Stage Data Isolation and Walk-Forward Rolling Validation
Backtesting framework documentation (specifically designed for trend-following trading strategies)
The Core Philosophy of Trend-Following Trading Lies in "Cut Losses Short, Let Profits Run," but in quantitative backtesting we often face three fatal pain points: overfitting (parameters overly adapted to history), out-of-sample failure (live performance vastly different from backtest), and look-ahead bias. The core idea of this study is to build an extremely rigorous backtest validation framework that, through data isolation, rolling validation, and high-threshold screening, eliminates survivorship bias and retains only trend-following models with true generalization capability.
Data Splitting Rules: Strictly Guard Against Look-Ahead Bias
The traditional binary split (Train/Test) is highly susceptible to look-ahead contamination caused by indicator smoothing. This system adopts a three-segment structure:
- 75% Training Set: Used for parameter grid search and model fitting.
- 10% GAP Isolation Segment: Completely severs the data connection between the training and validation periods, preventing boundary data leakage during indicator calculation.
- 15% Validation Set: Pure samples that never participated in training, serving as the final arbiter.
To avoid cross-timeframe parameter contamination, we independently test M5, M15, H1, H4 multi-timeframe candles, ensuring that the strategy logic of each timeframe is pure and self-consistent.
Segmented Backtesting on Lower Timeframes: Extreme Granularity Check
High-frequency data is full of noise and extreme slippage. To ensure the reliability of the backtesting engine, we designed a 49-Day Segmented Backtesting Method for lower-timeframe data:
Split the 49-day data into 7 groups, each lasting 7 days. Each group outputs not only performance metrics but also trade-by-trade records for manual verification. This approach can precisely expose the backtesting engine's blind spots in handling gap openings, liquidity droughts, or price limits, avoiding the tragedy of "backtest fierce as a tiger, live trading a joke."
Rolling Window Walk-Forward Validation Mechanism
Static backtesting cannot reflect transitions in market regimes. We introduce forward-looking rolling validation:
- Set up 16 rolling windows.
- Each window adopts the structure of 180-day training set + 7-day out-of-sample testing set, advancing forward.
This walk-forward mechanism forces the model to undergo continuous testing in unknown 7-day windows, verifying its generalization capability across market conditions. If computing resources are insufficient, parameter scale can be flexibly reduced, but the strict time-series structure of rolling validation must remain unchanged.
ATR Dynamic Take-Profit / Stop-Loss and Parameter Grid Search
The soul of a trend-following strategy lies in volatility adaptation. We construct a dynamic grid using ATR (Average True Range):
- Take Profit (TP): 1.6 / 3.2 / 4.8 / 6.4 / 8.0 × ATR
- Stop Loss (SL): 0.8 / 1.2 / 1.6 / 2.0 × ATR
- Trend Threshold (THR): Paired with 10 filter thresholds
A single round of search will generate 400 independent models. To uphold the spirit of trend-following trading, we impose a strict strategy threshold: Risk-Reward Ratio (RR) ≥ 1:6. Parameter combinations with low reward ratios are discarded outright regardless of win rate, because only high R-multiples can cover the whipsaw costs of trend-trial-and-error.
Model Iteration Comparison and Overfitting Prevention
After each new round of models is generated, we never look at out-of-sample returns alone. Instead, we conduct multi-dimensional metric comparison with historical old models (including Sharpe ratio, maximum drawdown, and RR stability). What we screen for is "long-term stable" trend-following strategies, not transient profit blooms from a single window.
The screened stable strategies will be fed into the AI analysis system as dedicated trading skills, allowing the AI to learn how optimal parameters adapt under different volatility regimes, thereby further guiding adaptive parameter switching in live trading. This closed loop—from rigorous backtesting to AI empowerment—is our strongest moat against overfitting.
Summary and Live Trading Application Scenarios
This system, through "75-10-15 Isolation + 49-Day Micro Inspection + 16-Window Rolling Validation + 1:6 High RR Threshold," fundamentally eliminates the survival space for overfitting and look-ahead bias. This backtest framework is especially suited for high-volatility instruments (such as cryptocurrencies, major forex pairs, and commodity futures) in trend-following live trading. It does not pursue a high win rate—instead, it ensures that when trends arrive, you are in the market; and when range-bound whipsaws hit, your losses are controllable.
⚠️ Risk Disclaimer: Quantitative backtesting only reflects historical statistical patterns and does not guarantee future profits. Extreme black swan events may trigger liquidity droughts, rendering ATR-based stop-losses ineffective. In live trading, position sizing must be strictly controlled, and worst-case stress testing must be performed.
⚠️ Disclaimer: This article is for educational purposes only and does not constitute investment advice. Investing involves risk.


