# How to backtest a stock trading strategy honestly

> A practical guide to backtesting stock strategies on NSE data: look-ahead and survivorship bias, costs, slippage, position sizing, and backtest versus live results.

Canonical: https://getmarketstrength.com/stock-strategy-backtesting
Last updated: 2026-10-28

By Market Strength Scanner · Updated 2026-10-28 · [How the data works](https://getmarketstrength.com/methodology)

A backtest replays a set of trading rules on past prices to see how they would have behaved. Done carelessly it produces beautiful numbers that no one could have earned. This guide covers the traps that matter most for Indian stocks, and how Market Strength’s backtests handle each one.

## What a backtest can and cannot tell you

A backtest answers a narrow question: if these exact rules had been followed on this data, with these assumptions, what would have happened? It is useful for rejecting bad ideas, comparing rule sets and understanding drawdowns. It cannot tell you what will happen next, and every result is hypothetical: no money was at risk and no orders met a real order book.

## Look-ahead bias: using tomorrow’s information today

Look-ahead bias creeps in whenever a rule uses data that was not available at the moment of the decision. Common examples:

- Buying at the same close that generated the signal, when the signal needed that close to exist.
- Ranking stocks with indicators computed on the full price history, including future bars.
- Using today’s sector or theme lists, or today’s index membership, to choose stocks in the past.

The fix is to compute everything “as of” each test date and to trade on the next session. Market Strength’s backtests price trades at the next session’s close and recompute RS ratings, sectors and themes using only prices up to each date.

## Survivorship bias: the stocks that disappeared

If you test on today’s Nifty 500 list, you only test on companies that survived and grew big enough to be in it today. The losers that shrank, were removed or were delisted are silently missing, so results look better than reality.

Market Strength rebuilds the stock list on each test date from that date’s size (today’s share count × that day’s price), so stocks that later fell out of the index stay in the test. Two gaps remain and are shown beside results: NSE does not publish full historical membership, so the list is a close approximation, and companies that have since been delisted are missing because their price history is not in the data source.

## Costs, slippage and tax

Every trade in India carries brokerage, securities transaction tax, exchange and regulatory charges, stamp duty and GST, and the price you get is rarely the exact close (slippage). Your broker’s contract note lists the actual charges. For frequent strategies these costs decide whether an edge survives.

**Illustrative arithmetic, not a result:** a strategy that makes 24 round trips a year at a 0.5% total cost per round trip gives up about 12% of traded capital per year to costs before it earns anything. The same rules rebalanced quarterly (4 round trips) give up about 2%.

Market Strength deducts a trading cost on every buy and sell (0.5% per round trip by default for India, adjustable) and can apply Indian short- and long-term capital-gains tax, with the settings shown next to the results.

## Data quality and history

Free daily data can contain gaps, bad ticks and late adjustments for splits, bonuses and dividends. Check any result that hinges on a handful of trades, and look at the trades themselves, not just the summary line. Short histories are another trap: a rule tested only in a strong bull market has not been tested.

## Position sizing and risk

The same entries can produce very different outcomes depending on sizing. Equal-weight portfolios, a fixed number of holdings and a cap on any one stock make results easier to interpret. Always read the maximum drawdown and the longest losing stretch: those decide whether a real person could have kept following the rules.

## Avoiding overfitting

If you try enough settings, one will look excellent by chance. Choose settings on one period and check them on another, prefer rules that work across a range of nearby parameters, and be suspicious of any rule with many conditions and few trades.

## Backtest results versus live results

A backtest is a hypothesis; a live record is evidence. Market Strength keeps them separate. The backtests are labelled hypothetical, and for India the app also keeps a forward track record: picks are logged before each month and never edited afterwards. Comparing the two over time shows how much of a backtest’s edge survives real-world conditions.

## Backtesting tools in Market Strength

- **Stock momentum backtest:** rank stocks by a weighted mix of 1-year, 6-month, 3-month and 1-month returns, hold the top N, rebalance on a schedule, with optional buffers and market filters.
- **Sector rotation backtest:** rank themes at each month-end and compare with official NSE thematic indices.
- **Rules-based tests:** set entry, stop, target and trailing-exit rules and test them on daily data.

See [momentum backtesting without hindsight](https://getmarketstrength.com/momentum-backtest) for how each tool is set up, and the [methodology page](https://getmarketstrength.com/methodology) for the full list of assumptions.

## Frequently asked questions

### What is look-ahead bias in backtesting?

Using information in a test that was not available at the time of the decision, such as trading at the close that produced the signal or selecting stocks from today’s index list.

### What is survivorship bias?

Testing only on companies that still exist or are in an index today, which leaves out the ones that failed and makes results look better than they were.

### Do Market Strength backtests include costs?

Yes. A per-trade cost is deducted (0.5% per round trip by default for India, adjustable), and Indian capital-gains tax can be switched on.

### Are backtest results a forecast?

No. They are hypothetical results of rules applied to past data, with known limitations. Future results can differ materially.

### Can I backtest my own rules?

Yes, within the rules-based tester: entry, stop, target and trailing exits on daily NSE data. It does not run arbitrary code.

**✨ Ask the AI**Inside the scanner you can type questions like: “Compare the sector rotation backtest with the NSE thematic indices and explain the results.” The AI answers from the scanner’s own data. [How the AI assistant works](https://getmarketstrength.com/ai-stock-analysis)

## Keep exploring

[All guides](https://getmarketstrength.com/learn)[Momentum investing in India](https://getmarketstrength.com/momentum-investing-india)[Backtest momentum strategies without hindsight](https://getmarketstrength.com/momentum-backtest)[Market breadth](https://getmarketstrength.com/market-breadth-indicator)

---
Source: Market Strength Scanner (https://getmarketstrength.com). Educational content, not investment advice. Cite with the canonical URL above.
