Zeal TerminalOpen the chart
Zeal Terminal / Guides

How to find the best Pine Script parameters with the Optimizer

Updated 26 November 2026

Most strategies have inputs: a moving-average length, a stop distance, an RSI threshold. The Optimizer tries many combinations of them on the chart's data and ranks the results. This guide runs it on a strategy that is already on the chart, reads the results table and heatmap, and writes a chosen setting back into the script.

Try it in Zeal Terminal

Steps

  1. Optimize. On the strategy's row in the chart legend, click Optimize. The Optimizer window opens on this strategy.
  2. Optimizer inputs. Each input of the strategy is listed here. Tick the ones to search and set the range for each. Fewer inputs give a clearer answer.
  3. Objective. Pick the objective: the number the search tries to push up, such as net profit or profit factor.
  4. Maximum runs. Set the maximum number of runs. When the ranges hold more combinations than this, the search samples them.
  5. Vary this input. Tick Vary on an input you want to search. The Run button stays off until at least one input is ticked.
  6. Run optimization. Click Run. A progress bar shows each combination being tested.
  7. Results table. The results table lists every combination, best first.
  8. Heatmap. With two inputs searched, the heatmap shows the result as a colour grid. Look for a broad bright area rather than a single bright cell.
  9. A heatmap cell. Click a cell to pick that combination. The picked values get an Apply button.
  10. Apply to script. Click Apply to write the picked values into the script and run it on the chart.

How to read the heatmap

Each cell is one pair of input values and its colour is the objective. A plateau, a wide region of similar good colours, means the strategy does not depend on exact values. A lone bright cell surrounded by poor ones is almost always noise, and a setting from it is unlikely to repeat.

Avoiding over-fitting

  • Prefer the middle of a plateau to the single best row.
  • Check the trade count. The minimum-trades setting keeps results with only a few trades out of the ranking.
  • Test on another period. Apply the chosen values, then scroll the chart to older data and run the strategy tester again. If the result collapses, the optimum was fitted to the first period.
  • Search few inputs. Every extra input multiplies the combinations and the chance of a lucky result.

Frequently asked questions

Does it run on a server? No. The search runs on your machine, in parallel browser workers, so it is as fast as your computer and nothing is uploaded.

Why is Optimize missing on my script? It shows only for strategies. An indicator() script has no trades to rank.

Can I stop a run? Yes. Stop ends the search and keeps the results found so far.

Related guides

  • How to backtest a Pine Script strategy and read the results
  • How to apply a Pine Script to the chart

This guide is replayed by an automated test on every release, so the steps here match the app as it is today.

PricingContactRefundsPrivacyTermsCookiesDisclaimer

© 2026 Zeal Terminal. An independent project, not affiliated with TradingView, Inc.