Freqtrade's official docs offer --timerange but no out-of-sample or walk-forward switch. So hyperopt on window A, backtest the exported parameters on A to confirm they match, then backtest them unchanged on a later window B. B is only out-of-sample until you re-optimize after seeing it. Copy the parameter JSON after each fold, because hyperopt-show can overwrite it. Remember that config values override hyperopted ones. Compare per-trade and per-day metrics, not total profit. Example dates and a hypothetical retention-ratio calculation are labeled; no backtest was run for this article.

Calculation and worked example. AI-assisted drafting. Educational information; no individual financial advice.

Freqtrade has no built-in out-of-sample mode

The official hyperopt page (checked 2026-11-13) has no walk-forward or out-of-sample switch. What it does give you is --timerange, which limits hyperopt or backtesting to a date window, and the advice to backtest the optimized strategy afterwards. The docs say to use the same configuration, timerange and timeframe as the hyperopt run if you want the backtest to reproduce the hyperopt result.

That gives you the whole method:

  1. Hyperopt on window A (in-sample).
  2. Backtest the same parameters on window A as a sanity check. The numbers should match the hyperopt result.
  3. Backtest those same parameters, unchanged, on a later window B that hyperopt never saw (out-of-sample).

Window B only stays out-of-sample until you use it to make a decision. If you look at the B result, change a parameter or a search space, and run hyperopt again, B has become part of the optimization. You need a fresh window to test again.

Timerange syntax and the boundary candle

The backtesting docs define the format. 20260101-20260301 is a fixed window, 20260501- runs from that date to the end of your data, and -20260131 runs from the start of your data to that date. Both sides also accept yyyymmddThhmm and epoch seconds. All times are UTC.

There is one detail the docs don't spell out. In the stable source we read (trim_dataframe in freqtrade/data/converter/converter.py, checked 2026-11-13), the start date is compared with >= and the end date with <=. So if in-sample ends at 20260501 and out-of-sample starts at 20260501, a candle that opens exactly at 2026-05-01 00:00 UTC can fall inside both windows. One shared candle rarely changes anything. For a strict split, end the in-sample window one candle earlier, for example 20251101-20260430T2300 on a 1h timeframe.

Warm-up is a different thing from leakage. The strategy docs explain that backtesting loads startup_candle_count extra candles before your start date so indicators are stable, then removes them before trading begins. Your out-of-sample run will therefore read some in-sample candles for indicator warm-up. That is expected, and no trades are placed on them. Make sure the data you downloaded covers that warm-up period. If it doesn't, freqtrade moves the start of the backtest later. For choosing the value, see our startup_candle_count walkthrough.

Example split: one fold, then walk-forward

The dates below are an example layout, not a recommendation for any market period. It uses 12 months of downloaded data, with 6 months for optimizing and 2 months for testing, stepped forward 2 months per fold:

FoldIn-sample (hyperopt)Out-of-sample (backtest only)
120251101-2026050120260501-20260701
220260101-2026070120260701-20260901
320260301-2026090120260901-20261101

The commands for fold 1:

freqtrade hyperopt --strategy MyStrategy --hyperopt-loss SharpeHyperOptLossDaily --spaces buy sell --timerange 20251101-20260501 -e 500 --random-state 42 --min-trades 30
cp user_data/strategies/MyStrategy.json user_data/strategies/MyStrategy.fold1.json
freqtrade backtesting --strategy MyStrategy --timerange 20251101-20260501 --export trades --cache none
freqtrade backtesting --strategy MyStrategy --timerange 20260501-20260701 --export trades --cache none

Why each step is there, based on the official hyperopt page:

  • The parameter file is overwritten. Hyperopt writes its result to a JSON file next to the strategy (MyStrategy.json), and backtesting loads it automatically. hyperopt-show also rewrites that file unless you pass --disable-param-export. Copy the file after each fold. Otherwise, opening an older epoch can quietly change the parameters your out-of-sample backtest uses.
  • The config wins. Precedence is config > parameter file > strategy *_params > parameter default. If your config sets stoploss, max_open_trades or trailing_stop, it overrides the hyperopted values in both backtests. Check the backtest log for what was actually applied.
  • Fix the seed. With the same --random-state and unchanged inputs, hyperopt should repeat its results. The docs also say different seeds will most likely produce different results. Running a few seeds on the same in-sample window and comparing the parameters you get is a cheap stability check.
  • --min-trades (default 1) stops the optimizer from picking an epoch that made only a handful of trades.
  • --cache none forces a fresh backtest. The docs warn that caching can reuse results it shouldn't, for example after strategy imports change.

For folds 2 and 3, repeat the same commands with the dates from the table. Keep every fold's parameter file and both result exports.

How to read in-sample versus out-of-sample

The two windows have different lengths, so don't compare total profit. Compare per-trade and per-day figures from the backtest summary:

  • Avg profit % per trade and win rate: did the edge per trade hold up?
  • Trades per day (Total/Daily Avg Trades): a big drop often means the entry conditions were fitted to one market regime.
  • Max drawdown % and the exit reason table: an out-of-sample run dominated by stop_loss or force_exit exits tells a different story than one with mostly roi exits.
  • Parameter drift across folds: if each fold picks very different values, the optimum is probably noise.

A simple retention ratio is out-of-sample avg profit per trade ÷ in-sample avg profit per trade. Here is the arithmetic with hypothetical numbers, not a backtest result. In-sample: 180 trades over 181 days, averaging 0.40% per trade. Out-of-sample: 50 trades over 61 days, averaging 0.10% per trade. Retention = 0.10 ÷ 0.40 = 25%. Trades per day fall from 180 ÷ 181 ≈ 0.99 to 50 ÷ 61 ≈ 0.82. Here, most of the per-trade edge did not carry over, which suggests overfitting.

There is no official pass mark. Set your own threshold before you look at window B. One good fold proves little, so look at every fold.

Checks to run before trusting any split

Run lookahead-analysis first. A strategy that peeks at future candles produces in-sample and out-of-sample results that are both wrong. Keep --timeframe-detail and protections settings the same across both windows, and treat every number as historical simulation only. The bot evaluation guide and the backtest statistics tool help you compare the two summaries side by side.

Sources & method

What this article adds

Turns freqtrade's one-line --timerange advice into a full in-sample/out-of-sample procedure: a three-fold walk-forward date table, copy-paste commands with the parameter-file copy step, the boundary-candle detail read from the stable source (end date compared with <=), the warm-up versus leakage distinction, and a retention-ratio worksheet with clearly labeled hypothetical numbers (0.10 ÷ 0.40 = 25%; 180/181 vs 50/61 trades per day).

How it was prepared

Drafted on 2026-11-13 from the official freqtrade stable docs (hyperopt, backtesting, strategy customization, utils, lookahead-analysis) and the stable source for trim_dataframe (stable branch head 4cf0351, committed 2026-10-30), all fetched that day. The fold dates are an example layout. The retention numbers are hypothetical and labeled, not results. Freqtrade was not executed for this article, and no in-sample or out-of-sample result is reported.

Hyperopt page: --timerange usage, the advice to backtest with the same config and timerange to reproduce hyperopt, parameter JSON auto-export and the hyperopt-show overwrite, config > parameter file > strategy precedence, --random-state reproducibility and seed variance, --min-trades default 1, and the 'results do not match' checklist. Backtesting page: timerange formats (UTC, open ends), --cache warnings and Total/Daily Avg Trades. Strategy customization: startup candles loaded before the timerange and removed before trading. Utils: hyperopt-show options. Lookahead analysis: purpose. Source converter.py: start >= and end <= comparisons.

For corrections, contact the publisher. Editorial policy · Affiliate disclosure

Put it into practice