Inputs

In HaasScript, users can create custom UI inputs to their scripts. These inputs allow for greater flexibility and customization within your trading strategy. Here are a few commands you can use to create inputs in your script:

Input()

Input(string label, [dynamic defaultvalue, string tooltip, string group])

This command creates an input which can be used for boolean, number, or text values. The label parameter is the text that will appear next to the input field. The defaultvalue parameter is the initial value that will be displayed in the input field. The tooltip parameter is an optional text that will appear when you hover over the input field. The group parameter is an optional string that can be used to group inputs together.

InputButton()

InputButton(string label, function callback, [string tooltip, string group])

This command creates a button with an action-callback. When clicked, the function is run immediately. The label parameter is the text that will appear on the button. The callback parameter is the function that will be executed when the button is clicked.

InputConstant()

InputConstant(string label, enum defaultValue, [string tooltip, string group])

This command creates a dropdown menu based on the default value, containing all items in that enum group. For example, InputConstant(‘MA Type’, SmaType) grabs all MA types and creates a dropdown menu containing all built-in MA types. The label parameter is the text that will appear next to the dropdown menu. The defaultValue parameter is the initial value that will be selected in the dropdown menu.

InputInterval()

InputInterval(string label, [number defaultValue, string tooltip, string group])

This command creates a dropdown menu containing supported intervals. The label parameter is the text that will appear next to the dropdown menu. The defaultValue parameter is the initial value that will be selected in the dropdown menu.

InputMaTypes()

InputMaTypes(string label, enum defaultValue, [string tooltip, string group])

This command creates a dropdown menu containing supported MA types used with the MA() command. The label parameter is the text that will appear next to the dropdown menu. The defaultValue parameter is the initial value that will be selected in the dropdown menu.

InputOptions()

InputOptions(string label, string defaultValue, dynamic options, [string tooltip, string group])

This command creates a dropdown menu that can be used with custom number or text based options array. The label parameter is the text that will appear next to the dropdown menu. The defaultValue parameter is the initial value that will be selected in the dropdown menu. The options parameter is an array of strings or numbers that will be used as the options in the dropdown menu.

Here is an example of creating an input dropdown menu with custom options:

options = {'Option 1', 'Option 2', 'Option 3'}
myInput = InputOptions('My Input Label', options[1], options)

In this example, a dropdown menu input named myInput is created with the label “My Input Label” and default value options[1] which points to “Option 1”. The options array contains three string options that will appear in the dropdown menu: “Option 1”, “Option 2”, and “Option 3”.

Conclusion

Once an input has been created, its value can be accessed in the script by simply calling the input variable. For example, to access the value of the input myInput created in the example above, you can simply use:

Log(myInput)

This will output the current value of the myInput input.

Inputs can be extremely useful for creating dynamic and user-friendly scripts. By allowing users to customize variables and settings through the user interface, scripts can become more accessible to a wider range of users. Additionally

Back to: HaasScript Fundamentals > Using Data