Inputs

How to Use minval, maxval, and step in Pine Script Inputs (v6)

How to Use minval, maxval, and step in Pine Script Inputs (v6)

set min/max/step values for inputs in pine script

When creating indicators or strategies in Pine Script v6, controlling user inputs is just as important as writing correct calculations.
The minval, maxval, and step parameters allow you to validate inputs, prevent errors, and improve the user experience.

This tutorial shows how and why to use them.

Why Use minval, maxval, and step?

Without constraints, users can:

  • Enter negative lengths
  • Use unrealistic values
  • Break calculations or visuals

With constraints, you:

  • Prevent invalid inputs
  • Make scripts easier to use
  • Reduce support questions (“Why is my indicator broken?”)

In short: better inputs = better scripts.

Basic Example: Limiting an Integer Input

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © QuantNomad

//@version=6
indicator("Input minval / maxval example")

length = input.int(
     defval = 14,
     title  = "SMA Length",
     minval = 1,
     maxval = 200
)

plot(ta.sma(close, length))

What This Does

  • minval = 1 → no zero or negative lengths
  • maxval = 200 → prevents unrealistic smoothing
  • The user can only select values in that range

Using step to Control Input Precision

The step parameter defines how much the value changes when clicking the arrows or dragging the slider.

mult = input.float(
     defval = 1.5,
     title  = "ATR Multiplier",
     minval = 0.1,
     maxval = 10,
     step   = 0.1
)

Why Step Matters

  • Cleaner values (no weird decimals like 1.473829)
  • Better UX for sliders
  • More consistent parameter testing

Common Use Cases

ParameterTypical Use
minvalLengths, periods, multipliers
maxvalSafety limits, performance caps
stepPercentages, multipliers, tuning

Examples:

  • RSI length: minval = 2
  • ATR multiplier: step = 0.1
  • Risk %: maxval = 5

Best Practices

✔ Always use minval for lengths
✔ Use step for float inputs
✔ Keep ranges realistic
✔ Think like a user, not a coder

Your future self (and your users) will thank you.

Final Thoughts

Input constraints are a small detail with a big impact.
They make your Pine Script indicators:

  • Safer
  • More professional
  • Easier to use

If you publish scripts or sell indicators, this is non-optional.


Follow me on TradingView and YouTube.

This image has an empty alt attribute; its file name is wide.png
This image has an empty alt attribute; its file name is wide.png

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Pine Script Programming Courses
Pine Script Programming Courses
Learn to build your own TradingView Indicators and Strategies
Sidebar Signup Form
If you want to be the first in this business, subscribe to the latest news