Previous  Next

The Chart Corner to Which an Object Is Attached

There is a number of graphical objects for which you can set a chart corner, relative to which the coordinates are specified in pixels. These are the following types of objects (in brackets object type identifiers are specified):

Object

ID

X/Y

Width/Height

Date/Price

OBJPROP_CORNER

OBJPROP_ANCHOR

OBJPROP_ANGLE

Text

OBJ_TEXT

Yes

Yes

Yes

Label

OBJ_LABEL

Yes

Yes (read only)

Yes

Yes

Yes

Button

OBJ_BUTTON

Yes

Yes

Yes

Bitmap

OBJ_BITMAP

Yes (read only)

Yes

Yes

Bitmap Label

OBJ_BITMAP_LABEL

Yes

Yes (read only)

Yes

Yes

Edit

OBJ_EDIT

Yes

Yes

Yes

Rectangle Label

OBJ_RECTANGLE_LABEL

Yes

Yes

Yes

The following designations are used in the table:

In order to specify the chart corner, from which X and Y coordinates will be measured in pixels, use ObjectSetInteger(chartID, name, OBJPROP_CORNER, chart_corner), where:

ENUM_BASE_CORNER

ID

Description

CORNER_LEFT_UPPER

Center of coordinates is in the upper left corner of the chart

CORNER_LEFT_LOWER

Center of coordinates is in the lower left corner of the chart

CORNER_RIGHT_LOWER

Center of coordinates is in the lower right corner of the chart

CORNER_RIGHT_UPPER

Center of coordinates is in the upper right corner of the chart

Example:

void CreateLabel(long   chart_id,
                 string name,
                 int    chart_corner,
                 int    anchor_point,
                 string text_label,
                 int    x_ord,
                 int    y_ord)
  {
//---
   if(ObjectCreate(chart_id,name,OBJ_LABEL,0,0,0))
     {
      ObjectSetInteger(chart_id,name,OBJPROP_CORNER,chart_corner);
      ObjectSetInteger(chart_id,name,OBJPROP_ANCHOR,anchor_point);
      ObjectSetInteger(chart_id,name,OBJPROP_XDISTANCE,x_ord);
      ObjectSetInteger(chart_id,name,OBJPROP_YDISTANCE,y_ord);
      ObjectSetString(chart_id,name,OBJPROP_TEXT,text_label);
     }
   else
      Print("Failed to create the object OBJ_LABEL ",name,", Error code = "GetLastError());
  }
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int height=(int)ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);
   int width=(int)ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0);
   string arrows[4]={"LEFT_UPPER","RIGHT_UPPER","RIGHT_LOWER","LEFT_LOWER"};
   CreateLabel(0,arrows[0],CORNER_LEFT_UPPER,ANCHOR_LEFT_UPPER,arrows[0],50,50);
   CreateLabel(0,arrows[1],CORNER_RIGHT_UPPER,ANCHOR_RIGHT_UPPER,arrows[1],50,50);
   CreateLabel(0,arrows[2],CORNER_RIGHT_LOWER,ANCHOR_RIGHT_LOWER,arrows[2],50,50);
   CreateLabel(0,arrows[3],CORNER_LEFT_LOWER,ANCHOR_LEFT_LOWER,arrows[3],50,50);
  }