Skip to content

ObjectCreate

ObjectCreate

The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow. During creation up to 30 coordinates can be specified.

bool  ObjectCreate(
   long         chart_id,      // chart identifier
   string       name,          // object name
   ENUM_OBJECT  type,          // object type
   sub_window   nwin,          // window index
   datetime     time1,         // time of the first anchor point
   double       price1,        // price of the first anchor point
   ...
   datetime     timeN=0,       // time of the N-th anchor point
   double       priceN=0,      // price of the N-th anchor point
   ...
   datetime     time30=0,      // time of the 30th anchor point
   double       price30=0      // price of the 30th anchor point
   );

Parameters

chart_id

[in] Chart identifier. 0 means the current chart.

name

[in] Name of the object. The name must be unique within a chart, including its subwindows.

type

[in] Object type. The value can be one of the values of the ENUM_OBJECT enumeration.

sub_window

[in] Number of the chart subwindow. 0 means the main chart window. The specified subwindow must exist, otherwise the function returns false.

time1

[in] The time coordinate of the first anchor.

price1

[in] The price coordinate of the first anchor point.

timeN=0

[in] The time coordinate of the N-th anchor point.

priceN=0

[in] The price coordinate of the N-th anchor point.

time30=0

[in] The time coordinate of the thirtieth anchor point.

price30=0

[in] The price coordinate of the thirtieth anchor point.

Return Value

The function returns true if the command has been successfully added to the queue of the specified chart, or false otherwise. If an object has already been created, an attempt is made to change its coordinates.

Note

An asynchronous call is always used for ObjectCreate(), that is why the function only returns the results of adding the command to a chart queue. In this case, true only means that the command has been successfully enqueued, but the result of its execution is unknown.

To check the command execution result, you can use the ObjectFind() function or any other function that requests object properties, such as ObjectGetXXX. However, you should keep in mind that such functions are added to the end of the queue of that chart, and they wait for the execution result (due to the synchronous call), and can therefore be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

An object name should not exceed 63 characters.

The numbering of the chart subwindows (if there are subwindows with indicators in the chart) starts with 1. The main chart window of the chart is and always has index 0.

The large number of anchor points (up to 30) is implemented for future use. At the same time, the limit of 30 possible anchor points for graphical objects is determined by the limit on the number of parameters (not more than 64) that can be used when calling a function.

When an object is renamed, two events are formed simultaneously. These events can be handled in an Expert Advisor or indicator by the OnChartEvent() function:

  • an event of deletion of an object with the old name;
  • an event of creation of an object with a new name.

There is a certain number of anchor points that must be specified when creating each object type:

IDDescriptionAnchor Points
OBJ_VLINEVertical LineOne anchor point. Actually only the time coordinate is used.
OBJ_HLINEHorizontal LineOne anchor point. Actually only the price coordinate is used.
OBJ_TRENDTrend LineTwo anchor points.
OBJ_TRENDBYANGLETrend Line By AngleTwo anchor points.
OBJ_CYCLESCycle LinesTwo anchor points.
OBJ_ARROWED_LINEArrowed LineTwo anchor points.
OBJ_CHANNELEquidistant ChannelThree anchor points.
OBJ_STDDEVCHANNELStandard Deviation ChannelTwo anchor points.
OBJ_REGRESSIONLinear Regression ChannelTwo anchor points.
OBJ_PITCHFORKAndrews’ PitchforkThree anchor points.
OBJ_GANNLINEGann LineTwo anchor points.
OBJ_GANNFANGann FanTwo anchor points.
OBJ_GANNGRIDGann GridTwo anchor points.
OBJ_FIBOFibonacci RetracementTwo anchor points.
OBJ_FIBOTIMESFibonacci Time ZonesTwo anchor points.
OBJ_FIBOFANFibonacci FanTwo anchor points.
OBJ_FIBOARCFibonacci ArcsTwo anchor points.
OBJ_FIBOCHANNELFibonacci ChannelThree anchor points.
OBJ_EXPANSIONFibonacci ExpansionThree anchor points.
OBJ_ELLIOTWAVE5Elliott Motive WaveFive anchor points.
OBJ_ELLIOTWAVE3Elliott Correction WaveThree anchor points.
OBJ_RECTANGLERectangleTwo anchor points.
OBJ_TRIANGLETriangleThree anchor points.
OBJ_ELLIPSEEllipseThree anchor points.
OBJ_ARROW_THUMB_UPThumbs UpOne anchor point.
OBJ_ARROW_THUMB_DOWNThumbs DownOne anchor point.
OBJ_ARROW_UPArrow UpOne anchor point.
OBJ_ARROW_DOWNArrow DownOne anchor point.
OBJ_ARROW_STOPStop SignOne anchor point.
OBJ_ARROW_CHECKCheck SignOne anchor point.
OBJ_ARROW_LEFT_PRICELeft Price LabelOne anchor point.
OBJ_ARROW_RIGHT_PRICERight Price LabelOne anchor point.
OBJ_ARROW_BUYBuy SignOne anchor point.
OBJ_ARROW_SELLSell SignOne anchor point.
OBJ_ARROWArrowOne anchor point.
OBJ_TEXTTextOne anchor point.
OBJ_LABELLabelPosition is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
OBJ_BUTTONButtonPosition is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
OBJ_CHARTChartPosition is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
OBJ_BITMAPBitmapOne anchor point.
OBJ_BITMAP_LABELBitmap LabelPosition is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
OBJ_EDITEditPosition is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
OBJ_EVENTThe “Event” object corresponding to an event in the economic calendarOne anchor point. Actually only the time coordinate is used.
OBJ_RECTANGLE_LABELThe “Rectangle label” object for creating and designing the custom graphical interface.Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.
Last updated on