BACKTESTMARKET
Backtest Warmup Period: How Many Bars to Set Aside
backtesting·

Backtest Warmup Period: How Many Bars to Set Aside

A backtest warmup period lets indicators initialize before the first trade. Learn how to size it per indicator, avoid NaN rows and keep warmup bars out of results.

By BacktestMarket Team
backtest warmup period

Trader reviewing historical bars before a backtest

A backtest warmup period is a block of history that runs through your strategy before the evaluation window opens. It lets moving averages, RSI, MACD and other indicators fill with enough bars to produce valid values. Trading is switched off during warmup, and none of its bars count toward performance. Size it from the slowest indicator in your chain, not from the longest number in your settings. Make sure the data exists before your first test date, with no gaps.

This guide shows how to size warmup for common indicators, what breaks when it is too short, and how to keep warmup bars out of your results. It also covers why the quality of the history in front of your start date matters as much as the data inside the test.

TL;DR

  • Warmup is pre-start history that initializes indicators. No trades are placed and no results are measured during it.
  • Warmup is not the same as the in-sample or out-of-sample split. Warmup prepares state, while those splits decide what you may learn from.
  • A simple moving average needs its period in bars. Recursive and chained indicators need more: MACD(12,26,9) needs 34 inputs, and ADX(14) needs 28 candles at minimum.
  • Too little warmup produces NaN values that can look like "no signal" and quietly distort your trades.
  • The history ahead of your start date must be clean and continuous. Missing bars there corrupt every indicator that follows.

Table of Contents

What a warmup period is and why every backtest needs one

Indicators are functions of past bars. A 50-period simple moving average is undefined on bar 10, because the 50 bars it averages do not exist yet. If your backtest starts on the first bar of your data file, your strategy spends its first stretch making decisions on values that are missing or meaningless.

The fix is to run the strategy over earlier history first. Indicators absorb those bars and reach a ready state. Only then does the evaluation window begin, and the strategy is allowed to place orders. The MetaTrader 5 Strategy Tester documentation describes the same idea: the tester loads a pre-start history buffer so indicators can calculate from the very beginning of the requested test.

Three things follow from this:

  1. Warmup consumes data. You need history before your intended start date, not only after it.
  2. Warmup is silent. Nothing errors out when it is too short. The numbers just get worse.
  3. Warmup is a property of the strategy. A strategy with a 200-bar moving average needs more than one with a 10-bar RSI, and a strategy with both needs the larger.

Warmup, evaluation window and out-of-sample: three different things

Traders often mix these up, so separate them before you set anything.

SegmentPurposeAre trades placed?Do results count?
WarmupFills indicators and stateNoNo
In-sample (development)Design and tune the rulesYesYes, for development only
Out-of-sample (OOS)One final check on unseen dataYesYes, as your honest estimate

Warmup sits in front of whichever segment you are about to run. You need one before the in-sample run, and another before the out-of-sample run if that segment is tested separately. Otherwise the first OOS bars are evaluated with indicators that have been reset, and the cold-start error lands in your most important test.

Another subtlety: your requested start date is not always your effective start date. MetaTrader 5 states that when the available history is insufficient, the tester automatically moves the actual start date forward to the nearest point that meets its requirements, and records the change in the tester log. If you compare two runs that you believe cover the same period, check the log. They may not.

How to size the warmup for each indicator

The rule is simple: find the number of bars each indicator needs before its output is valid, then take the largest value across the whole strategy. The difficulty is that "number of bars" is not always the visible period.

Simple indicators: the period itself

The maintainer of the open-source Stock.Indicators library explains that a simple moving average cannot be calculated until a full period of data exists. SMA(200) needs 200 bars. A rolling highest-high or lowest-low over N bars needs N bars.

Recursive indicators: more than the period

Exponential averages and anything built on them carry memory of the entire past. The same maintainer notes that recursive indicators can produce values that are less accurate at first and converge over time. They emit a number early, but it is not yet trustworthy.

For ADX, that discussion recommends at least 2×N+100 historical quotes before you rely on the output, and preferably 2×N+250 for better precision. Its example removes the warmup rows before evaluating results. For ADX(14), that is 128 bars as a floor and 278 as the safer choice.

Chained indicators: add up the dependency chain

A chained indicator feeds one calculation into another, and the warmup is the length of the chain. The Wickra MACD documentation defines MACD warmup as the slow period plus the signal period minus one. For the classic 12/26/9 setup, that is 34 inputs before the full output appears. The Wickra ADX documentation reports 2×period for ADX, so 28 candles for ADX(14). The calculation first seeds directional movement and true-range smoothing, then seeds the ADX itself.

Here is a quick reference built from those sources:

IndicatorMinimum bars before first valid outputSafer practical buffer
SMA(N)NN
MACD(12,26,9)34Several times the slow period, so the EMAs settle
ADX(14)282×N+100 (128), preferably 2×N+250 (278)

The safer buffer for MACD is our practical suggestion for recursive smoothing, not a published figure. Treat the minimums as floors.

A strategy with several indicators

Take a strategy that uses SMA(200) on the trend, MACD(12,26,9) for timing and ADX(14) as a filter. The floors are 200, 34 and 28 bars, so the strategy needs at least 200. But ADX only settles around 128 to 278 bars, which is also below 200. A 250-bar warmup covers the strategy's floors and the recommended ADX buffer. If you add a 200-period EMA, which is recursive, you would want a buffer well beyond 200 so that its early values have converged.

Indicator bar requirements and example warmup

Converting bars into calendar time on minute data

Warmup is counted in bars, but you load data by date, and the two diverge as the timeframe changes. On 1-minute bars, a 250-bar warmup is about four hours of trading. On daily bars, it is about a year of trading days. If your strategy computes a 200-day average from minute data, the warmup is 200 sessions of minute bars. In a 24-hour forex market that is roughly 288,000 bars on a five-day week, a figure you should check against your own instrument's session calendar.

MetaTrader 5 builds a fixed minimum pre-start buffer. According to its documentation, for D1 and lower timeframes it loads from the beginning of the previous calendar year. For W1 and MN1 it requires at least 100 weekly and 100 monthly bars respectively. A test starting in mid-2024 on minute bars therefore draws on history from the start of 2023. This is convenient, but it only helps if that earlier data actually exists in your terminal and is accurate.

Converting bars into calendar time on minute data

What goes wrong when warmup is too short

The obvious failure is an indicator that returns NaN. The less obvious one is what your code does with it.

The QuantWave documentation warns that warmup outputs may be NaN rather than null. A cleanup step that drops nulls only will leave invalid warmup rows inside your backtest. It also notes that comparisons such as NaN < 30 evaluate to false. An RSI-below-30 entry rule will therefore read a NaN as "no signal" and look like a perfectly ordinary quiet period. Nothing crashes, and the strategy appears to work.

The damage shows up in these ways:

  • Phantom first trades. Rules that compare an indicator with a price (for example, close above a moving average that has not formed) can fire on garbage.
  • Distorted early equity. The first weeks of results come from a half-built model, which skews drawdown and trade counts.
  • Unreproducible comparisons. Two runs that start on the same date but with different warmup lengths produce different trades, so parameter tests become noise.
  • Inflated or deflated stats on short tests. On a test of a few hundred bars, a 200-bar warmup is most of the data. The effect is largest exactly where traders are most tempted to cut corners.

Keeping warmup bars out of your performance numbers

The goal is for warmup bars to feed state without producing trades or statistics. There are three common approaches, and they can be combined.

  1. Skip the first N bars in the strategy. Many frameworks expose a setting that begins strategy execution at bar N instead of bar zero. A 200-bar warmup on a 500-bar dataset leaves 300 bars to evaluate. In custom code, return early from your bar handler until the count reaches N.
  2. Check readiness, not just count. Test that every indicator reports ready, and raise the lookback if one does not.
  3. Trim by alignment. If you work in dataframes, remove the leading warmup rows across all columns together. QuantWave recommends an alignment-preserving trim over dropping rows column by column, which would shift one series against another. Remove NaN rows explicitly, not only nulls.

A few practical checks before you trust a run:

  • Print the first timestamp at which the strategy is allowed to trade and confirm it is later than the first timestamp loaded.
  • Confirm that the number of evaluated bars equals total bars minus warmup bars.
  • Compare the first trade time with the first date your indicators have valid values.
  • If you test in segments (in-sample, then OOS), restart the warmup for each segment from real history, not from zeros.

The data in front of your start date has to be sound

Most warmup advice stops at bar counts. The part that bites in practice is the quality of the bars. An indicator is only as good as the history it digests. A missing hour, a duplicated timestamp or a bad spike in the warmup region does not just affect that moment. It leaks forward through every recursive indicator, because exponential smoothing never fully forgets. That is a quiet way to get different results from the same strategy on two different data files.

So audit the warmup region the way you audit the test region:

  • Look for gaps and timestamp shifts, especially around daylight saving changes and session rollovers.
  • Check that bars are continuous across the boundary between warmup and evaluation.
  • Make sure the pre-start history comes from the same source and adjustment method as the rest of the series.

We cover the audit routine in more detail in our guides on auditing MT5 backtesting data for gaps and timestamps and preparing MQL4 data per year. If your strategy trades on short timeframes, minute-bar backtesting accuracy explains how the underlying bars affect fills and results.

Promo: history that is ready before your first bar

Warmup means you need more history than the period you want to judge. BacktestMarket provides clean minute-bar historical intraday data since 2014 across forex, metals, bonds and stock indices. It is delivered as complete datasets that are ready to import into MT4 and MT5, so the years in front of your start date are already there. Our engineers collect the data and answer support questions directly. You can browse the historical data sets or the forex data. The Annual Plan is €119 per year.

Backtestmarket

Our perspective

We build datasets for people who backtest, and the most common complaint we hear about results is not the strategy. It is that two runs disagree and nobody can say why. Warmup is one of the first places to look, and the data under it is the second.

Our standard is bar-by-bar verification and documented adjustments. A warmup region full of gaps defeats the point of warmup. A 250-bar buffer made of broken minutes is worse than a shorter buffer made of clean ones, because the error hides inside your indicators.

That is why we deliver complete datasets in one download, ready for MT4 and MT5, starting in 2014. You decide where the evaluation window begins, and the history in front of it is already in the same format and the same standard. Choose your warmup from the slowest indicator, start the test after it, and keep one continuous, documented history underneath all of it.

Start

A short procedure you can reuse

  1. List every indicator and its parameters.
  2. Write down each indicator's minimum valid bars, including its dependency chain.
  3. For recursive indicators, add a convergence buffer, such as 2×N+100 for ADX where the source recommends it.
  4. Take the largest figure and round up generously.
  5. Convert bars to calendar time on your timeframe and instrument calendar.
  6. Confirm that data exists that far back, with no gaps.
  7. Run, then check the log for the effective start date and the first trade timestamp.
  8. Repeat the procedure for every separately tested segment.

FAQ

How long should a backtest warmup period be?

It should be at least as long as the slowest indicator needs to become valid, and longer for recursive indicators. A 200-bar moving average needs 200 bars, while ADX(14) is recommended to have at least 2×14+100 quotes. Round up and confirm the effective start date in your tester log.

Is the warmup period the same as out-of-sample data?

No. Warmup bars only initialize indicators, and no trades are placed or measured. Out-of-sample data is withheld during development, then used for a final test of how the strategy generalizes. Each segment you test still needs its own warmup in front of it.

What happens if I skip the warmup?

Indicators return NaN or immature values at the start, and your rules may treat them as real. NaN comparisons evaluate false, so a missing signal can look like a calm market. Early trades and statistics end up built on invalid inputs.

Does MetaTrader handle warmup for me?

Partly. The MT5 tester loads a pre-start history buffer, starting from the beginning of the previous calendar year for D1 and lower timeframes. If that history is missing, it can shift your start date forward. You still need to verify the data and read the log.

Sources

Recommended

Related resources

Explore BacktestMarket's Expert Advisor robots to put the ideas in this article into practice.

Newsletter

Stay updated

New datasets, expert advisors, discounts, and trading insights — straight to your inbox.

Cart

Your cart is empty

Add some products to get started.