FindObject
Syntax
FindObject(chartId: number | null = null, objectName: string): numberParameters
Return Value
Description
Example
// Find object on current chart
const index = this.api.FindObject(null, "MyTrendLine");
if (index !== -1) {
console.log(`Object found at index: ${index}`);
} else {
console.log("Object not found");
}
// Find object on specific chart
const chartId = this.api.GetCurrentChartId();
const objectIndex = this.api.FindObject(chartId, "MyLabel");
if (objectIndex >= 0) {
// Use the index to get object properties
const objectType = this.api.GetObjectType(
this.api.GetObjectName(objectIndex)
);
console.log(`Object type: ${objectType}`);
}
// Find and modify object
const targetName = "SignalLine";
const foundIndex = this.api.FindObject(null, targetName);
if (foundIndex >= 0) {
// Object exists, modify it
const name = this.api.GetObjectName(foundIndex);
this.api.SetObjectProperty(name, ObjProp.OBJPROP_COLOR, 0xff0000);
} else {
// Object doesn't exist, create it
this.api.СreateChartObject(
targetName,
TObjectType.TREND_LINE,
0,
this.api.createFTODate(Date.now()),
1.2345
);
}Last updated