PipCircle app icon

Install PipCircle

Add the app to your device - fast access, full screen, and it works offline.

Important Disclaimer

PipCircle is the social network for traders. We connect forex, stock, crypto, and prop firm traders with broker reviews, community insights, and real-time trading discussions.

The information on this platform, including user posts, broker reviews, and discussions, is for informational and educational purposes only. It does not constitute financial advice, investment recommendations, or an endorsement of any broker or trading strategy.

Risk Warning: Trading in financial markets involves substantial risk of loss and is not suitable for every investor. Past performance is not indicative of future results. You should carefully consider your investment objectives, level of experience, and risk appetite before trading.

Users are solely responsible for their own trading decisions.

Overfitting

Overfitting is choosing rules or settings because they did best on past prices. The past then looks excellent and the future does not match it.

  • Level 11 Your Trading Plan
  • الدرس 15 من 25
  • 5 دقائق قراءة
  • 2 أسئلة

Overfitting means tuning a system to the prices it was tested on: trying many settings, rules or filters and keeping whatever scored best. Part of any best score is luck that belonged to those prices alone. Level 3 and Level 5 both warned against tuning to the past. This lesson shows it happening, with numbers.

Eight settings of one rule

The example system looks back 20 candles for its breakout. Suppose eight lookbacks are tried and judged on the first three years of the example candles, after costs.

Eight pairs of bars, one pair for each lookback from 10 to 60 candles: the average result of a trade after costs in years 1 to 3 and in years 4 to 6. The best setting in the first three years, 30 candles, made +0.14R a trade there and −0.09R a trade in the next three. Every setting lost money in years 4 to 6.Eight pairs of bars, one pair for each lookback from 10 to 60 candles: the average result of a trade after costs in years 1 to 3 and in years 4 to 6. The best setting in the first three years, 30 candles, made +0.14R a trade there and −0.09R a trade in the next three. Every setting lost money in years 4 to 6.
Figure 1. Eight lookbacks in the years used to choose and in the three years after. Example prices made by a formula, not market data.
LookbackYears 1 to 3, R a tradeYears 4 to 6, R a trade
10−0.015−0.050
15−0.009−0.065
20+0.050−0.087
25+0.078−0.105
30+0.140−0.091
40+0.099−0.147
50+0.137−0.036
60−0.005−0.074

A lookback of 30 looks best: +0.140R a trade, +26.2R over 187 trades. In the next three years it made −0.091R a trade and lost 15.0R. Every setting lost in those years.

The prices were made with no pattern in them, so every plus sign in the middle column is luck. That is known here by construction. With real prices nobody knows, which is the reason for the next two ideas.

In-sample and out-of-sample

The prices used to choose a setting are in-sample. Prices kept back and used once, after the choice is final, are out-of-sample. Only the second set says anything about the choice. Looking at the out-of-sample result and then adjusting turns it into in-sample data.

Walk-forward

Four rows on a six-year axis. Each row chooses the best lookback on two years and trades it on the year that follows, then moves on a year. The choices were 30 (year 3: −6.7R), 50 (year 4: +10.5R), 50 (year 5: +3.5R) and 50 (year 6: −18.5R). The four traded years together made −11.2R.Four rows on a six-year axis. Each row chooses the best lookback on two years and trades it on the year that follows, then moves on a year. The choices were 30 (year 3: −6.7R), 50 (year 4: +10.5R), 50 (year 5: +3.5R) and 50 (year 6: −18.5R). The four traded years together made −11.2R.
Figure 2. A walk-forward test: choose on two years, trade the next, move on a year. Example prices made by a formula, not market data.

A walk-forward test repeats the split along the data. Choose the best setting on years 1 and 2, trade it in year 3, then choose again on years 2 and 3 and trade year 4, and so on. The traded years, joined together, show what the habit of choosing the best setting would have earned. Here the four traded years lost 11.2R over 185 trades.

A wide plateau is not proof

Level 5 gave a guard: distrust a setting whose neighbours fail. Here the neighbours passed. Lookbacks of 25, 40 and 50 all made money in years 1 to 3, and all lost afterwards. Neighbouring settings share most of their trades, so they rise and fall together. The guard can reject a system and cannot confirm one.

Signs of a fitted system

  • Many rules, each with its own setting.
  • A filter with no reason behind it beyond the results.
  • An equity curve far smoother than the method’s logic would suggest.
  • No out-of-sample result, or one that was looked at more than once.

Key points

  • Overfitting is choosing settings because they scored best on the tested prices.
  • In the example the best of eight lookbacks made +0.140R a trade in years 1 to 3 and −0.091R in years 4 to 6.
  • In-sample prices are used to choose. Out-of-sample prices are used once, after the choice.
  • A walk-forward test repeats that split along the data and joins the out-of-sample years.

مراجعة سريعة

لا تُحتسب هذه الأسئلة في نتيجة الاختبار القصير.

1. A trader tests 40 versions of a rule on last year’s prices and trades the best one. What is the most likely outcome on new prices?
2. A system is chosen on years 1 to 3 and then checked once on years 4 to 6. Which years are out-of-sample?

Common mistakes

  • Trying settings until one works. With enough attempts something always works on the tested prices.
  • Using the out-of-sample data twice. After the first look it has become part of the search.
  • Adding a rule to remove each losing period. The curve improves and the system stops describing anything real.
  • Trusting a wide plateau of good settings. Neighbouring settings share most of their trades, so they tend to succeed and fail together.

Another example

Suppose a rule with no edge is tested in 20 versions, and a version is called promising if it scores better than 19 out of 20 random results would. Each version has a 5% chance of looking promising by luck. The chance that at least one of the 20 does so is 1 − 0.95 multiplied by itself 20 times, which is 64.2%. Nearly two times in three, a search through 20 worthless versions turns up something that looks like a discovery.

Questions people ask

What is overfitting in trading?

Overfitting is shaping a system so closely to past prices that it captures their accidents as well as anything lasting. It happens when many settings, rules or filters are tried and the best-scoring one is kept. The result looks excellent on the tested data and does worse on new data.

What is out-of-sample testing?

It is checking a system on prices that were kept apart while the system was being designed and tuned. The design uses the in-sample prices only. The out-of-sample prices are then used once, and their result is the first fair estimate of how the choice performs.

What is walk-forward analysis?

It is a repeated out-of-sample test. Settings are chosen on one stretch of data and traded on the next, then both windows move forward and the process repeats. The traded stretches together show how the whole habit of choosing and trading would have performed.

Should I optimise my strategy’s settings?

Only with care, and with data kept back. Trying a handful of sensible values and checking the choice on untouched prices is reasonable. Searching thousands of combinations for the best curve is overfitting, and most platform optimisers make that easy to do.

التاليHow many trades make a fair test?

الدروس مجانية للقراءة دون حساب. سجّل الدخول وسيتذكر PipCircle أين توقفت ويحفظ نتائجك ويمنحك شاراتك. سجّل الدخول مجانًا

Trading foreign exchange and CFDs carries a high risk of losing money. PipCircle Learn is education and is not investment advice.

SA flag

Showing PipCircle in العربية. Prefer another language?

We use cookies

Necessary cookies keep PipCircle working. Optional cookies (analytics, marketing, preferences) help us improve the product. You can change this any time from Settings → Privacy & Data. Read our Privacy Policy.