thequantscience

Manage Input variables with Pine Script v5

Education
BINANCE:ETHUSDT   Ethereum / TetherUS
Welcome to this new tutorial that helps traders and investors better understand the powerful Pine Script programming language v5.

In this tutorial, we will program together three Input variables:

  1. Color type Input: a color input is a parameter that allows specifying a custom color for the indicator or script. It can be used to set the color of lines, areas, texts, or other graphical components in the indicator.
  2. Float type Input: a float input is a parameter that allows specifying a floating-point numerical value for the indicator or script. It can be used to set parameters such as threshold levels, indicator sizes, or any other numerical value that requires decimal precision.
  3. Integer type Input:an integer input is a parameter that allows specifying an integer numerical value for the indicator or script. It can be used to set parameters such as moving average periods, length of a time interval, or any other integer numerical value.

IMPORTANT: The code used in this tutorial has been created purely for educational purposes.

Our indicator is a simple indicator that plots the close data of the underlying asset on the chart in a weighted manner. The displayed data is the sum of the close price plus 20%. The goal of the indicator is to provide a fully dynamic tool that can vary its parameters from the user interface and update automatically.

Here is the complete code for this tutorial:

//@version=5
indicator("Input Tutorial", overlay = false)
pond = input.float(defval = 0.20, title = "Float", minval = 0.10, maxval = 1, step = 0.10)
color_indicator = input.color(defval = color.red, title = "Color")
data = close + (close * pond)
linewidth_feature = input.int(defval = 1, title = "Integer", minval = 1, maxval = 10, step = 1)
plot(close, color = color_indicator, linewidth = linewidth_feature)

//@version=5
Indicates the version of the Pine Script language used in the code.

indicator("Input Tutorial", overlay = false)
Set the name of the indicator as "Input Tutorial", and overlay=false indicates that the indicator should not overlap the main chart.

pond = input.float(defval = 0.20, title = "Float", minval = 0.10, maxval = 1, step = 0.10)
Create a float input called "pond" with a default value of 0.20. The input title is "Float", and the minimum value is 0.10, the maximum value is 1, and the step is 0.10.

color_indicator = input.color(defval = color.red, title = "Color")
Create a color input called "color_indicator" with a default value of red color. The input title is "Color".

data = close + (close * pond)
Calculate a new value "data" by adding the closing price value with the closing price multiplied by the "pond" input.

linewidth_feature = input.int(defval = 1, title = "Integer", minval = 1, maxval = 10, step = 1)
Create an integer input called "linewidth_feature" with a default value of 1. The input title is "Integer", and the minimum value is 1, the maximum value is 10, and the step is 1.

plot(close, color = color_indicator, linewidth = linewidth_feature)
Plot the chart of the closing value with the color specified by the "color_indicator" input and the line width specified by the "linewidth_feature" input.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.