I spent 17 years writing rules for a living, and the first thing I learned is that a chart read by eye cannot be wrong. If a stock falls after a "breakdown", the pattern worked. If it rises, the pattern was "a bear trap". A claim that survives every outcome tells you nothing. A rule is the opposite: it says exactly when to be in, when to be out and how much, so that a computer can run it over old data and report what it would have done. This module is about that conversion. It sets out what makes a rule testable, the four mistakes that make a test look better than it is (look ahead, survivorship, ignored costs and data snooping), how every test in this path is built, and the one number every later result is held against: what holding the Nifty 50 did over the same dates. It is education, not advice, and every figure is from a script you can run.
6By the end you can
- Write an indicator as a rule with an entry, an exit, a position and a cost, so that two people get the same trades.
- Say what look ahead bias is and show it in numbers on the same rule traded three ways.
- Explain why a stock index tested after the fact is a flattering sample, and why costs belong in every test.
- Explain data snooping with the Lo and MacKinlay, Sullivan, Timmermann and White, and Bailey and Lopez de Prado papers.
- Read the buy and hold baseline for January 2021 to September 2026 and know why its short window limits every later result.
- Run a rule through a short checklist before believing it.

What a testable rule is
Take a sentence from any trading chat: "The index looks strong above its 200 day average." You cannot test it. Strong for how long, by how much, and what do you do about it? Now write it again.
the 200 day average
Position: all in, else cash
Trade: next day's close
Cost: 0.1% each way
Read 3 more paragraphs, 185 words
A rule has four parts. The signal is a function of past prices only, evaluated at a stated time. The position says what you hold for each signal value: all in, all out, or a fraction. The timing says when the trade happens after the signal. The cost says what each trade takes. Leave one out and the test is not a test. Most "strategies" shared online leave out the timing and the cost, and those are the two parts that move a result most.
What cannot be written as a rule cannot be tested, and I treat it as opinion. "The market feels toppy" is not a signal. "A head and shoulders is forming" is one only after somebody writes down exactly how high the shoulders must be relative to the head, over how many days. Module 23.7 is about how much of chart lore survives that treatment.
A written rule also removes the decision at the moment it is hardest. The 200 day average does not know that the news is frightening. That is the argument of module 2.1, applied to charts.
The window and the baseline
All tests in this path use one file: the Nifty 50 price index, daily closes from 1 Jan 2021, taken from Yahoo Finance (symbol ^NSEI) and stored at frontend/public/data/nifty50-daily.json. Two properties of that file matter.
- It is a price index. Dividends are not included. Holding the index through a total return product would have earned a little more, in every row, so a rule that spends time in cash is compared with a slightly low baseline. I say so where it matters.
- It is short. I use closes dated 30 Sep 2026 or earlier: 1,420 closes, from 1 Jan 2021 to 30 Sep 2026, about 5.74 years. That is one stretch of Indian market history, with one pandemic recovery, one flat 2022 and one weak 2026. I cannot say how any rule behaves in a market that did something else, and neither can anyone who tests on this file. Every result in this path is one test, not proof.

The baseline is buy and hold: invest at the first close, pay 0.1% on the way in, hold to the last close. The script prints it.
Source: test script module-23-1, run on nifty50-daily.json, closes to 30 Sep 2026. Price index, dividends not included. Past figures, not a forecast.
Read 3 more paragraphs, 168 words
The same run gives the rest of the picture. Annualised volatility of daily returns is 14.0%. The index rose on 52.9% of days. The largest one day gain was +4.74% and the largest one day loss was -5.93%. By calendar year, with 2026 running only to 30 Sep: 2021 +23.7%, 2022 +4.3%, 2023 +20.0%, 2024 +8.8%, 2025 +10.5% and 2026 -13.4%.
Look at that last number. The window ends in a falling stretch, and that matters for the CAGR of every rule: they all finish on the same low. A window that ended in December 2025 would have a better baseline. This is one reason I do not trust any single CAGR from a short file, and why I report drawdown and time in market beside it.
One more fact for later: the index gained 61.2% in total between those two dates. A rule that sits in cash a quarter of the time has to avoid a large part of the bad days to keep up with that.
How every test in this path is built
Each module has a Python script in the RupeeCase repository, written with the standard library only. The rules are the same in all of them, and I state them once here.
Trade at the close of day t+1
Earn from day t+2 onward
Cost 0.1% of value per side
Cash earns 0% when out
The term this section turns on: Buy and hold
Read 2 more paragraphs, 171 words
The measures are plain. CAGR is the compound annual growth rate of the equity curve: the end value to the power of one over the years, minus one, with years counted from calendar days divided by 365.25. Maximum drawdown is the largest fall of the equity curve from a previous peak close. Trades counts every entry and every exit, so a round trip is two trades. Time in market is the share of days with money invested. Module 2.3 covers these measures in general.
A word on "same dates". A 200 day average does not exist for the first 199 closes, so rules with different warm up periods start on different days and their CAGRs compare different markets. In each module I fix one start date for all rules and give buy and hold from that same date. That is why the baseline figure changes from module to module: 8.67% over the full file here, and a different figure over a shorter window later. The dates always come with the number.
Look ahead bias
Look ahead bias means the test uses information that was not available when the trade was made. It is the most common error, and it is almost always accidental.
Two terms to hold on to from 23.1
| Timing | CAGR | Max drawdown | Trades |
|---|---|---|---|
| Buy and hold | 4.57% | -16.5% | 1 |
| Signal t close, trade t+1 close | 2.96% | -14.6% | 36 |
| Signal t close, trade t close | -0.43% | -20.8% | 36 |
| Uses day t's own return | 10.13% | -10.2% | 36 |
Test script module-23-1, section C. Nifty 50 price index, 25 Oct 2021 to 30 Sep 2026, 0.1% per side, cash at 0%. The last row is the error being demonstrated and cannot be traded.
Read 5 more paragraphs, 344 words
The usual form: the signal is computed from a day's close, and the trade is assumed to happen at that same close. In real life you see the close at 3:30 pm and the market has shut. A subtler form: the code computes a position on day t and multiplies it by the return of day t, so the rule earns the very move that created its signal.
I tested the same rule, price above its 200 day SMA (a simple moving average, defined in module 23.2), long when above and cash otherwise, three ways over the same window from 25 Oct 2021 to 30 Sep 2026. The only change is the timing.
The honest row is the second: 2.96% a year, against 4.57% for buy and hold. The last row, where the rule is allowed to earn the day's own move, shows 10.13%. Same rule, same data, same costs. The difference is information from the future.
The third row surprised me, and I report it because it is the point of the exercise. Trading at the same close as the signal is not much of a cheat in theory (you could, in principle, act on the last few minutes of the session), yet it came out at -0.43%, worse than the next close version. A one day shift on a noisy rule changes the answer by several points of CAGR in either direction. That tells me the 200 day rule on this file is sensitive to a single day of timing, and I should not take any of these three numbers as the "true" value of the rule. It is the spread between the three that I keep.
The defence is mechanical. The test frame above has a one day gap built in, and every script is written so that the position on day k comes from a signal at least two closes earlier. When I read a published backtest, the first thing I look for is the timing sentence. If I cannot find one, I treat the result as possibly cheated.
Survivorship bias and the index itself
Survivorship bias means the test universe contains only what survived to the end. A study of "all stocks listed now" leaves out the ones that were delisted, merged or went to zero. The ones left are the winners, so any rule appears better than it was.
Read 2 more paragraphs, 158 words
The Nifty 50 is a subtler case. NSE keeps the count at 50, so when a company falls out, another enters. The price series in the file is therefore not the return of a fixed list. It is the return of whatever list met the criteria at each date, which is what an index fund holder owned. But the stocks that leave tend to be ones that fell and the ones that enter ones that rose, so the index carries a mild survivor effect by design. I test an index, where the rules of membership are known and dated, and not a hand picked list of shares. Module 3.10 covers how NSE reconstitutes its indices.
If you test a stock rule, the universe must be what was investable on each date, not what exists now. I do not claim the Nifty 50 test is free of survivorship, only that it is a tradable instrument with a published history.
Costs
A rule that trades often pays the cost over and over, and the cost does not depend on whether the trade was right. Here is the arithmetic for 0.1% per side, where a round trip costs 0.2%. Suppose the price goes nowhere and the rule trades back and forth. The drag on a year's return, from the script:
₹100 in Allcap became about ₹424 in the model
| Round trips a year | Drag a year | On ₹10,00,000 |
|---|---|---|
| 1 | -0.20% | ₹1,999 |
| 4 | -0.80% | ₹7,972 |
| 12 | -2.37% | ₹23,726 |
| 24 | -4.69% | ₹46,889 |
| 50 | -9.52% | ₹95,208 |
Test script module-23-1, section B. Arithmetic on 0.1% per side, an illustration of cost and not a quote of any broker. Each drag is (1 - 0.001) to the power of 2 times the round trips, minus one.
Read 2 more paragraphs, 138 words
A rule that makes 50 round trips a year, about one a week, gives away close to a tenth of the portfolio every year before it has been right about anything. Few indicators earn that back on an index. The 200 day rule in the table above made 36 trades (18 round trips) in about five years. Short term rules in later modules make over a hundred.
0.1% per side is not a measured number for an Indian retail investor. It is a round figure chosen to show the size of the effect. Modules 23.2 to 23.4 also print each rule with no cost at all, so you can see how much of the gap to buy and hold is cost and how much is the rule itself. For the actual charges in India, module 1.5 lists them.
Data snooping and overfitting
This is the mistake that fools the careful. Say you try 30 rules and report the one that scored highest. The report is not "this rule works". It is "the maximum of 30 outcomes was this high", and the maximum of many noisy outcomes is high even when none of them has any skill.
Three papers set out the problem, and I read each abstract or page for this module.
- Lo and MacKinlay (1990), "Data-Snooping Biases in Tests of Financial Asset Pricing Models", Review of Financial Studies 3(3), pages 431 to 467. Their point is that tests can give misleading answers when properties of the data are used to build the test, as when portfolios are sorted on some characteristic that was picked because it looked interesting. Through analytical calculations, simulations and two empirical examples they show that the effect of such snooping can be substantial.
- Sullivan, Timmermann and White (1999), "Data-Snooping, Technical Trading Rule Performance, and the Bootstrap", Journal of Finance 54(5), pages 1647 to 1691. They take the 26 trading rules studied by Brock, Lakonishok and LeBaron (1992), widen the universe, apply it to 100 years of daily Dow Jones Industrial Average data and use White's Reality Check bootstrap to measure and remove the data snooping bias, testing performance across all the rules examined and not only the winner.
- Bailey, Borwein, Lopez de Prado and Zhu, "The Probability of Backtest Overfitting", Journal of Computational Finance 20(4), published in 2017 (SSRN 2326253, first posted in 2013). They propose a framework, combinatorially symmetric cross validation, to estimate the probability that the top backtest in a set is overfit, and they argue that a simple hold out check is often unreliable in this setting.

Read one more paragraph, 45 words
I do not need their mathematics to show the effect. The script does three experiments on the Nifty 50 file, all from the 301st close (21 Mar 2022) to 30 Sep 2026, over which buy and hold earned 6.33% a year with a -15.8% drawdown.
Experiment 1: try 30 rules
Price above its n day SMA, for n = 10, 20, up to 300. Thirty rules, one idea, one parameter. Highest CAGR: n = 210 at 5.86%, with a -12.7% drawdown and 40 trades. Lowest: n = 20 at 0.33% with 106 trades. The median of the 30 was 3.82%. How many beat buy and hold on CAGR? None of 30. How many had a smaller drawdown than buy and hold? 19 of 30.
Read one more paragraph, 60 words
Read that as a researcher would. If I had only shown n = 210, I could say "the 210 day rule gave up under a point of return and had a smaller worst fall" and it would be true. It would also hide the 29 other rules, including the one that earned 0.33%. The honest statement is the whole table.
Experiment 2: pick on one half, test on the other
I split the same window in two: 21 Mar 2022 to 27 Jun 2024, then 27 Jun 2024 to 30 Sep 2026. I chose the highest CAGR n out of the 30 on the first half. It was n = 150, with 13.51% against 16.10% for buy and hold, a drawdown of -7.8% against -15.3% and 13 trades. Then I applied n = 150, unchanged, to the second half. Result: -3.96% a year, against -2.71% for buy and hold, with a -16.2% drawdown against -15.8%. Among the 30 rules in that second half, n = 150 ranked 21st.
Read one more paragraph, 69 words
So the rule that led in sample did not lead out of sample. It lost to buy and hold in both halves, and the thing that made it look good in the first half, a smaller drawdown, did not appear in the second. One split is a small test (two regimes, one choice), but it is the kind of check every claimed result should pass before anyone trusts it.
Experiment 3: rules with no information
Here is the one I find most useful. I built 1,000 rules that know nothing: every 21 sessions, flip a fair coin and be in or out for the next block. The random generator is seeded at 2026, so you get the same 1,000 rules. Median time in market 50.2%, median CAGR 2.60%. Of the 1,000, 128 beat buy and hold on CAGR. The top one earned 12.82% a year with a -9.7% drawdown, 28 trades and 57.7% of the time in market. And 580 of the 1,000 had a smaller maximum drawdown than buy and hold.
Where this section sits in module 23.1
- Top of 1,000 random rules12.82%
- Buy and hold6.33%
- Top of 30 SMA rules (n = 210)5.86%
- Median of the 30 SMA rules3.82%
- Median of 1,000 random rules2.60%
Test script module-23-1, sections D and F. Nifty 50 price index, 21 Mar 2022 to 30 Sep 2026, 0.1% per side, cash at 0%. Illustration of data snooping, not a rule anyone could have chosen in advance.
Read 2 more paragraphs, 159 words
A coin has no skill. Yet if I had run 1,000 of them and shown you the top one, it would have beaten the index by a wide margin with a smaller drawdown. Anyone who tests many indicators, many parameters and many stop levels on one short file and reports the top one is, in effect, showing you the top coin. This is the data snooping that Lo and MacKinlay, and Sullivan, Timmermann and White, describe, and the overfitting that Bailey and Lopez de Prado put a probability on.
There are three practical defences, none of them perfect. First, count how many rules were tried and report all of them, as I did with the 30. Second, keep part of the data untouched and use it once. Third, prefer a rule with few parameters and a reason that exists before the data, since each free parameter is one more coin. Module 5.5 goes deeper on out of sample practice.
What one test can and cannot say
Suppose a rule passes every check above. What have you learned? That in one 5.74 year sample, trading one index at closing prices with an assumed cost, it did a certain thing. You have not learned that it will do it again.
Read 3 more paragraphs, 216 words
The short file has three limits. It has one dominant regime: a recovery, a sideways stretch, then a fall. It has few independent events: a 200 day rule that makes 18 round trips has 18 data points, and the average of 18 noisy numbers has a wide margin of error. And it ends on a low, which flatters rules that were out of the market at the end and penalises those that were in.
Longer academic studies address the first two. Brock, Lakonishok and LeBaron (1992), the classic test of technical rules, used Dow Jones data from 1897 to 1986. Sullivan, Timmermann and White extended the sample to 100 years. Those are US data and not Indian data. I use the Indian file because it is the one a reader can trade, and I say plainly that it is too short to settle anything. What it can do is show how to run a test, how big the cost and timing effects are, and what an honest report looks like.
For the same reason I give a result with its dates, never a verdict that an indicator "works". The 200 day rule can trail buy and hold on this file while a long US study finds the opposite. Both can be true. They answer different questions.
A rule checklist
These are the questions I put to any rule, mine or anyone else's, before looking at its return.
- Can I write it in four lines? Signal, position, timing, cost. If not, it is a story.
- Is the timing stated and at least one close after the signal?
- What is the cost per trade and how many trades are there? Multiply them.
- How many versions were tried? One parameter set shown from a grid of 30 is a different claim from one set tried once.
- Was any data held back? If the same dates chose and judged the rule, it was graded on its own homework.
- Which dates, and against what? The same dates for the rule and for buy and hold, with the baseline printed.
- How long, and how many independent trades? A handful of round trips is a story, not a statistic.
- What did it do when it was wrong? The drawdown and the worst trade matter as much as the average.

Where this meets how RupeeCase works
The same logic is the reason RupeeCase publishes its index algorithms as rules and not as opinions. A RupeeCase strategy is a written rule that rebalances on stated dates, and its record is shown as model, back tested, with the date it was run. That record carries every limit set out above: it is a model, it was built in hindsight, and the costs of your own account differ from the model's. Module 2.6 sets out the difference between a model history and a portfolio you hold, and module 2.4 explains backtesting itself. Nothing in this path is a RupeeCase strategy. These are indicator tests on a public index, done to teach.
Common mistakes
- Trading at the same close as the signal, or earning the day's own move. On the 200 day rule this moved the result from 2.96% to 10.13% a year in the same data.
- Leaving out costs. At 50 round trips a year, 0.1% per side takes 9.52% a year before the rule has been right or wrong.
- Showing the winner of a grid. The top of 30 SMA rules looked reasonable, but none of the 30 beat buy and hold here.
- Grading a rule on the data that chose it. The first half favourite, n = 150, ranked 21st of 30 in the second half.
- Treating a coin flip with a good run as skill. The top of 1,000 random rules earned 12.82% a year.
- Calling a 5.74 year file proof. It is a sample of one market regime.

What I'd keep from this
- A testable rule has a signal, a position, a timing and a cost. Without all four it is not a test.
- Every test in this path signals at the close of day t, trades at the close of day t+1, charges 0.1% per side and holds cash at 0%.
- The baseline is buy and hold on the Nifty 50 price index: 8.67% a year from 1 Jan 2021 to 30 Sep 2026, with a maximum drawdown of -17.2%. The file is short and ends on a weak stretch.
- Look ahead moved one rule's CAGR from 2.96% to 10.13% on the same data. A one day timing shift changed it again.
- Costs scale with trades: 12 round trips a year drag 2.37% a year at 0.1% per side.
- Of 30 SMA rules, none beat buy and hold on CAGR here. The top of 1,000 random rules earned 12.82% a year. Count what you tried.
Questions readers ask
What is look ahead bias in a backtest?
It is using information that was not available at the moment of the trade, for example computing a signal from a day's close and trading at that same close, or multiplying a position by the same day's return. In the 200 day rule test here it raised the result from 2.96% to 10.13% a year.
What is data snooping?
It is trying many rules, parameters or periods on one data set and reporting the one that scored highest. The reported return is then the maximum of many noisy results and overstates what to expect. Lo and MacKinlay (1990) and Sullivan, Timmermann and White (1999) study it; the experiment above shows 1,000 coin flip rules whose top performer earned 12.82% a year.
Why does every test in this path charge 0.1% per side?
As an illustration of costs. A rule's turnover decides how much it pays, and the cost does not depend on whether the trade was right. It is not a quote of any broker, and real costs vary.
Why is a short data file a problem?
Because the window holds one market regime and few independent trades. The file used here covers 1 Jan 2021 to 30 Sep 2026, about 5.74 years, so every result is one test and not proof.
Allcap fell at most 19.4% below its model high, month end to month end
Rules and figures in this module were last verified on 27 Nov 2026. Tax and regulatory rules change; check the source before acting.
