Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Walk Forward Testing Explained in Simple Terms

4 min read

Watercolor illustration of a laptop with code and trading charts for walk forward testing

Walk forward testing (WFT) checks a trading system by optimising it on one slice of history (in-sample) and then trading those exact parameters on the next, unseen slice (out-of-sample), and repeating the process step by step through the data. If the strategy keeps making money on data it was never tuned on, you have far better evidence than a single backtest can give you.

Key takeaways

  • Walk forward testing = repeated optimisation on in-sample data followed by a test on the next out-of-sample period.
  • Only the stitched out-of-sample results count; they are the closest thing to a live track record you can get from history.
  • Anchored walk forward keeps the start date fixed; rolling walk forward moves the whole window forward.
  • AmiBroker has walk forward optimisation built in under the Optimize button of the Analysis window.
  • A strategy that only works in-sample is curve fitted. Fix it or drop it before risking capital.

Understanding Walk Forward Testing

Walk Forward Testing is a rigorous method used to assess the performance of a trading system’s rules over a period. Unlike traditional backtesting, where a strategy is tested on historical data to see how it would have performed, WFT takes this a step further. It not only tests the strategy on historical data but also checks its applicability and robustness in different market conditions.

How Walk Forward Testing Works

WFT involves several key steps:

OpenAlgo: one API for 35+ Indian brokers

FREE AND OPEN SOURCE

OpenAlgo: one API for 35+ Indian brokers

Self-hosted algo trading platform. Send orders from Python, AmiBroker, TradingView, Excel or a no-code flow through one consistent API.

  • Unified REST and WebSocket API
  • Works with AmiBroker, TradingView, ChartInk and Excel
  • Sandbox mode to test before going live
Get OpenAlgo →by Marketcalls
  1. Division of Data: The historical data set is divided into two parts, the in-sample data and the out-of-sample data. The in-sample data is used for the initial testing and optimization of the strategy, while the out-of-sample data serves to test the strategy’s performance as if it were being applied in real-time.
  2. Optimization: Using the in-sample data, the trading system’s parameters are optimized. This could mean adjusting certain thresholds or indicators to see what combination gives the best performance.
  3. Walk Forward: After optimization, the strategy is then applied to the out-of-sample data, essentially ‘walking it forward’ in time. This step is important as it simulates how the strategy would perform in unseen market conditions.
  4. Analysis and Adjustment: The performance of the strategy on the out-of-sample data is analyzed. Based on this analysis, adjustments can be made to the strategy’s parameters before the whole process is repeated.

Anchored vs rolling walk forward

Anchored walk forwardRolling walk forward
In-sample start dateFixed; the window grows each stepMoves forward by the step size
In-sample lengthGets longer every stepStays the same
Best forSlow, long-term systems that need lots of historySystems that should adapt to recent market behaviour
RiskOld regimes keep influencing the parametersShort windows can make parameters jump around

Why Walk Forward Testing is Important

Walk Forward Testing is invaluable for several reasons:

  • Realism: By using out-of-sample data to test a strategy, WFT provides a more realistic gauge of how a strategy might perform in the future. It helps to mitigate the risk of overfitting, where a strategy looks perfect in historical testing but fails in real trading.
  • Adaptability: Markets are dynamic, and a strategy that worked yesterday may not work tomorrow. WFT helps traders understand how their strategies might need to evolve to remain effective.
  • Confidence: Successfully passing the WFT gives traders more confidence in their strategy before deploying it with real capital.

How to run walk forward testing in AmiBroker

AmiBroker has walk forward optimisation built in. According to the official AmiBroker walk-forward guide, the workflow is:

  1. Open the Analysis window, click Settings and go to the Walk-Forward tab.
  2. Set the Start and End dates of the first in-sample period, the Step (how far the window moves each time) and the Last date. Tick Anchored if you want the start date to stay fixed.
  3. Leave Easy mode (EOD) or Easy mode (Intraday) on so AmiBroker builds valid out-of-sample periods for you, and check the generated segments in the preview list.
  4. Pick the Optimization target. The default is CAR/MDD; you can choose any built-in metric or a custom one from the custom backtester.
  5. Add Optimize() statements to your AFL, then click the arrow next to Optimize and choose Walk Forward Optimization.
  6. Review the results in the Walk Forward document. The out-of-sample summary report (marked “PS” in the Report Explorer) combines every out-of-sample step, and the ~~~OSEQUITY composite ticker plots the stitched out-of-sample equity curve.

How to read walk forward testing results

  • Compare in-sample and out-of-sample returns. Out-of-sample results will almost always be weaker. A modest drop is normal; a collapse means the in-sample result was curve fitting.
  • Look at consistency across steps. One huge out-of-sample period carrying all the profit is a warning sign.
  • Watch parameter stability. If the best parameter jumps from 10 to 80 and back between steps, the system has no stable edge at those settings.
  • Check the drawdown. The out-of-sample drawdown is a better estimate of what you will live through than the in-sample one.

Common walk forward testing mistakes

  • Making the out-of-sample window too short to contain enough trades to mean anything.
  • Re-running the whole walk forward many times with new rules until it looks good. That turns the out-of-sample data into in-sample data.
  • Optimising too many parameters at once, which multiplies the chance of a lucky fit.
  • Ignoring brokerage, slippage and taxes, which often decide whether a short-term system survives.

Walk forward testing pairs well with Monte Carlo analysis for trading system validation, which shuffles the trade sequence to show the range of drawdowns you could face. If you test in Python, the same idea applies to VectorBT backtesting and optimisation.

For the Novice Trader

If you’re new to system trading, the concept of Walk Forward Testing might seem daunting. However, it’s a critical step towards developing a dependable trading strategy. By rigorously testing and optimizing your system with WFT, you not only enhance its performance but also deepen your understanding of how different market conditions affect your strategy.

As you embark on your trading journey, remember that no strategy is foolproof. Markets change, and part of being a successful trader is continuously learning and adapting. Walk Forward Testing is an essential tool in your arsenal to ensure your trading system stays relevant and effective in the ever-evolving market landscape.

Frequently Asked Questions

What is the difference between backtesting and walk forward testing?

A backtest runs one set of parameters over the whole history, often after optimising on that same history. Walk forward testing optimises on one period and tests on the next unseen period, repeatedly, so the reported results come only from data the parameters were not fitted to.

What is walk forward optimization?

Walk forward optimization is the process of re-optimising a strategy at each step of a walk forward test. The parameters chosen in each in-sample window are then traded in the following out-of-sample window.

How much data should be in-sample vs out-of-sample?

There is no fixed rule. A common starting point is an out-of-sample window of around a quarter to a third of the in-sample window, with enough trades in each out-of-sample period to be meaningful.

Can I do walk forward testing in Python?

Yes. You can loop over date windows, optimise on each in-sample slice with a library such as VectorBT or Backtrader, and record the results of the next out-of-sample slice.

Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

3 Replies to “Walk Forward Testing Explained in Simple Terms”

  1. hello thanx for intro of walk forward testing. one thing i observed when tried to chek how walkforward backtesting . it creat a workforward data base in ami and cant be deleted.

  2. Hi Rajandran,

    I was just wondering if you know of a way to export the OOS (out of sample) trade list from Amibroker’s walk forward analysis.

    I would like to analyse the results in excel to create a monte carlo analysis of the results as a final check before using a given trading system.

    Many Thanks in advance
    Matthew Wills

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More