myeatrade

MQL4 Reference

MQL4 Object functions (2)

A group of functions intended for working with graphical objects related to the current chart.

 

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:

  int shift=ObjectGetShiftByValue("MyTrendLine#123", 1.34);

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

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.

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++)
    {
     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:

if(ObjectType("line_object2")!=OBJ_HLINE) return(0);
This article url: http://www.myeatrade.com/450/

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