How to Backtest on TradingView β Complete Guide 2026
Backtesting is testing a strategy on historical data to see how it would have performed in the past. It’s the only reliable way to validate a strategy before risking real money.
TradingView has one of the best free backtesting tools on the market β the Strategy Tester. In this guide, I’ll show you how to use it from scratch.
What is backtesting?
It’s simulating your strategy with real historical data. For example: “If I had run this strategy on EUR/USD from January to December 2025, would I have won or lost?”
β οΈ Important limitations
Backtesting shows what would have happened, not what will happen. A profitable strategy in the past can fail in the future (volatility shifts, market conditions). Use backtesting as a filter, not a guarantee.
Indicator vs Strategy
On TradingView there are 2 types of Pine Script code:
| Type | Purpose | Backtesting? |
|---|---|---|
| Indicator | Shows signals on the chart | No |
| Strategy | Simulates automated entries/exits | Yes β |
To backtest, you need to convert an indicator into a strategy. AI does this easily.
Step by step
Open TradingView
Go to the chart of the asset you want to test (EUR/USD, BTCUSD, Volatility 75, etc.).
Open Pine Editor
Click the “Pine Editor” tab at the bottom. Delete the default code.
Paste a strategy
Use the ready example below or generate one with AI (“create a Pine Script v5 strategy with…”).
Add to chart
Click “Add to chart”. The strategy will be applied to the historical data.
Open Strategy Tester
At the bottom, click “Strategy Tester”. You’ll see the full backtest results.
Ready example strategy
EMA crossover strategy with RSI filter for backtest:
//@version=5
strategy("EMA Cross + RSI β IA Trader Pro", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.1)
// === PARAMETERS ===
emaFast = input.int(9, "Fast EMA")
emaSlow = input.int(21, "Slow EMA")
rsiPeriod = input.int(14, "RSI Period")
rsiBuy = input.int(40, "RSI minimum for buy")
rsiSell = input.int(60, "RSI maximum for sell")
slPercent = input.float(2.0, "Stop Loss %") / 100
tpPercent = input.float(4.0, "Take Profit %") / 100
// === INDICATORS ===
ef = ta.ema(close, emaFast)
es = ta.ema(close, emaSlow)
r = ta.rsi(close, rsiPeriod)
// === CONDITIONS ===
longCond = ta.crossover(ef, es) and r > rsiBuy and r < 70
shortCond = ta.crossunder(ef, es) and r < rsiSell and r > 30
// === EXECUTION ===
if longCond
strategy.entry("Long", strategy.long)
strategy.exit("Exit Long", "Long", stop=close*(1-slPercent), limit=close*(1+tpPercent))
if shortCond
strategy.entry("Short", strategy.short)
strategy.exit("Exit Short", "Short", stop=close*(1+slPercent), limit=close*(1-tpPercent))
// === PLOT ===
plot(ef, "EMA Fast", color.green, 2)
plot(es, "EMA Slow", color.red, 2)
How to interpret the results
| Metric | What it means | Ideal value |
|---|---|---|
| Net Profit | Total net profit | Positive |
| Total Trades | Number of trades | > 100 |
| Percent Profitable | % of winning trades | > 50% |
| Profit Factor | Gross profit / gross loss | > 1.5 |
| Max Drawdown | Largest equity drop | < 20% |
| Avg Trade | Average profit per trade | Positive |
| Sharpe Ratio | Risk-adjusted return | > 1.0 |
β Good strategy
+100 trades, +55% win rate (sample test only), profit factor > 1.5, drawdown < 20%. If it hits all these criteria in backtest, it’s worth testing on demo.
β Bad or overfitted
< 30 trades, profit factor < 1.2, drawdown > 30%, win rate > 90% (overfit suspect). Reject and refine.
Common mistakes
- Overfitting: Tweaking parameters too much until it looks “perfect” in the past. Usually fails in the future
- Small sample: Backtests with fewer than 50 trades aren’t reliable
- Ignoring spread/commission: In real Forex, the spread eats small profits
- Using only favorable data: Test on different periods (uptrend, downtrend, sideways)
- Lookahead bias: Code that “sees the future” β common in poorly written Pine Script
Tip: backtesting with AI
Ask AI (ChatGPT/Claude) to analyze the results. Paste the report and ask:
- “Does this strategy show signs of overfitting?”
- “Which parameters could I tweak to improve the profit factor?”
- “Is X% drawdown acceptable for that win rate?”
- “Convert this strategy to a Python + Deriv API bot”
π After validating in backtest, test on a live Deriv demo account:
Open Deriv Demo Account βπ Related
β TradingView Free: Complete Guide
β Build Indicators with AI
β 10 Pine Script Indicators
