CreateChartObject

Creates a new chart object with specified parameters.

Syntax

СreateChartObject(
    name: string,
    objType: TObjectType,
    window: number,
    ftoDate1: FTODate,
    price1: number,
    ftoDate2?: FTODate,
    price2?: number,
    ftoDate3?: FTODate,
    price3?: number,
    isStatic?: boolean
): boolean

Parameters

Parameter
Type
Description

name

string

Unique identifier for the object

objType

Type of object to create (e.g., trend line, rectangle)

window

number

Chart window number where the object will be placed

ftoDate1

First time coordinate

price1

number

First price coordinate

ftoDate2

Optional. Second time coordinate (required for some objects)

price2

number

Optional. Second price coordinate (required for some objects)

ftoDate3

Optional. Third time coordinate (required for triangles)

price3

number

Optional. Third price coordinate (required for triangles)

isStatic

boolean

Optional. Whether the object is static (persists across timeframes)

Return Value

Returns boolean - true if the object was created successfully, false otherwise.

Description

The СreateChartObject method creates a new chart object with the specified parameters. Different object types require different sets of coordinates

Examples

Text Object

// Create text object
this.api.CreateChartObject('MyLabel', TObjectType.TEXT, 0, this.api.Time(0), this.api.Close(0))

// Set text content and styling
this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_TEXT, 'Support Level')
this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_FONTNAME, 'Arial')
this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_FONTSIZE, 12)
this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_COLOR, '#0000FF')
this.api.SetObjectProperty('MyLabel', ObjProp.OBJPROP_ANCHOR_POINT, AnchorPoint.CENTER)

Rectangle Object

// Create rectangle
this.api.CreateChartObject(
    'MyRectangle',
    TObjectType.RECTANGLE,
    0,
    this.api.Time(10),
    this.api.Close(10),
    this.api.Time(0),
    this.api.Close(0)
)

// Set rectangle styling
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_COLOR, '#00FF00')
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FILLCOLOR, '#00FF0020')
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FILLINSIDE, true)
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_WIDTH, 1)
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_BACK, true)
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_MIDDLE_LINE, true)

// Set text content and styling for rectangle
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_TEXT, 'Text')
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FONTNAME, 'Arial')
this.api.SetObjectProperty('MyRectangle', ObjProp.OBJPROP_FONTSIZE, 12)

Fixed Object (Screen Coordinates)

// Create a text object with screen coordinates
this.api.CreateChartObject('FixedLabel', TObjectType.TEXT, 0, 0, 0)

// Enable screen coordinates mode
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_SCREENCOORDS, true)

// Set fixed position relative to chart corner (top-left)
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_XDISTANCE, 50) // 50 pixels from left
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_YDISTANCE, 30) // 30 pixels from top

// Set fixed size
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_XSIZE, 200) // 200 pixels wide
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_YSIZE, 40) // 40 pixels tall

// Configure text properties
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_TEXT, 'Fixed Position Label')
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_FONTNAME, 'Arial')
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_FONTSIZE, 14)
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_COLOR, '#333333')
this.api.SetObjectProperty('FixedLabel', ObjProp.OBJPROP_ANCHOR_POINT, AnchorPoint.LEFT_TOP)

Last updated