The input.float
function is one of its core features. This tutorial aims to shed light on the input.float
function in Pine Script, providing insights into its syntax, usage, and unique applications.
What is input.float in Pine Script?
The input.float
function is a vital element in Pine Script that creates an input field in the Inputs tab of a script’s Settings. It allows users to configure their scripts more conveniently by entering floating-point values.
Syntax of input.float
Here’s a closer look at the syntax for input.float
:
input.float(defval, title, minval, maxval, step, tooltip, inline, group, confirm) → input float input.float(defval, title, options, tooltip, inline, group, confirm) → input float
Arguments Explained
Let’s break down the arguments in the input.float
function:
defval
(const int/float): Defines the default value of the input variable that users can change in the script’s “Settings/Inputs” tab. If using theoptions
parameter, the value must be one of the options listed.title
(const string): The title of the input. If not specified, the variable name is used as the title.minval
andmaxval
(const int/float): The minimum and maximum possible values of the input variable, respectively. Both are optional.step
(const int/float): The step value for incrementing/decrementing the input variable. Optional, with a default value of 1.options
(tuple of const int/float values: [val1, val2, …]): A list of options for the dropdown menu. Can’t be used withminval
,maxval
, andstep
parameters.tooltip
(const string): The tooltip that appears when users hover over the icon.inline
(const string) andgroup
(const string): Arguments used to arrange inputs in the same line and create headers above inputs, respectively.confirm
(const bool): When set to true, it prompts users to confirm input values before adding the indicator to the chart.
Example of input.float
Let’s delve into a practical example to illustrate the usage of input.float
:
//@version=5 indicator("input.float", overlay=true) i_angle1 = input.float(0.5, "Sin Angle", minval=-3.14, maxval=3.14, step=0.02) plot(math.sin(i_angle1) > 0 ? close : open, "sin", color=color.green) i_angle2 = input.float(0, "Cos Angle", options=[-3.14, -1.57, 0, 1.57, 3.14]) plot(math.cos(i_angle2) > 0 ? close : open, "cos", color=color.red)
Here is what each line of the code does:
- The first line specifies the Pine Script version used and the name of the indicator.
- The second line defines a floating input
i_angle1
for the Sine angle with a default value of 0.5 and a range from -3.14 to 3.14 with a step of 0.02. - The third line plots the
close
value if the sine ofi_angle1
is positive; otherwise, it plots theopen
value. - Similarly, the fourth line defines a floating input
i_angle2
for the Cosine angle with a list of specific options. - The fifth line plots the
close
value if the cosine ofi_angle2
is positive; otherwise, it plots theopen
value.
Key Takeaway
The input.float
function is a powerful tool in Pine Script that helps users to enhance their scripts by adding custom float input fields. It’s flexible, customizable, and helps to make scripts more interactive and user-friendly.
Conclusion
Understanding the input.float
function is crucial for effectively using Pine Script and creating more dynamic trading indicators. This function allows you to provide intuitive configuration options to users, enhancing the overall flexibility of your scripts. As you continue to explore Pine Script, remember to make the best use of input.float
to optimize your trading strategies.