RemoveChartObject

Removes a chart object with the specified name.

Syntax

RemoveChartObject(uniqueObjectName: string, isStatic: boolean = false): void

Parameters

  • uniqueObjectName: string - The unique name of the object to remove

  • isStatic: boolean - Optional. Whether the object is static (default: false)

Description

The RemoveChartObject method removes a specified chart object from the chart. The object is identified by its unique name. If the object is static (persists across all timeframes), set the isStatic parameter to true.

Example

// Remove a regular chart object
this.api.RemoveChartObject("MyTrendLine");

// Remove a static chart object
this.api.RemoveChartObject("MyStaticLabel", true);

// Remove object after checking existence
if (this.api.DoesChartObjectExist("MyObject")) {
  this.api.RemoveChartObject("MyObject");
  console.log("Object removed successfully");
}

// Remove multiple related objects
const objectPrefix = "Signal_";
for (let i = 0; i < this.api.GetObjectCount(); i++) {
  const name = this.api.GetObjectName(i);
  if (name.startsWith(objectPrefix)) {
    this.api.RemoveChartObject(name);
  }
}

Last updated