Guide
How to Backtest an RSI Strategy on Indian Stocks
To backtest an RSI strategy, define the exact crossing rules, select an Indian stock and timeframe, and run a strategy rather than an RSI indicator alone. TradingLead accepts Python and a documented Pine subset for backtesting. Compare results after costs and on unseen periods; an RSI threshold is not a buy recommendation.
Define a testable RSI rule
This example buys when 14-period RSI crosses back above 30 and closes when RSI crosses below 70. These are crossing events, not instructions to buy repeatedly while RSI is low. A stock can remain overbought or oversold for a long time.
The numbers below are starting assumptions for learning, not an optimized strategy.
Enter an explicit strategy
In TradingLead's TLScript-Pine editor, use a strategy() declaration rather than indicator():
//@version=6
strategy("RSI rebound research", overlay=true, initial_capital=100000, default_qty_value=1)
length = input.int(14, "RSI length", minval=2)
lower = input.float(30, "Entry crossing level")
upper = input.float(70, "Exit crossing level")
r = ta.rsi(close, length)
enterLong = ta.crossover(r, lower)
exitLong = ta.crossunder(r, upper)
if enterLong
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")
This deliberately simple script has no stop, target or end-of-day square-off. Define those separately before evaluating an intraday trading plan. Do not treat it as a ready-to-trade system.
Follow the Pine backtesting guide to compile, inspect settings and start a run. TradingLead executes Pine through its own emulator; Python and Pine have different execution adapters.
Make the Indian-stock test meaningful
Pick a liquid stock supported by your feed, fix the interval and record the actual history used. Daily and five-minute RSI represent different horizons. Avoid a period chosen because you already know the stock rebounded.
In the Pine execution settings, review commission and slippage. Pine slippage is specified in integer ticks, not the basis-point setting used by the Python engine. Costs should reflect your own assumptions; a profitable zero-cost test may not survive frequent trading.
Check more than net profit
Inspect entry and exit locations, drawdown, trade count and any position still open at the end. Then run the unchanged rules on later dates. If you tune the RSI period, follow optimization without overfitting, and keep an untouched final check.
Steps
- Choose an Indian stock available on your chart feed and fix the interval.
- Open TLScript-Pine in Indicator Studio and enter the example strategy.
- Compile, review the inputs and execution settings, then use Apply & backtest.
- Choose a history range and enter cost assumptions before starting the run.
- Inspect completed trades and test the unchanged rules on a later period.
Limitations
- The example is educational, long-only and has no protective stop or time-based exit.
- Pine uses TradingLead's emulator, not TradingView's execution engine; full compatibility and identical results are not promised.
- Historical candle availability depends on the selected source; backtests are bounded to 20,000 candles.
- Historical results do not predict returns or establish suitability for live trading.
Frequently asked questions
- Is RSI below 30 enough to define a backtest?
- No. Specify whether the rule means below 30 on every candle or a crossing event, when orders become eligible, position size, exit rules and costs.
- Can I backtest by adding the RSI indicator?
- An oscillator plot is not an executable strategy. TradingLead needs Python strategy decisions or a supported Pine strategy() script.
- What is the best RSI period for Indian stocks?
- There is no universally best period. Fourteen bars is a common educational starting point, not evidence that it is optimal for your stock or interval.
Related
Last updated: