Walk Forward Window Planner
Walk-forward testing means running the same optimisation repeatedly over a sliding or expanding window and forward-testing each result on the period right after it - and working out the date boundaries for a dozen windows by hand, in a spreadsheet, without making an off-by-one mistake, is the kind of chore that discourages people from doing walk-forward testing at all. This script generates the window list instead. Give it a total range, an in-sample length, an out-of-sample length and a step size, and it writes one row per window: in-sample start and end, out-of-sample start and end, numbered in order. Two modes are supported - rolling, where a fixed-length in-sample window slides forward each step, and anchored, where the in-sample start never moves and the window simply grows, the expanding window some walk-forward methodologies prefer. The plan is checked against real history before it is written. A window list built purely from calendar arithmetic can name a start date the terminal has no bars for, and that mistake is normally only discovered when the first scheduled run fails. This script reads the earliest and latest bar actually available for the chosen symbol and timeframe first, clips the requested range to what exists, and says plainly in the log when it had to. Notes and limitations - Clipping to available history uses the coverage timeframe's bars, not the timeframe your expert actually trades. If your expert needs deeper history than what is downloaded on that timeframe, the plan can still name a range with thin underlying data - download history first. - Windows are date arithmetic only. This script does not run the tester, does not read or write .set files, and does not know whether a given window even has enough bars for a meaningful optimisation - pair it with a coverage check on the range before committing to a long batch. - If the requested range is too short to fit even one in-sample plus out-of-sample pair, the script says so and writes nothing.
Script · MT4 · v1.0 · Free
About Walk Forward Window Planner
Walk Forward Window Planner is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 9 settings, such as Symbol, Timeframe for coverage and Start date. MQL source code included.
Files in the download: WalkForwardWindowPlanner.ex4, WalkForwardWindowPlanner.mq4, WalkForwardWindowPlanner.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Symbol | Symbol to plan for, blank = this chart's symbol | |
| Timeframe for coverage | PERIOD_H1 | Timeframe used to bound the plan to real history |
| Start date | 0 | Plan start, 0 = earliest available bar |
| End date | 0 | Plan end, 0 = now |
| In sample days | 180 | Length of each in-sample window, in days |
| Out sample days | 60 | Length of each out-of-sample window, in days |
| Step days | 60 | How far the window set moves forward each step |
| Anchored | false | Anchored (expanding) instead of rolling in-sample window |
| Output file name | walk_forward_windows.csv | Output file, written to MQL4\Files |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Script · MQL4 Source Code