Pine Script, used extensively in financial trading scripts, offers a range of input functions that allow users to customize script behavior. These functions accept various parameters, each playing a specific role. Let’s dive into these parameters, understanding their purposes and how they influence the script’s functionality.
Parameters Common to All Input Functions
1. defval
- Description: Serves as the default value in the input widget.
- Argument Type: Corresponds to the type of input value the function is used for.
2. title
- Description: The label of the input field.
- Argument Type: Constant string (
const string
).
3. tooltip
- Description: Displays a tooltip text on hovering over the input field’s question mark icon.
- Argument Type: Constant string (
const string
). - Special Note: If used with
inline
, the tooltip appears next to the rightmost field.
4. inline
- Description: Aligns multiple input widgets on the same line.
- Argument Type: Constant string (
const string
). - Functionality: Input fields with the same
inline
argument align together.
5. group
- Description: Groups multiple inputs under a shared section.
- Argument Type: Constant string (
const string
). - Functionality: The argument string becomes the section heading.
Parameters Specific to Other Input Functions
6. options
- Usage: Creates a dropdown menu.
- Argument Type: A comma-separated list within square brackets (e.g.,
["ON", "OFF"]
). - Special Note: Not compatible with
minval
,maxval
, orstep
when used.
7. minval
- Description: Sets the minimum valid value.
- Argument Type: Constant integer/float (
const int/float
).
8. maxval
- Description: Sets the maximum valid value.
- Argument Type: Constant integer/float (
const int/float
).
9. step
- Description: Determines the increment for the input field’s value.
- Argument Type: Usually a small number.
10. confirm
- Description: Triggers the “Settings/Inputs” tab popup when script is added to a chart.
- Argument Type: Constant boolean (
const bool
).
Key Points to Remember
- Constant Arguments: Parameters expect constant (
const
) arguments, known at compile time and immutable during script execution. - No Nested Input Functions: You cannot use the result of one
input.*()
function as an argument in another due to the “input” qualifier.
Application and Syntax
- Versatility: These parameters allow for dynamic, user-interactive scripts.
- Syntax: Proper syntax and understanding of each parameter’s role are crucial for effective script development.
In conclusion, mastering these parameters enhances the functionality and user interaction of Pine Script-based trading scripts. By appropriately leveraging these parameters, you can create more intuitive and flexible trading indicators and strategies.