Download MetaTrader 5

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

Returns true or false depending on whether the object is created or not. To read more about the error call GetLastError(). If the object has been created already, the function tries to change its coordinates.

Note

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:

ID

Description

Anchor Points

OBJ_VLINE

Vertical Line

One anchor point. Actually only the time coordinate is used.

OBJ_HLINE

Horizontal Line

One anchor point. Actually only the price coordinate is used.

OBJ_TREND

Trend Line

Two anchor points.

OBJ_TRENDBYANGLE

Trend Line By Angle

Two anchor points.

OBJ_CYCLES

Cycle Lines

Two anchor points.

OBJ_ARROWED_LINE

Arrowed Line

Two anchor points.

OBJ_CHANNEL

Equidistant Channel

Three anchor points.

OBJ_STDDEVCHANNEL

Standard Deviation Channel

Two anchor points.

OBJ_REGRESSION

Linear Regression Channel

Two anchor points.

OBJ_PITCHFORK

Andrews’ Pitchfork

Three anchor points.

OBJ_GANNLINE

Gann Line

Two anchor points.

OBJ_GANNFAN

Gann Fan

Two anchor points.

OBJ_GANNGRID

Gann Grid

Two anchor points.

OBJ_FIBO

Fibonacci Retracement

Two anchor points.

OBJ_FIBOTIMES

Fibonacci Time Zones

Two anchor points.

OBJ_FIBOFAN

Fibonacci Fan

Two anchor points.

OBJ_FIBOARC

Fibonacci Arcs

Two anchor points.

OBJ_FIBOCHANNEL

Fibonacci Channel

Three anchor points.

OBJ_EXPANSION

Fibonacci Expansion

Three anchor points.

OBJ_ELLIOTWAVE5

Elliott Motive Wave

Five anchor points.

OBJ_ELLIOTWAVE3

Elliott Correction Wave

Three anchor points.

OBJ_RECTANGLE

Rectangle

Two anchor points.

OBJ_TRIANGLE

Triangle

Three anchor points.

OBJ_ELLIPSE

Ellipse

Three anchor points.

OBJ_ARROW_THUMB_UP

Thumbs Up

One anchor point.

OBJ_ARROW_THUMB_DOWN

Thumbs Down

One anchor point.

OBJ_ARROW_UP

Arrow Up

One anchor point.

OBJ_ARROW_DOWN

Arrow Down

One anchor point.

OBJ_ARROW_STOP

Stop Sign

One anchor point.

OBJ_ARROW_CHECK

Check Sign

One anchor point.

OBJ_ARROW_LEFT_PRICE

Left Price Label

One anchor point.

OBJ_ARROW_RIGHT_PRICE

Right Price Label

One anchor point.

OBJ_ARROW_BUY

Buy Sign

One anchor point.

OBJ_ARROW_SELL

Sell Sign

One anchor point.

OBJ_ARROW

Arrow

One anchor point.

OBJ_TEXT

Text

One anchor point.

OBJ_LABEL

Label

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

OBJ_BUTTON

Button

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

OBJ_CHART

Chart

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

OBJ_BITMAP

Bitmap

One anchor point.

OBJ_BITMAP_LABEL

Bitmap Label

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

OBJ_EDIT

Edit

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.

OBJ_EVENT

The "Event" object corresponding to an event in the economic calendar

One anchor point. Actually only the time coordinate is used.

OBJ_RECTANGLE_LABEL

The "Rectangle label" object for creating and designing the custom graphical interface.

Position is set using the OBJPROP_XDISTANCE and OBJPROP_YDISTANCE properties.


Updated: 2015.12.03