TOptValue_LineStyle

What Is It?

TOptValue_LineStyle is a class used to define line style parameters for custom indicators. It allows users to configure line appearance (visibility, color, style, width) through the indicator settings panel.

Use the createTOptValue_LineStyle() method from the api object inside Init() method to create an instance.


When to Use

Use TOptValue_LineStyle when you want to let the user configure line appearance for:

  • Support/resistance levels

  • Trend lines

  • Other visual elements on charts


Syntax

public MyLineStyle!: TOptValue_LineStyle;

public Init(): void {
    // Create the parameter
    this.MyLineStyle = this.api.createTOptValue_LineStyle(isVisible, color, style, width, ignoreColor);

    // Register the parameter
    this.api.RegOption("MyLineStyle", TOptionType.LINE, this.MyLineStyle);
}

Example

export default class CustomIndicator extends IndicatorImplementation {
  public LineStyle!: TOptValue_LineStyle;

  public Init(): void {
    this.LineStyle = this.api.createTOptValue_LineStyle(true, '#FF0000', TPenStyle.SOLID, 2, false);

    this.api.RegOption("LineStyle", TOptionType.LINE, this.LineStyle);
  }

  public Calculate(index: number): void {
    if (this.LineStyle.isVisible) {
      const objName = "MyHorizontalLine";
      
      // Remove existing object if it exists
      if (this.api.DoesChartObjectExist(objName)) {
        this.api.RemoveChartObject(objName);
      }

      // Create horizontal line object
      this.api.CreateChartObject(objName, TObjectType.H_LINE, 0, undefined, this.api.Close(index));

      // Apply line style properties
      this.api.SetObjectProperty(objName, ObjProp.OBJPROP_COLOR, this.LineStyle.color);
      this.api.SetObjectProperty(objName, ObjProp.OBJPROP_STYLE, this.LineStyle.style);
      this.api.SetObjectProperty(objName, ObjProp.OBJPROP_WIDTH, this.LineStyle.width);
    }
  }
}

In this example:

  • LineStyle allows the user to configure line appearance

  • Inside Calculate(), a horizontal line is created with the configured style

  • The line is positioned at the current bar's close price


Notes

  • Don't forget to register line style parameters using this.RegOption inside the Init method.

  • Use TOptionType.LINE when registering TOptValue_LineStyle parameters.

  • Access properties with this.MyLineStyle.isVisible, this.MyLineStyle.color, this.MyLineStyle.style, this.MyLineStyle.width.

Last updated