A group of functions intended for working with graphical objects related to the current chart.
OBJECTCREATE
bool
ObjectCreate(
string name, int type, int window, datetime time1, double price1,
datetime time2=0, double price2=0, datetime time3=0,
double price3=0)
Creation of an object with the specified name, type and initial coordinates in the specified window. Count of coordinates related to the object can be from 1 to 3
depending on the object type. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. Objects of the OBJ_LABEL type ignore the coordinates. Use the function of ObjectSet() to set up the OBJPROP_XDISTANCE
and OBJPROP_YDISTANCE properties.
Notes: The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.
Coordinates must be passed in pairs: time and price. For example, the OBJ_VLINE object needs only time, but price (any value) must be passed, as well.
Parameters:
name - Object unique name.
type - Object type. It can be any of the Object type enumeration values.
window - Index of the window where the object will be added. Window index must
exceed or equal to 0 and be less than WindowsTotal().
time1 - Time part of the first point.
price1 - Price part of the first point.
time2 - Time part of the second point.
price2 - Price part of the second point.
time3 - Time part of the third point.
price3 - Price part of the third point.
Sample:
// new text object
if(!ObjectCreate("text_object", OBJ_TEXT, 0, D'2004.02.20 12:30', 1.0045))
{
Print("error: can't create text_object! code #",GetLastError()); return(0);
}
// new label object
if(!ObjectCreate("label_object", OBJ_LABEL, 0, 0, 0)) {
Print("error: can't create label_object! code #",GetLastError()); return(0);
}
ObjectSet("label_object", OBJPROP_XDISTANCE, 200); ObjectSet("label_object", OBJPROP_YDISTANCE, 100);
117
OBJECTDELETE
bool ObjectDelete( string name)
Deletes object having the specified name. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE.
To get the detailed error information, one has to call the GetLastError() function. Parameters:
name - Name of the object to be deleted.
Sample:
ObjectDelete("text_object");
OBJECTDESCRIPTION
string ObjectDescription( string name)
Return object description. For objects of OBJ_TEXT and OBJ_LABEL types, the text drawn by these objects will be returned.
To get the detailed error information, one has to call the GetLastError() function.
See also ObjectSetText() function.
Parameters:
name - Object name.
Sample:
// writing the chart objects list to the file int handle, total;
string obj_name,fname; // file name fname="objlist_"+Symbol(); handle=FileOpen(fname,FILE_CSV|FILE_WRITE); if(handle!=false) { total=ObjectsTotal(); for(int i=-;i<total;i++) { obj_name=ObjectName(i);
FileWrite(handle,"Object "+obj_name+" description= "+ObjectDescription(obj_name));
}
FileClose(handle); }
OBJECTFIND
int ObjectFind( string name)
Search for an object having the specified name. The function returns index of the
windows that contains the object to be found. If it fails, the returned value will be -1. To get the detailed error information, one has to call the GetLastError() function. The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index.
Parameters:
name - Object name to search for.
Sample:
118
OBJECTGET
double ObjectGet( string name, int index)
The function returns the value of the specified object property. To check errors, one has to call the GetLastError() function.
See also ObjectSet() function.
Parameters:
name - Object name.
index - Object property index. It can be any of the Object properties enumeration
values. Sample:
color oldColor=ObjectGet("hline12", OBJPROP_COLOR);
OBJECTGETFIBODESCRIPTION
string ObjectGetFiboDescription( string name, int index)
The function returns the level description of a Fibonacci object. The amount of
Fibonacci levels depends on the object type. The maximum amount of Fibonacci levels is 32.
To get the detailed error information, one has to call the GetLastError() function.
See also ObjectSetFiboDescription() function.
Parameters:
name - Fibonacci object name.
index - Index of the Fibonacci level (0-31).
Sample: #include <stdlib.mqh> ... string text; for(int i=0;i<32;i++) { text=ObjectGetFiboDescription(MyObjectName,i);
//---- checking whether the objects has less than 32 levels if(GetLastError()!=ERR_NO_ERROR) break;
Print(MyObjectName,"level: ",i," description: ",text); }
OBJECTGETSHIFTBYVALUE
int ObjectGetShiftByValue( string name, double value)
The function calculates and returns bar index (shift related to the current bar) for the given price. The bar index is calculated by the first and second coordinates using a linear equation. Applied to trendlines and similar objects. To get the detailed error information, one has to call the GetLastError() function.
See also ObjectGetValueByShift() function.
Parameters:
name - Object name. value - Price value.
Sample:
119
OBJECTGETVALUEBYSHIFT
double ObjectGetValueByShift( string name, int shift)
The function calculates and returns the price value for the specified bar (shift related to the current bar). The price value is calculated by the first and second coordinates using a linear equation. Applied to trendlines and similar objects. To get the detailed error information, one has to call the GetLastError() function.
See also ObjectGetShiftByValue() function.
Parameters:
name - Object name shift - Bar index.
Sample:
double price=ObjectGetValueByShift("MyTrendLine#123", 11);
OBJECTMOVE
bool ObjectMove( string name, int point, datetime time1, double price1)
The function moves an object coordinate in the chart. Objects can have from one to three coordinates depending on their types. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function. The object coordinates are numbered starting from 0.
Parameters:
name - Object name.
point - Coordinate index (0-2). time1 - New time value.
price1 - New price value.
Sample:
ObjectMove("MyTrend", 1, D'2005.02.25 12:30', 1.2345);
OBJECTNAME
string ObjectName( int index)
The function returns the object name by its index in the objects list. To get the detailed error information, one has to call the GetLastError() function.
Parameters:
index - Object index in the objects list. Object index must exceed or equal to 0 and
be less than ObjectsTotal(). Sample: int obj_total=ObjectsTotal(); string name; for(int i=0;i<obj_total;i++) { name=ObjectName(i);
Print(i,"Object name is " + name); }
120
OBJECTSDELETEALL
int ObjectsDeleteAll( int window=EMPTY, int type=EMPTY)
Removes all objects of the specified type and in the specified sub-window of the chart. The function returns the count of removed objects. To get the detailed error information, one has to call the GetLastError() function.
Notes: The chart sub-windows (if there are sub-windows with indicators in the chart) are numbered starting from 1. The chart main window always exists and has the 0 index. If the window index is missing or it has the value of -1, the objects will be removed from the entire chart.
If the type value equals to -1 or this parameter is missing, all objects will be removed from the specified sub-window.
Parameters:
window - Optional parameter. Index of the window in which the objects will be
deleted. Must exceed or equal to -1 (EMPTY, the default value) and be less than WindowsTotal().
type - Optional parameter. An object type to be deleted. It can be any of
the Object type enumeration values or EMPTY constant to delete all objects with any types.
Sample:
ObjectsDeleteAll(2, OBJ_HLINE); // all horizontal lines are removed from the 2nd sub-window.
ObjectsDeleteAll(2); // all objects are removed from the 2nd sub-window.
ObjectsDeleteAll(); // all objects are removed from the chart.
OBJECTSET
bool ObjectSet( string name, int index, double value)
Changes the value of the specified object property. If the function succeeds, the returned value will be TRUE. Otherwise, it will be FALSE. To get the detailed error information, one has to call the GetLastError() function.
See also ObjectGet() function.
Parameters:
name - Object name.
index - Object value index. It can be any of Object properties enumeration values.
value - New value of the given property.
Sample:
// moving the first coord to the last bar time ObjectSet("MyTrend", OBJPROP_TIME1, Time[0]); // setting the second fibo level
ObjectSet("MyFibo", OBJPROP_FIRSTLEVEL+1, 1.234);
// setting object visibility. object will be shown only on 15 minute and 1 hour charts
ObjectSet("MyObject", OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15 | OBJ_PERIOD_H1);
121
OBJECTSETFIBODESCRIPTION
bool ObjectSetFiboDescription( string name, int index, string text)
The function assigns a new description to a level of a Fibonacci object. The amount of Fibonacci levels depends on the object type. The maximum amount of Fibonacci levels is 32.
To get the detailed error information, one has to call the GetLastError() function. Parameters:
name - Object name.
index - Index of the Fibonacci level (0-31). text - New description of the level.
Sample:
ObjectSetFiboDescription("MyFiboObject",2,"Second line");
OBJECTSETTEXT
bool
ObjectSetText(
string name, string text, int font_size, string font=NULL,
color text_color=CLR_NONE)
Changes the object description. For objects of OBJ_TEXT and OBJ_LABEL, this description is shown as a text line in the chart. If the function succeeds, the returned value will be TRUE. Otherwise, it is FALSE. To get the detailed error information, one has to call the GetLastError() function.
Parameters of font_size, font_name and text_color are used for objects of OBJ_TEXT and OBJ_LABEL only. For objects of other types, these parameters are ignored.
See also ObjectDescription() function.
Parameters:
name - Object name.
text - A text describing the object.
font_size - Font size in points.
font - Font name.
text_color - Text color.
Sample:
ObjectSetText("text_object", "Hello world!", 10, "Times New Roman", Green);
OBJECTSTOTAL
int ObjectsTotal( int type=EMPTY)
Returns total amount of objects of the specified type in the chart. Parameters:
type - Optional parameter. An object type to be counted. It can be any of the Object
type enumeration values or EMPTY constant to count all objects with any types. Sample: int obj_total=ObjectsTotal(); string name; for(int i=0;i<obj_total;i++) {
122 name=ObjectName(i);
Print(i,"Object name for object #",i," is " + name); }
OBJECTTYPE
int ObjectType( string name)
The function returns the object type value. To get the detailed error information, one has to call the GetLastError() function.
Parameters:
name - Object name.
Sample:
123