Search Modes — Sequential vs Smart
Sequential Mode tests every combination in the parameter grid — guaranteed to find the global best on the test window, but combinatorial: 4 inputs at 20 steps each = 160,000 runs. Smart Mode optimizes one input at a time, locks the best value, then moves to the next input, repeating for N rounds — dramatically fewer runs, no global-best guarantee, but practical on large grids. Pick by grid size: ≤ a few thousand → Sequential, otherwise → Smart.
Sequential Mode
Sequential Mode is the exhaustive grid search. It iterates through every combination of the input ranges you defined.
The number of runs is the product of the steps per field:
total runs = steps_field_1 × steps_field_2 × ... × steps_field_N
| Setup | Steps per field | Total runs |
|---|---|---|
| 2 inputs, 10 steps each | 10 × 10 | 100 |
| 3 inputs, 20 steps each | 20 × 20 × 20 | 8,000 |
| 4 inputs, 20 steps each | 20⁴ | 160,000 |
| 5 inputs, 10 steps each | 10⁵ | 100,000 |
At roughly 1-3 seconds per backtest, 8,000 runs is around 2-6 hours. 160,000 runs is days. Plan your ranges accordingly.
| Aspect | Sequential |
|---|---|
| Pros | Guaranteed to find global best on the test window. Deterministic results — same setup, same numbers. |
| Cons | Combinatorial explosion. Quickly impractical above a few thousand combinations. |
| When to use | Small parameter spaces (≤ ~5,000 combinations) or when you need absolute certainty for a final tune. |
Smart Mode
Smart Mode is a heuristic — it doesn't test every combination. Instead it optimizes inputs one by one, locking in the best value before moving on, and repeats for the number of search rounds you define. Here is a worked example with three inputs:
3 input fields, each with its own range:
Field 1: [1 … 100]
Field 2: [1 … 50]
Field 3: [1 … 150]
Start with every field at its minimum:
Field 1 = 1, Field 2 = 1, Field 3 = 1
Round 1
Sweep Field 1 over [1–100], hold Field 2 = 1, Field 3 = 1 → best Field 1 = 45
Sweep Field 2 over [1–50], hold Field 1 = 45, Field 3 = 1 → best Field 2 = 20
Sweep Field 3 over [1–150], hold Field 1 = 45, Field 2 = 20 → best Field 3 = 31
End of round 1: (45, 20, 31)
Round 2 (starts from the round-1 result)
Sweep Field 1 over [1–100], hold Field 2 = 20, Field 3 = 31 → best Field 1 = 80
Sweep Field 2 over [1–50], hold Field 1 = 80, Field 3 = 31 → best Field 2 = 47
… and on through Field 3
Repeat for N rounds, or stop early when a round produces no improvement.
The number of runs:
total runs = (steps_field_1 + steps_field_2 + ... + steps_field_N) × rounds
| Setup | Per-round runs | 3 rounds | Sequential equivalent |
|---|---|---|---|
| 3 inputs, 20 steps each | 60 | 180 | 8,000 |
| 4 inputs, 20 steps each | 80 | 240 | 160,000 |
| 5 inputs, 10 steps each | 50 | 150 | 100,000 |
Two orders of magnitude fewer runs. Smart Mode also short-circuits if a round produces no improvement — so the practical runtime is often less than the worst case.
| Aspect | Smart |
|---|---|
| Pros | Massively faster on large grids. Scales to many inputs without the combinatorial explosion. Early-stops when improvement stalls. |
| Cons | No global-best guarantee. Can get stuck in a local optimum if Field 1's best in isolation isn't the best in combination with other fields. |
| When to use | Large parameter spaces (>5,000 combinations), broad exploration phases, or when you want a fast first pass. |
Search criterion (what to optimize for)
Pick one criterion for the run — Strategy Finder sorts and "best result" decisions are based on this metric.
| Criterion | Optimizes for | Watch out for |
|---|---|---|
| Net profit | Highest total currency P&L | Overfits on trending markets. Long-only on a bull window always looks great. |
| Percent profitable | Highest win rate | A high win rate with small wins and big losses can still lose money overall. |
| Profit factor | Highest gross-profits-to-gross-losses ratio | Less prone to overfit than net profit, but still gameable by cherry-picking trade size. |
For most strategies, profit factor + drawdown filter is the most robust pairing.
Drawdown filter
The drawdown filter excludes any combination whose max drawdown exceeds your threshold from the ranking (and optionally from the run itself).
This is the single most important guardrail against backtest overfitting. Without it, the "best" parameters will always be the most aggressive ones — and they'll blow up live.
| Threshold | Typical use |
|---|---|
| ≤ 5% | Conservative, low-leverage strategies |
| ≤ 10-15% | Mainstream — most published systems target this range |
| ≤ 20-25% | Aggressive momentum / trend-following |
| > 25% | You're optimizing for noise |
Wait function
Strategy Finder injects a configurable delay between each backtest run. The delay exists because TradingView's UI can freeze or rate-limit if the Strategy Tester is driven too fast.
| Delay | Effect |
|---|---|
| 0-500 ms | Fast, but flaky on complex strategies — TV may skip a tester refresh |
| 1-3 seconds | Recommended default — stable across most strategies |
| 3+ seconds | Use for very complex Pine scripts that take a while to recompute |
Save / Load search configurations
A saved config bundles:
- The list of inputs you're varying
- Each input's min, max, step
- Search criterion and drawdown filter
- Search mode (Sequential / Smart) and round count
- Wait delay
Use cases:
- Same strategy, multiple pairs — load the config once per symbol.
- Same strategy, multiple timeframes — sweep on 1h, then load again on 4h.
- Walk-forward analysis — re-run the same config across rolling windows.
CSV Export
Every result row exports to CSV with the input columns plus the metric columns (net profit, percent profitable, profit factor, max drawdown, trade count). Open in Excel, Google Sheets, or pandas for:
- Pivot tables across input dimensions
- Custom scoring formulas (e.g. profit factor × win rate / drawdown)
- Plots of metric surface vs input value
- Aggregating runs across multiple timeframes or pairs
Best practices
- Start small. Sweep 2-3 inputs with coarse steps first to learn the strategy's sensitivity surface. Don't burn hours on a 5-input sweep before you know which inputs even matter.
- Always run a drawdown filter. Optimizing on net profit alone is the fastest path to a strategy that overfits on backtest and loses live.
- Validate out-of-sample. Run the sweep on the first 70-80% of your history. Take the best parameters and test them on the held-out 20-30%. If the metrics collapse, you overfit.
- Walk-forward. Roll the optimization window forward in 3-6 month chunks. If the "best" parameters change wildly each chunk, the strategy is unstable.
- Combine criteria. Use the drawdown filter first to cull risky combinations, then sort survivors by profit factor.
- Beware of trade-count cliffs. A combination with 8 trades and 100% win rate is statistically meaningless. Filter by minimum trade count in the CSV.
- Use Smart Mode for exploration, Sequential for the final tune. Sweep broadly with Smart, then take the top region of the parameter space and sweep it densely with Sequential.
When NOT to backtest
| Situation | Why it breaks backtesting |
|---|---|
Strategy uses request.security() with lookahead | TradingView's lookahead semantics produce future-information leakage on historical bars |
| Fewer than ~50 trades in the test window | Sample size too small to be statistically meaningful |
| Illiquid asset (new altcoin, low-volume pair) | Backtest assumes infinite liquidity at the bar's price — reality is brutal slippage |
| Strategy depends on order-book microstructure | TradingView only has OHLCV — microstructure-dependent strategies cannot be validated this way |
| Different exchange than the chart symbol | Spreads, fees, and tick sizes differ — backtest on the exchange you'll trade on |
From backtest to live trading
| Step | Action |
|---|---|
| 1 | Lock in the parameters you found with Strategy Finder (write them into the Pine input.* defaults). |
| 2 | Add a strategy.entry / strategy.close call with an alert_message argument carrying your JSON payload — see Strategy Alerts. |
| 3 | Build the JSON payload with the Trade Command Builder. |
| 4 | Create a TradingView alert on the strategy with Webhook URL = your TVH webhook endpoint and Message = {{strategy.order.alert_message}}. |
| 5 | Test in paper-trading mode first if your exchange supports it. |
| 6 | Monitor live performance — compare actual fills, slippage, and metrics against the backtest. |
A backtest is a hypothesis. Live trading is the experiment. Strategy Finder makes the hypothesis cheaper to generate — it doesn't validate that the hypothesis is real.