myeatrade

MQL4 Reference

MQL4 Object functions (1)

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);

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:

if(ObjectFind("line_object2")!=win_idx) return(0);

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);

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 property index. It can be any of the 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);

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);
    }

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");
This article url: http://www.myeatrade.com/449/

Please login to post comment, if you haven't account you can register free