Pine Script inputs for optimization: min, max and step
Use Pine Script integer inputs to set valid bounds, then define a separate range and step for an optimization run.
On this page
- How does an integer input fit into an optimization test?
- What do the input declaration and its arguments mean?
- Is the Pine step the same as the search step?
- How do script bounds differ from the range of a run?
- Does changing the input actually change the strategy?
- What type and qualifier checks prevent confusing inputs?
- What does a manual parameter sweep involve?
- How can a reader check the result without overreading it?
- Sources
Key takeaways
- An integer input exposes a whole-number value that a strategy can use in its calculations.
- Pine input bounds limit valid values, while the optimization range selects values to test.
- The Pine input step controls the widget arrows, not the optimizer's search spacing.
- A useful test record includes the script version, input ranges and backtest conditions.
How does an integer input fit into an optimization test?
input.int() defines a whole-number input that a strategy can use as a setting, such as the length of a calculation used by its rules. An input is a value exposed for the reader to change without rewriting the calculation that uses it, making comparisons easier to organize.
For optimization, the important distinction is between making a value available and choosing which values to test under a stated set of conditions. The input declaration describes the field and its valid boundaries, while the search plan describes the candidates to compare in a particular run of the strategy.
TradingView says that changes to a script’s inputs prompt it to re-execute across the available data, using the new values (Inputs documentation, checked 2026-11-20). That makes an exposed input a useful starting point for comparing variations of the same strategy logic across the chosen test period.
A declaration alone does not establish that the input affects a simulated trade or even the calculation a reader intended to change. Trace the value through the script to find the calculation or condition that reads it, then check whether that condition can influence the strategy’s order logic.
For the broader research question of how to set a search interval, use the guide to choosing parameter ranges. This article focuses on how an integer input’s declaration relates to the separate choices made for a test, rather than prescribing a range.
What do the input declaration and its arguments mean?
An argument is a value supplied to a function when the script calls it, such as the label chosen for an input field. In an integer input declaration, named arguments make it easier to distinguish the starting value, the label, the permitted limits and the widget increment.
Consider the illustrative expression input.int(defval = BASE, title = "Length", minval = LOW, maxval = HIGH, step = INCREMENT). The uppercase names stand for integer constants declared elsewhere, so the expression is a template rather than a complete snippet to paste into a script.
The default is the starting value for the field, while the title is the label that helps a reader identify it in the script’s settings. Choose a label that describes the calculation’s role, because a record of a test is harder to interpret when several fields have vague or similar names.
TradingView defines minval and maxval as the minimum and maximum valid values for integer and float input fields (Inputs documentation). Those boundaries describe what the field accepts, not a claim that every value between them is useful to test or relevant to the research question.
The default and the limits have different jobs in the declaration, and neither substitutes for an explanation of the values selected for a run. A default inside the permitted interval gives the script a starting setting, but it does not explain why that value belongs in the next research run or why adjacent values would be meaningful.
Is the Pine step the same as the search step?
TradingView defines the input step as the increment used when clicking the field’s up and down arrows (Inputs documentation). It describes a widget action, so it should not be treated as proof of the spacing used by an optimization tool in a separate search.
A search step is the distance between candidate values chosen for a particular test, rather than a description of how the input field responds to a click. For example, a researcher might want a coarse pass across an interval and then a separate, finer pass around a region worth inspecting, without changing the script’s declaration.
That distinction matters when reviewing a run or trying to reproduce the candidate list from notes written after the test. If the script’s field uses one increment and the search plan uses another, a note that simply says “step” leaves the reader unsure which setting produced the tested candidates.
Record the Pine widget increment and the search increment under separate labels, alongside the field name and the boundaries used for the run. Also check that each intended candidate is a valid whole number within the script’s bounds, rather than assuming the optimizer’s range can override those bounds.
If a test does not reach its stated upper bound exactly, the last candidate may be below that bound rather than at it. Inspect the actual candidates or the run record before describing the upper bound as a value that was tested in the comparison.
How do script bounds differ from the range of a run?
Script bounds express the valid domain of the input field, which is the set of values allowed by its lower and upper limits. A run range is a research choice inside that domain, made for a particular question, dataset and set of other strategy settings held fixed during the test.
A broad valid domain can accommodate different uses of a script, while a narrower test interval can focus on the behavior under review in a particular study. Neither boundary tells a reader that the values near it are sensible for the calculation or representative of future conditions outside the selected data.
Before a run, write down the reason for its lower and upper search bounds in terms of the input’s role in the strategy. For a lookback length, that reason might concern the amount of history the calculation uses, rather than a result observed after testing the candidates.
Keep the starting value separate from the planned candidates as well, since the declaration’s default and the run’s search interval answer different questions. The starting value may be included in a range, but it may also sit outside a deliberately narrow test interval, so the record needs to say which case applies.
If an intended candidate falls outside the script’s permitted interval, resolve the mismatch before comparing results or treating the candidate list as complete. Changing a bound in the source is a change to the script, and the revised script should be identified in the research notes for that run.
For a practical check, read the declaration and the run setup side by side, with the research question and fixed settings close at hand. Match the field name, value type, valid limits and search spacing before treating the resulting comparisons as tests of the intended input in the strategy.
Does changing the input actually change the strategy?
Follow the value from its declaration into the expressions that use it, including any intermediate calculations that connect the field to the strategy’s conditions. A named input can be visible in settings yet have no effect on the part of the script that determines simulated orders, so visibility alone is not evidence of a meaningful test.
TradingView describes variables as named containers that store data for a script to access and use within a scope, meaning the part of the script where a name is available (Variable declarations, checked 2026-11-20). Trace the input variable through any intermediate variables before reaching a condition used by the strategy, noting where its value enters the calculation.
Look for a calculation that still contains a fixed value where the input was intended, especially if the field was added after the calculation was written. In that case, changing the exposed field may leave that calculation unchanged, even though the field itself appears to be set up for testing.
A simple diagnostic is to choose distinct valid input values and inspect the relevant calculation or plotted output under the same chart conditions. If nothing changes, inspect the path through the code and any condition that might prevent the value from being used in the calculation.
The reverse also matters: an input may alter a calculation without changing the simulated trades in the selected period, depending on the strategy’s conditions. That observation calls for inspection of the conditions and data, not an automatic conclusion that the input is broken or irrelevant to every test.
What type and qualifier checks prevent confusing inputs?
An integer is a whole-number type, which makes it suitable for a setting expressed as a count rather than a fractional quantity. Use an integer input when the strategy’s setting represents a whole count, and consider a float input, which accepts decimal values, when fractions have meaning in the calculation.
A qualifier describes when a value is available and whether it can change during execution. TradingView says that an input-qualified value is established at input time and does not change as the script runs on the dataset (Type system, checked 2026-11-20).
This is different from a value that changes from bar to bar as the script processes the chart’s data. A bar is a record for a chart interval, and a calculation using an input can still produce changing outputs as the market data for each bar changes.
The declaration arguments need attention too, especially when a script combines several inputs or uses named constants to make the code easier to read. TradingView says that most input parameters require const arguments and that arguments requiring const cannot use results from other input calls (Inputs documentation).
In the earlier template, BASE, LOW, HIGH and INCREMENT therefore need to be suitable constants, rather than values read from other inputs in the script. If a declaration fails to compile, check the required types and qualifiers before assuming that the search tool caused the error in the script.
An integer choice can also be presented as a list of options rather than as a field with a range of valid values. TradingView says an input call using minval, maxval or step cannot also use options (Inputs documentation). Treat a discrete list and a bounded field as distinct designs when planning the input, since the declaration determines which form is available.
What does a manual parameter sweep involve?
A parameter sweep is a planned series of tests that changes input values according to a recorded set of candidates chosen for a research question. Each test needs the same strategy version and comparable conditions if its result is to be interpreted as part of that series rather than a separate experiment.
Start by recording the input name, the candidate values and any settings that will remain fixed while the test series is in progress. Note the chart, test period and cost assumptions too, because a change in those conditions can make a difference look like an input effect.
For each candidate, enter the value, let the strategy recalculate and record the value alongside the resulting report before moving to another candidate. If several inputs change together, keep the full combination in each record rather than writing down only the value that attracted attention during review.
TradingView describes its strategy report as a view of the hypothetical performance of a simulated strategy (Strategies documentation, checked 2026-11-20). Read that report as evidence about the specified test, not as a record of actual execution or a forecast of later outcomes.
TradingTune is a free Chrome and Brave extension that automates TradingView strategy optimization. A search still depends on decisions about the script’s valid bounds and the candidates to examine, so record those choices with the research question.
A record of the run is useful even when the tests are automated, because it preserves the context needed to understand the comparisons later. Keep the question, the selected ranges and the fixed conditions together, so a later review can distinguish a deliberate change in the experiment from an accidental change in setup.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
How can a reader check the result without overreading it?
Start with the test question rather than the highest-ranked row in the report, and keep the original reason for the range in view. Ask whether the tested input changed the behavior the script was meant to change, and whether the comparisons were made under the same conditions.
Inspect neighboring candidates where the search actually tested them, rather than assuming untested values behave like the candidates on either side. A result isolated from nearby values can be a reason to investigate sensitivity, meaning how much the observed behavior changes when the input changes slightly; it is not proof that the setting will generalize.
Next, examine the simulated trades and the assumptions behind them, including whether the selected period offers enough context for the question being asked. A comparison based on a thin or unusual set of trades may be difficult to interpret, even when the input and search ranges were configured correctly.
Keep a period of data aside for a later check, rather than repeatedly using it to choose the candidate being assessed in the initial test. The guide to in-sample and out-of-sample testing explains the difference between data used for selection and data held back for review after that selection.
If the script, bounds or candidate spacing changes after the first review, label the next run as a revised test with its own record. Preserve the earlier plan and its observations, including any unexpected behavior, rather than merging the runs into a single unexplained conclusion about the input.
An input declaration makes a controlled comparison possible; it does not establish that the comparison is representative of conditions outside the test. The useful outcome is a clear account of what was changed, what was held fixed and what the test could not answer on its own.
Sources
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.
TradingTune for Chrome
Stop tuning your strategy's inputs by hand.
TradingTune runs systematic parameter searches on your own TradingView strategy, right inside the chart page. You keep the strategy, you read the results.
Free tier, no API keys. A free account is required to run. Not affiliated with TradingView, Inc.