TOptValue_number
What Is It?
TOptValue_number is a class used to define numeric parameters for custom indicators.
These parameters appear in the indicator settings panel and allow the user to input or adjust numbers such as periods, shifts, price types, and more.
You must use the createTOptValue_number() method of the api object inside Init() method to create an instance.
When to Use
Use TOptValue_number when you need a configurable parameter of type number, such as:
Period length for moving averages
Shift values
Enum values (e.g., MA type, price type)
Any numeric input from the user
Syntax
// Declare the parameter in the class fields
public MyParameter!: TOptValue_number;
public Init(): void {
// Create the parameter
this.MyParameter = this.api.createTOptValue_number(defaultValue);
// Register the parameter
this.api.RegOption("MyParameter", TOptionType.INTEGER, this.MyParameter);
}Example
In this example:
Periodcontrols how many bars are used in the moving average calculation.Shiftcan offset the indicator horizontally.MAtypeselects the type of moving average (e.g., SMA, EMA).ApplyToPricedefines which price (close, open, high, low) the MA should use.VShiftapplies a vertical offset to the line.
Notes
After creating a parameter, don’t forget to register it using
this.RegOptionin theInitmethod.You can access the value using
this.MyParameter.value.
Last updated