TradingView's strategy tester and its pitfalls
Lesson 24 · about 11 min
TradingView's strategy tester is the most accessible backtesting tool most retail traders will use. You write a strategy in Pine Script, add it to a chart, and a panel shows the trade list, equity curve and statistics. It is a good tool for a first pass and a bad tool to trust without understanding its defaults, because several of them are set in ways that flatter results.
What it does well
- Runs on any chart and timeframe you can see, including forex and crypto from many exchanges.
- Marks every trade on the chart, so you can check fills against bars by eye.
- Exports the trade list, which lets you do the Module 5 analysis in a spreadsheet.
- Supports the order types you need: market, limit, stop, and stop-limit, with a broker emulator that decides fills from bar data.
The defaults that mislead
| Setting | Default | Problem | Fix |
|---|---|---|---|
| Commission | 0 | Every trade is free | Set your real commission per order or per unit |
| Slippage | 0 ticks | Every market and stop order fills at the exact price | Set at least 1 tick; more for fast markets |
| Order size | Percent of equity, often 10% or more | Sizing does not use the stop, so R is inconsistent | Size from stop distance in the script, or use a fixed quantity and convert to R afterwards |
| Pyramiding | Off (good) | Turning it on multiplies exposure silently | Leave off unless it is part of the rules |
| Fill on bar close | Off | Orders placed on a bar fill at the next bar's open, which is correct | Leave off; turning it on introduces look-ahead |
| Bar magnifier | Off on lower plans | Intrabar sequence of stop and target is guessed | Turn on if available; otherwise assume stop-first |
| Historical bars | Limited by plan | Short tests on intraday data | Be aware the sample is small; test on higher timeframes too |
The two that cause the most damage are commission and slippage at zero. A scalping script with 800 trades and a "net profit" of 40% often shows a net loss the moment a single tick of slippage is added.
Intrabar assumptions
The broker emulator sees only open, high, low and close for each historical bar and must guess the path inside it. Its rule of thumb: if the close is above the open, it assumes the price went open → low → high → close; otherwise open → high → low → close. When your stop and target are both inside the bar, the fill depends on that guess. It is a reasonable guess and it is still a guess. With the bar magnifier enabled, the emulator uses lower-timeframe bars to resolve the sequence, which is much better. Without it, run your strategy with the target moved just outside the typical bar range and see how much the result changes; that is your exposure to the guess.
Repainting and lookahead
Two script-level traps produce results that cannot be reproduced live:
- Higher-timeframe data with lookahead. Requesting a daily value from an intraday script can return the daily bar's final close before that day has ended, unless the request is configured to avoid it. The historical plot then knows the future, and the strategy trades on it. Check that any higher-timeframe request uses the completed prior bar.
- Calculation on every tick. In real time, a script can evaluate on every price update, while on historical bars it evaluates once at the close. A condition that is true mid-bar and false at the close will trigger live and not in the backtest, or the reverse. Make sure entry conditions are evaluated on confirmed bars, and set the script to behave the same way in real time.
The symptom of both is a strategy whose forward-tested trades, watched live, do not match what the tester later shows for the same bars. Any mismatch means the historical results are unreliable.
Key idea: The strategy tester's defaults are zero commission, zero slippage, percent-of-equity sizing, and a guessed intrabar path. Change the first three before reading a single statistic, and treat the fourth as an uncertainty to measure.
Reading the performance panel
The summary panel reports net profit, percent profitable, profit factor, max drawdown, and average trade. Three cautions:
- Net profit in percent depends on the sizing setting. With percent-of-equity sizing the result compounds; with fixed quantity it does not. Neither is R. Export the trade list and compute R yourself using the stop distance you know.
- Max drawdown is reported on the intrabar equity, including open positions, which is correct and often larger than closed-trade drawdown. Use it.
- The "Sharpe ratio" shown is computed on a monthly basis in most versions and is not comparable with the daily Sharpe from Module 5. Compute your own from the exported list if you need one.
A sensible workflow
- Write the rules in Pine exactly as specified in Module 3, with orders placed on confirmed bars and filled next bar.
- Set commission and slippage to your real values before the first run.
- Size from the stop in the script so that each trade risks a fixed fraction of equity; if that is awkward, use fixed quantity and convert to R after export.
- Export the trade list. Do the Module 5 and Module 6 analysis outside the platform.
- Check a handful of trades on the chart against the rules by eye.
- Forward-test in real time on the same chart for a few weeks and compare the trades the script takes live with the historical markers for those bars. Any difference is a repaint or a tick-evaluation issue.
Try it: Take any public strategy script and run it with the defaults. Note net profit and profit factor. Then set commission to your real rate and slippage to one tick, and rerun. Record how much of the result disappears. This is the single most instructive five minutes you can spend with the tool.
Recap
- The strategy tester is convenient and its defaults are optimistic: zero commission, zero slippage, percent-of-equity sizing.
- Intrabar fills are guessed from OHLC unless the bar magnifier is on; measure your sensitivity to the guess.
- Higher-timeframe lookahead and every-tick evaluation cause backtests that live trading cannot reproduce.
- The panel's profit and Sharpe are not in R and not comparable; export the trade list and compute your own.
- Forward-test for a few weeks and compare live trades with historical markers to catch repainting.
See it drawn
Original diagrams for the ideas on this page. Illustrative, not real market data.