Question about ObjectCreate, Rectangles

 

Hello,

Im trying to understand ObjectCreate function for couple of days now.

I just don't understand the 2 or more last parameters: priceN and timeN.

What are they? 

At the beggining I thought that the are the coordinate of the object but then I saw the:OBJPROP_TIME,OBJPROP_YDISTANCE,OBJPROP_XSIZE,OBJPROP_YSIZE,OBJPROP_XOFFSET and I've got totally confused.


The second question is about making a rectangle on the screen.

How do I do it? how do I set the width and height of it? do I set coordinate of it? How does it work?


Thank you,

yuv.

 
yuv98:

Hello,

Im trying to understand ObjectCreate function for couple of days now.

I just don't understand the 2 or more last parameters: priceN and timeN.

What are they? 

At the beggining I thought that the are the coordinate of the object but then I saw the:OBJPROP_TIME,OBJPROP_YDISTANCE,OBJPROP_XSIZE,OBJPROP_YSIZE,OBJPROP_XOFFSET and I've got totally confused.


The second question is about making a rectangle on the screen.

How do I do it? how do I set the width and height of it? do I set coordinate of it? How does it work?


Thank you,

yuv.


1) Show us your code.

2) First price and time is the starting location of the rectangle, Second price and time is the end location of the rectangle.

3) There is example code on this page. https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_rectangle








Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_RECTANGLE
Documentation on MQL5: Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_RECTANGLE
  • www.mql5.com
Standard Constants, Enumerations and Structures / Objects Constants / Object Types / OBJ_RECTANGLE - Reference on algorithmic/automated trading language for MetaTrader 5
 
Jack Thomas:

1) Show us your code.

2) First price and time is the starting location of the rectangle, Second price and time is the end location of the rectangle.

3) There is example code on this page. https://www.mql5.com/en/docs/constants/objectconstants/enum_object/obj_rectangle








I read the example and I understnad that the set of Object_Rectangle and Object_Rectangle_LABEL are totally different. 

I mean Object_Rectangle_LABEL is set by (x,y) point that relative to the corner of the chart and Object_Rectangle is by (price,time) point? this is where I get confused.

 

Here is another probelm thaat I don't understand about rectangles:

Im trying to draw a rectangle on my 0 candle in the chart, I was trying to use this code:


 ObjectCreate(0,"rect",OBJ_RECTANGLE,0,rates[0].time+60,rates[0].open,rates[0].time-60,rates[0].close);


and it just doesn't work. the rectangle is moving wired when I change the "60" parameter.

 

Some object types are placed by entering time and price parameters where other objects are placed by entering X and Y axis parameters.

The objects that are pegged to time and price will move when the chart is scrolled where the X and Y pegged objects remain stationary as an overlay on the chart, when it is scrolled underneath.

It all depends on what you are trying to do with it.

For details on the object type and its anchor points you can look at the specifications on the object type in the documentation.

ENUM_OBJECT

ID

 

Description

OBJ_VLINE


Vertical Line

OBJ_HLINE


Horizontal Line

OBJ_TREND


Trend Line

OBJ_TRENDBYANGLE


Trend Line By Angle

OBJ_CYCLES


Cycle Lines

OBJ_ARROWED_LINE


Arrowed Line

OBJ_CHANNEL


Equidistant Channel

OBJ_STDDEVCHANNEL


Standard Deviation Channel

OBJ_REGRESSION


Linear Regression Channel

OBJ_PITCHFORK


Andrews’ Pitchfork

OBJ_GANNLINE


Gann Line

OBJ_GANNFAN


Gann Fan

OBJ_GANNGRID


Gann Grid

OBJ_FIBO


Fibonacci Retracement

OBJ_FIBOTIMES


Fibonacci Time Zones

OBJ_FIBOFAN


Fibonacci Fan

OBJ_FIBOARC


Fibonacci Arcs

OBJ_FIBOCHANNEL


Fibonacci Channel

OBJ_EXPANSION


Fibonacci Expansion

OBJ_ELLIOTWAVE5


Elliott Motive Wave

OBJ_ELLIOTWAVE3


Elliott Correction Wave

OBJ_RECTANGLE


Rectangle

OBJ_TRIANGLE


Triangle

OBJ_ELLIPSE


Ellipse

OBJ_ARROW_THUMB_UP


Thumbs Up

OBJ_ARROW_THUMB_DOWN


Thumbs Down

OBJ_ARROW_UP


Arrow Up

OBJ_ARROW_DOWN


Arrow Down

OBJ_ARROW_STOP


Stop Sign

OBJ_ARROW_CHECK


Check Sign

OBJ_ARROW_LEFT_PRICE


Left Price Label

OBJ_ARROW_RIGHT_PRICE


Right Price Label

OBJ_ARROW_BUY


Buy Sign

OBJ_ARROW_SELL


Sell Sign

OBJ_ARROW


Arrow

OBJ_TEXT


Text

OBJ_LABEL


Label

OBJ_BUTTON


Button

OBJ_CHART


Chart

OBJ_BITMAP


Bitmap

OBJ_BITMAP_LABEL


Bitmap Label

OBJ_EDIT


Edit

OBJ_EVENT


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

OBJ_RECTANGLE_LABEL


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

 
yuv98:

Hello,

Im trying to understand ObjectCreate function for couple of days now.


Hi Yuv,

It's much easier to use the standard library. Here's an example that draws a rectangle around the highest high and lowest low of the last 50 bars.


//+------------------------------------------------------------------+
//|                                                    Rectangle.mq4 |
//|                                                      nicholishen |
//|                                   www.reddit.com/u/nicholishenFX |
//+------------------------------------------------------------------+
#property copyright "nicholishen"
#property link      "www.reddit.com/u/nicholishenFX"
#property version   "1.00"
#property strict
#property indicator_chart_window

#include <ChartObjects\ChartObjectsShapes.mqh>
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

CChartObjectRectangle rect;
int OnInit()
  {
//--- indicator buffers mapping
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   ArraySetAsSeries(time,true);
   ArraySetAsSeries(high,true);
   ArraySetAsSeries(low,true);
   int h = iHighest(Symbol(),Period(),MODE_HIGH,50,0);
   int l = iLowest(Symbol(),Period(),MODE_LOW,50,0);
   
   if(prev_calculated == 0)
   {
      rect.Create(0,"Rect",0,time[h],high[h],time[l],low[l]);
   }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 

Thank you!

But I have more questions about it:

1)How can I draw a rectangle on my 0 candle? I mean a rect that is just "on" the candle.

I was trying to do it with:

 ObjectCreate(0,"rect",OBJ_RECTANGLE,0,rates[0].time+60,rates[0].open,rates[0].time-60,rates[0].close);

but it didn't work...

2) What is the difference between standard library and the default functions?

 
yuv98:

Thank you!

But I have more questions about it:

1)How can I draw a rectangle on my 0 candle? I mean a rect that is just "on" the candle.

I was trying to do it with:

 ObjectCreate(0,"rect",OBJ_RECTANGLE,0,rates[0].time+60,rates[0].open,rates[0].time-60,rates[0].close);

but it didn't work...

2) What is the difference between standard library and the default functions?

The standard library gives you access to classes that neatly packages the API functions so you can write 1 line of code instead of 10. See my example above. If you are unfamiliar with OOP and working with objects then disregard. 
 
   ObjectCreate("rec1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("rec1", "n", 280, "Wingdings", White);
   ObjectSet("rec1", OBJPROP_CORNER, CORNER_RIGHT_UPPER);
   ObjectSet("rec1", OBJPROP_XDISTANCE,-15);
   ObjectSet("rec1", OBJPROP_YDISTANCE, -75);
   ObjectSet("rec1", OBJPROP_BACK, true);

try using this code.

 

thank you

Reason: