Smart QA AcademyGuidesFree lessonsFree quizzes

Guides · Trading education · Published 2026-12-03

In-Sample vs Out-of-Sample Testing: How to Avoid Overfitting a Trading Strategy

Disclaimer. Educational content only, not legal or regulatory advice. Always check the current official text of the regulation or standard and consult a qualified professional for your specific case. Training only, not trading or investment advice. Demo account, past results are no guide. Consult your licensed broker. Trading can lose all of your investment.

Almost every beginner finds a "perfect" setting at some point: the moving-average length, the stop distance or the time filter that turns a mediocre backtest into a beautiful one. Then it is switched to a demo account and the beauty disappears. This is overfitting, also called curve fitting, and the standard defence is to keep some data hidden from the search. This guide explains in-sample and out-of-sample testing, the maths of why searching hurts you, and a simple routine to apply on a demo account. All figures below are made-up demo and past examples for training; nothing here is a signal or a recommendation.

Test yourself: free 5-question quiz on this topic — no sign-up

Free during beta. No account, no e-mail, no payment.

What in-sample and out-of-sample mean

The idea is simple. A method tuned on a set of data will always look good on that data, because you chose the settings that fit it, noise included. Only data that played no part in the choice can tell you whether the method found something real or just memorised the past.

Why searching creates false winners

Every time you try another setting, you give luck another chance to look like skill. Suppose a setting that has no real edge has a 5% chance of looking "significant" on a given history. Test several settings and the chance that at least one looks good grows fast:

Settings testedChance at least one looks significant (1 - 0.95^n)
15.0%
522.6%
2064.2%
10099.4%

These figures assume independent settings; real settings are correlated, so exact numbers differ, but the direction does not. The more you search, the more a good-looking result is expected even when nothing is there. That is why the number of variations you tried matters as much as the result you kept, and why it belongs in your journal.

Three ways to split your data

  1. Simple split. Use the first 60 to 70 percent of the history for design and keep the last 30 to 40 percent untouched. Keep the order in time; never shuffle trades from the future into the design set.
  2. Walk-forward. Tune on a window (for example two years), test on the next window (six months), then slide both forward and repeat. You collect several out-of-sample slices that were each unseen when the settings were chosen. It costs more work but shows how the method behaves across different market conditions.
  3. Forward test on a demo account. The cleanest out-of-sample data is data that does not exist yet. Freeze the rules, write them down with the date, and record every trade on a demo account.

The out-of-sample result is a verdict, not feedback. If you look at it, change the rules and retest, it has become in-sample.

Worked example with demo numbers

A demo trader has 100 past trades of one rule set, measured in R-multiples (profit divided by the amount risked). Costs are already included in each result. The first 60 trades are in-sample and the last 40 are out-of-sample.

Demo A, a rule with three settings tried. The best of three combinations shows an average of +0.35R per trade over the 60 in-sample trades. The 40 out-of-sample trades, run once with those settings, average +0.28R. The result shrank, which is normal, but it stayed clearly positive and the worst losing streak was in line with the in-sample one. This is a candidate to forward test on demo, still without any promise.

Demo B, a rule with 200 settings tried. The trader scanned 200 combinations of entry filter, stop distance and time of day. The best looked excellent: +0.45R per trade in-sample. On the 40 out-of-sample trades it averaged -0.05R. Nothing about the market changed; the search simply selected the combination that had fitted the noise best. With 200 tries, the chance of finding something flattering by luck was close to certain.

Settings triedIn-sample avg R (60 trades)Out-of-sample avg R (40 trades)Verdict
Demo A3+0.35+0.28Held up, keep forward testing
Demo B200+0.45-0.05Faded, discard

Notice that Demo B had the better in-sample figure. A better backtest is not a better method; it is often just a longer search. Remember sample size too: 40 trades is small, so a positive out-of-sample result is encouraging evidence, not proof (see our guide on how many trades you need to test a strategy).

Warning signs of curve fitting

A routine you can follow on a demo account

  1. Write the idea and the rules in your journal before testing. Fix the list of settings you are allowed to try.
  2. Count and record every variation you test, including the ones you discard.
  3. Reserve the last third of the data, or a block of future demo trades, as out-of-sample.
  4. Tune on the in-sample part only. Choose a setting on a plateau, not a peak.
  5. Run the out-of-sample test once. Record average R, win rate, profit factor and maximum drawdown next to the in-sample figures.
  6. Accept the verdict. If it failed, you may design a new idea, but then the old out-of-sample block is spent.

Frequently asked questions

What is the difference between in-sample and out-of-sample testing?

In-sample data is used to design and tune a trading method; out-of-sample data is kept aside and used once afterwards to check whether the method works on data it was not fitted to. The second is much better evidence of a real edge.

How much data should I keep out-of-sample?

A common rule of thumb is to hold back roughly 30 to 40 percent of the history, in time order, as long as enough trades remain in both parts to be meaningful. There is no official standard; the more settings you tried, the more you need.

What is walk-forward testing?

Walk-forward testing repeatedly tunes a method on one window of data and tests it on the next unseen window, then moves both windows forward. It produces several out-of-sample results instead of one, which shows how stable the method is over time.

Can I reuse out-of-sample data after it fails?

Not honestly. Once you have looked at the result and changed the rules because of it, that data has influenced the design and is now in-sample. You need new data, such as later history or forward demo trades.

Is a good out-of-sample result a guarantee?

No. Markets change, samples are small and costs vary. A good out-of-sample result lowers the chance that you fitted noise; it does not promise future performance.

Practise it in the Academy

The trading lessons on strategy testing and journalling include demo practicals where you record variations, split results and compare in-sample and out-of-sample metrics. They are free to open and need no sign-up.

Related Academy lessons

Test yourself: free 5-question quiz on this topic — no sign-up

Open the full lesson · All free quizzes

Full lessons, explained quizzes and audit simulations. Free during beta, no sign-up needed.

More guides

Disclaimer. Educational content only, not legal or regulatory advice. Always check the current official text of the regulation or standard and consult a qualified professional for your specific case. Training only, not trading or investment advice. Demo account, past results are no guide. Consult your licensed broker. Trading can lose all of your investment.