Guide
Walk-Forward Test an NSE Strategy
To walk-forward test a strategy in TradingLead, first complete a Python or Pine backtest, then choose Walk-forward in Optimize and preview a bounded parameter grid and rolling train/test windows. Each segment starts flat on frozen data. Test results do not select parameters, but later training can reuse earlier test candles.
1. Freeze the strategy and its assumptions first
Open a supported NSE symbol and interval, then complete a backtest. Record the actual candle count and dates, capital, quantity, fees and slippage. Decide which parameters the code really reads. Pine grids use declared variable IDs, not input display labels or arbitrary execution-setting names.
Do not change the dataset between candidate evaluations. The optimizer uses the source, inputs, primary/secondary history and execution assumptions captured in the completed run.
2. Use a small interpretable grid
As an illustrative vectorized example, a strategy reading fast and slow can test fast=[10,20] and slow=[40,60,80]: six combinations. These are example values, not a profitable or recommended NSE strategy.
A 1,000-candle sample with 400 training candles, 100 test candles and three folds gives:
| Fold | Training offsets | Test offsets |
|---|---|---|
| 1 | 0–400 | 400–500 |
| 2 | 100–500 | 500–600 |
| 3 | 200–600 | 600–700 |
Offsets are zero-based, end exclusive. There are 18 training evaluations and three selected tests; 300 candles remain unused. Preview maps these offsets to the run's exact UTC dates. Do not apply this 1,000-candle example to sequential mode, whose source run is limited to 250 candles.
3. Choose training-only selection and warmup
Select highest training net P&L, which can include open mark-to-market, or lowest training max drawdown. Set a minimum completed-position count if you want to exclude near-inactive candidates. A maximum drawdown constraint is an account-currency amount, not a percentage.
Cold-start uses each segment's original configured warmup. Explicit past-only warmup uses preceding unscored captured candles, up to 5,000, with a fresh scored account. Missing preceding history shortens the warmup; positions and equity never carry across the boundary. Pine secondary warmup is unsupported.
Preview before running. It validates workload without executing the strategy. Optional measured time estimation executes one real candidate and is low-confidence, not a completion-time guarantee.
4. Run and read each phase separately
Start optimization explicitly and wait for its own terminal status. The baseline backtest can remain completed while optimization is still running. Cancellation, failure and skipped tests are distinct outcomes.
Read the winning training candidate, its eligibility and the following held-out result for every fold. Do not combine independently initialized folds and call the output a continuous portfolio return. Later training can include earlier test candles, so it is rolling validation rather than permanently unseen data.
Avoid repeatedly editing the grid after inspecting poor tests and then calling the same tests untouched. Keep both positive and failed attempts as research evidence.
5. Preserve the result without relabeling reused data
Save the stopped run with its current revision. A confirmed selected-parameter rerun creates another backtest on the full original sample, including reused tests. It is useful for inspection but is not new out-of-sample validation.
Detailed optimizer HTML generation reconstructs recorded evaluations and flags metric mismatches. Export HTML to retain that session-cached report. Small authored explanations belong to Research reports, not another optimizer run.
Use it with an AI assistant
Use tl-strategy-optimization and real commands backtesting.optimizePreview, backtesting.optimize, backtesting.optimizeMeasure, backtesting.optimizeRerun and backtesting.optimizeReport. Require explicit approval for operations that execute code and discover the actual Desktop tab's support first.
See the TradingLead command reference and AI prompt cookbook. Ask for training and test evidence separately, not a claim that the optimizer found a guaranteed profitable strategy.
Steps
- Complete a backtest with explicit source, history and cost assumptions.
- Open Optimize and choose Walk-forward.
- Enter declared parameter candidates and training/test candle counts.
- Choose 1–5 folds, an objective and training-only constraints.
- Preview exact windows, warmup, work and unused candles.
- Start explicitly and wait for the optimization report to finish.
- Review held-out results separately and preserve the frozen run.
Limitations
- Small bounded search, not an adaptive or genetic optimizer.
- Frozen original data; walk-forward does not fetch a fresh validation sample.
- Each segment starts flat; later training can include earlier revealed test candles.
- Vectorized source can still contain lookahead; the product does not certify causality.
- Past-only warmup is bounded; Pine secondary warmup is unsupported.
- Results remain simulations with assumed costs, not live trading or investment advice.
Frequently asked questions
- Can TradingLead walk-forward test both Python and Pine?
- Yes. Completed authoritative Pine runs use declared input IDs and frozen execution settings; Python uses parameters the source actually consumes. Pine does not require Python runtime readiness.
- How large can my search be?
- At most four parameter keys, 12 combinations and five folds, with up to 65 evaluations. Sequential prefix work is capped at 1,000 calls and the original sequential run at 250 candles.
- Do positions continue across folds?
- No. Each training and test segment starts flat with the original capital. This is not a continuously carried portfolio.
- Can I supply a 70/30 split?
- The UI can convert percentages to candle counts. Commands use trainBars and testBars, not percentage fields. Preview actual dates, warmup and unused tail before running.
- What if no candidate passes my constraints?
- The fold has no selected candidate and its held-out test is skipped explicitly. A skipped test is not zero return or successful validation.
- Is a full-sample winner rerun fresh out-of-sample evidence?
- No. It reuses the original full frozen sample, including held-out candles, and requires explicit confirmation. Keep it separate from the fold tests.
Related
Last updated: