# 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

```ts
// 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

```ts
export default class MovingAverage extends IndicatorImplementation {
  public Period!: TOptValue_number;
  public Shift!: TOptValue_number;
  public MAtype!: TOptValue_number;
  public ApplyToPrice!: TOptValue_number;
  public VShift!: TOptValue_number;

  public Init(): void {
    // Create the parameter
    this.Period = this.api.createTOptValue_number(8);
    this.Shift = this.api.createTOptValue_number(0);
    this.MAtype = this.api.createTOptValue_number(E_MAType.SMA);
    this.ApplyToPrice = this.api.createTOptValue_number(TPriceType.CLOSE);
    this.VShift = this.api.createTOptValue_number(0);

    // Register the parameter
    this.api.RegOption("Period", TOptionType.INTEGER, this.Period);
    this.api.RegOption("Shift", TOptionType.INTEGER, this.Shift);
    this.api.RegOption("MAtype", TOptionType.INTEGER, this.MAtype);
    this.api.RegOption("ApplyToPrice", TOptionType.INTEGER, this.ApplyToPrice);
    this.api.RegOption("VShift", TOptionType.INTEGER, this.VShift);
  }
}
```

In this example:

* `Period` controls how many bars are used in the moving average calculation.
* `Shift` can offset the indicator horizontally.
* `MAtype` selects the type of moving average (e.g., SMA, EMA).
* `ApplyToPrice` defines which price (close, open, high, low) the MA should use.
* `VShift` applies a vertical offset to the line.

***

### Notes

* After creating a parameter, don’t forget to register it using [`this.RegOption`](https://fto-2.gitbook.io/fto-indicators-docs/external_parameters_definition/reg-option) in the [`Init`](https://fto-2.gitbook.io/fto-indicators-docs/indicators/indicator-structure/init) method.
* You can access the value using `this.MyParameter.value`.
