Skip to content

Guide

How to Backtest a Trading Strategy on TradingLead

To backtest on TradingLead, open a chart at /charts, open the Backtesting tab, choose a Python strategy (or the bundled example), set capital, costs and history range, and click Run backtest. When the run completes, read net P&L, drawdown, win rate and profit factor alongside the trades on the chart. Results are simulations on past data, not predictions.

This guide walks through a complete backtest in TradingLead's Backtesting panel using a Python strategy. If your strategy is a Pine Script strategy(), follow Backtest a Pine strategy instead. The setup and reading steps are the same.

Before you start

  • You need access to the TradingLead charts workspace (5-day free trial, then subscription; see pricing).
  • Decide what you want to learn. A backtest is most useful when you have a specific rule set, for example "buy when the 20-period average crosses above the 50, exit on a 2% stop or 4% target".
  • New to backtesting? The Backtesting Lab shows the common mistakes in about 20 minutes.

Step 1: Open the chart you want to test

Go to tradinglead.in/charts. Pick the data feed, symbol (for example a Nifty 50 stock or index available on your feed) and interval. The backtest captures exactly this chart context. There is no separate symbol box in the backtest form, so set the chart first.

Step 2: Open the Backtesting tab

In the bottom panel, open Backtesting. (The neighbouring Paper Trading tab uses the same engine for manual practice.)

Step 3: Choose the strategy

Set the language to Python and choose a script you saved in Indicator Studio, or keep the bundled example. Then choose an execution mode:

  • Vectorized: fastest; processes up to 20,000 candles. Your code sees the full captured history, so make sure it only uses past values when generating each signal.
  • Sequential: your code runs after every completed candle with only the revealed prefix and the actual simulated account (balance, position, pending orders). It is limited to 250 candles, and it suits account-aware sizing.

Step 4: Set realistic assumptions

Open the setup and Advanced settings:

SettingDefaultTip
Initial capital1,00,000Use the amount you'd actually allocate.
Quantity1Match a realistic position size or lot.
Commission5 bpsAdd your broker's charges; fixed per fill and per unit/lot are also available.
Slippage2 bpsRaise this for illiquid stocks or fast intraday intervals. See slippage.
Stop % / Target %2% / 4%Set 0 to disable. Trailing stop is 0 (off) by default.
ShortingOffEnable only if your strategy shorts.
Warmup bars20Lets indicators settle before signals count.

Under Instrument & cost assumptions you can also choose lots, a contract multiplier, tick size and a user-assumed margin model. These are your assumptions, not verified broker rules. Taxes are not modelled.

Finally, choose the history range: leave dates empty to use the latest closed candles up to the cap, or enter explicit dates. An optional session schedule lets you pin trading hours, holidays and special sessions for intraday data.

Step 5: Run and wait for completion

Click Run backtest, review the preflight summary, then click Start backtest. The run first shows as preparing while history is fetched and the strategy executes. Wait for completed. If it fails, read the message: TradingLead stops on missing history, invalid candles or session mismatches instead of quietly testing fewer candles.

Step 6: Read the results honestly

Start with the summary, then open Analytics:

  • Net P&L after fees, and net P&L including open mark-to-market.
  • Max drawdown: the worst peak-to-trough fall in candle-close equity. Ask yourself whether you could sit through it.
  • Win rate and profit factor: read them together, since a high win rate with small wins and large losses can still lose money.
  • Expectancy: average net P&L per closed position.
  • Number of trades: a handful of trades is not enough evidence.
  • Buy-and-hold benchmark for the same period: did the strategy actually beat simply holding?
  • Costs: total fees paid, and how much of gross profit they consumed.

Sharpe ratio and annualized volatility appear only after you enter explicit sampling assumptions (samples per year, interval, risk-free rate).

Step 7: Inspect trades on the chart

Entry and exit arrows appear on the chart. Use Chart display / range to show labels for all trades or only the selected one, plus connecting lines, stop/target segments and open-position levels. Click any row in the trade grid to jump to it on the chart. Check a few trades by eye: do entries happen where your rules say they should?

Step 8: Save, compare or go further

  • Save a stopped run to the saved-run library, and compare runs tested on the same candles.
  • Stress-test inputs with the Strategy Optimizer, preferably with a holdout or walk-forward split.
  • Rehearse the rules manually with paper trading.

Common mistakes to avoid

  • Testing only a period where the idea obviously worked.
  • Leaving costs at zero. Frequent intraday strategies are especially sensitive.
  • Using future values in vectorized code (lookahead bias). TradingLead cannot certify that your code is free of it.
  • Tuning many settings on the full history and trusting the best one.
  • Treating a backtest as a forecast. It is a simulation on past data, not investment advice.

Steps

  1. Open /charts and choose the symbol, feed and interval.
  2. Open the Backtesting tab in the bottom panel.
  3. Select Python and a saved script or the bundled example.
  4. Set initial capital, quantity, commission, slippage, stops and history range.
  5. Click Run backtest, review the preflight, then Start backtest and wait for completed status.
  6. Read metrics and Analytics, then inspect trades on the chart.
  7. Save the run, or move on to the Strategy Optimizer or paper trading.

Limitations

  • Backtests are simulations on historical candles; past performance does not guarantee future results.
  • Candle-level fills; no tick data or order-book liquidity.
  • Costs and margin are user assumptions; taxes are not modelled.
  • Sequential Python is limited to 250 candles; vectorized and Pine to 20,000.
  • Data coverage and quality depend on the chart's data feed.

Frequently asked questions

Do I need to install Python to backtest on TradingLead?
No. Python strategies run in an isolated WebAssembly runtime in supported browsers, or in the Desktop app's native runtime. Scripts that use TradingLead's Python SDK helpers or operating-system modules need the Desktop app.
What is the difference between vectorized and sequential mode?
Vectorized mode runs your calculation over the whole history at once and supports up to 20,000 candles. Sequential mode calls your code after every completed candle with only past data and the real simulated account state, and is limited to 250 candles.
Why did my backtest fail instead of running on fewer candles?
TradingLead fails the run if the data source can't supply the requested window, or if candles are invalid or outside the session schedule. It does this on purpose so a shorter or gapped test is never presented as complete. Reduce the range or check the feed.
What costs should I enter for Indian stocks?
Enter what your own broker and the exchange actually charge. The panel accepts commission in basis points, fixed per fill and per unit or lot, plus extra fees and slippage in basis points. TradingLead does not auto-apply STT, stamp duty or GST in the main backtester.
How many backtests can I keep?
Three active runs per account. Save stopped runs to the local saved-run library (up to 100 runs) and delete old active runs to free a slot.

Last updated: