SetObjectProperty

Sets a property value for a chart object.

Syntax

SetObjectProperty(
  name: string,
  index: number,
  value: any,
  isStatic: boolean = false
  ): boolean

Parameters

Parameter
Type
Description

name

string

The name of the object

index

number

The property identifier

value

any

The value to set

isStatic

boolean

Optional. Whether the object is static (default: false)

Return Value

Returns boolean - true if the property was set successfully, false otherwise.

Description

The SetObjectProperty method sets a property value for a specified chart object. It can handle both numeric and string properties, and automatically converts time values from FTODate to the internal format.

Example

// Set object coordinates
const success1 = this.api.SetObjectProperty(
  "MyTrendLine",
  ObjProp.OBJPROP_TIME1,
  this.api.createFTODate(1641024000000)
);
const success2 = this.api.SetObjectProperty(
  "MyTrendLine",
  ObjProp.OBJPROP_PRICE1,
  1.2
);

// Set visual properties
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_COLOR, 0xff0000); // Red color
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_STYLE, 1); // Solid line
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_WIDTH, 2); // Line width

// Set text properties
this.api.SetObjectProperty("MyLabel", ObjProp.OBJPROP_TEXT, "New Label Text");
this.api.SetObjectProperty("MyLabel", ObjProp.OBJPROP_FONTSIZE, 12);

// Set object state
this.api.SetObjectProperty("MyTrendLine", ObjProp.OBJPROP_HIDDEN, true);

Last updated