Home » Input Functions » input.int function in Pine Script

input.int function in Pine Script

Photo of author
Published on

In this blog, we will delve into the input.int function in Pine Script, a useful feature that enables you to provide configuration options to users of your script.

What is input.int?

The input.int function adds an input field for an integer in your script’s settings. This is specifically found under the Inputs tab. This function allows users of your script to have configurable options for better interaction and functionality.

Syntax of input.int

input.int can take a range of parameters. Here are two commonly used syntax structures:

  1. input.int(defval, title, minval, maxval, step, tooltip, inline, group, confirm) → input int
  2. input.int(defval, title, options, tooltip, inline, group, confirm) → input int

Let’s discuss each of these parameters in detail.

Key Parameters

  • defval (const int): Determines the default value of the input variable. This is the value users see and can change from the script’s “Settings/Inputs” tab.
  • title (const string): This represents the title of the input field. If unspecified, the variable name is used as the title.
  • minval, maxval (const int): These represent the minimum and maximum possible values of the input variable respectively.
  • step (const int): Defines the increment/decrement value of the input. The default value is 1.
  • options (tuple of const int values): This provides a dropdown menu of options for users to select from.
  • tooltip (const string): Displays a message to the user when they hover over the tooltip icon.
  • inline, group (const string): These parameters allow you to combine input calls in one line and create a header above inputs respectively.
  • confirm (const bool): If set to true, the user will be asked to confirm the input value before adding the indicator to the chart.

Practical Example

Let’s look at an example that utilizes the input.int function:

indicator("input.int", overlay=true)
i_len1 = input.int(10, "Length 1", minval=5, maxval=21, step=1)
plot(ta.sma(close, i_len1))

i_len2 = input.int(10, "Length 2", options=[5, 10, 21])
plot(ta.sma(close, i_len2))
input.int function

Here, the input.int function is used to create two configurable settings, Length 1 and Length 2. Both settings influence the length of the simple moving average (SMA) lines plotted on the chart.

The first instance of input.int sets a default value of 10, allows values between 5 and 21 with a step of 1.

The second instance of input.int uses an options parameter instead, providing the user with three values to choose from: 5, 10, and 21.

The returned values of these input.int functions are then used in ta.sma(close, i_len1) and ta.sma(close, i_len2) respectively to plot SMAs of the closing prices with the user-selected lengths.

Key Takeaways

Understanding and using the input.int function effectively allows you to create highly customizable scripts in Pine Script. This function gives users the ability to modify script settings to suit their preferences or needs. It offers a wide range of parameters to fine-tune how users interact with the script’s inputs. By knowing how to set and adjust these parameters, you can provide a more user-friendly and interactive experience.


By now, you should have a solid grasp of the input.int function in Pine Script, its syntax, usage, and how to incorporate it into your scripts to provide customizable options. Remember to always assign the result of input.int function to a variable as seen in the provided examples. Happy coding!

Leave a Comment