Download MetaTrader 5

How to draw rectangles on top of the chart?

To add comments, please log in or register
Tosh5457
232
Tosh5457  
How do I draw rectangles on the top of the chart? I also want them to stay there if I zoom or unzoom. 
whroeder1
17081
whroeder1  
Use the rectangle tool. What's the problem?
MisterDog
383
MisterDog  

OBJ_RECTANGLE uses two coordinates and will move with the bars as you zoom in and out.

OBJ_LABEL uses 1 coordinate in pixels and will remain relative to the window as you zoom in and out. This is what you are looking for, right?

Try using OBJ_LABEL with Wingdings as a work around. This will draw a "rectangle" that remains relative to the window.

 

   ObjectCreate("rec1", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("rec1", "n", 200, "Wingdings", Gray);
   ObjectSet("rec1", OBJPROP_XDISTANCE, 10);
   ObjectSet("rec1", OBJPROP_YDISTANCE, 20);
   ObjectSet("rec1", OBJPROP_BACK, true);
   
   ObjectCreate("rec2", OBJ_LABEL, 0, 0, 0);
   ObjectSetText("rec2", "n", 200, "Wingdings", Gray);
   ObjectSet("rec2", OBJPROP_XDISTANCE, 10);
   ObjectSet("rec2", OBJPROP_YDISTANCE, 120);
   ObjectSet("rec2", OBJPROP_BACK, true);
Tosh5457
232
Tosh5457  
MisterDog:

OBJ_RECTANGLE uses two coordinates and will move with the bars as you zoom in and out.

OBJ_LABEL uses 1 coordinate in pixels and will remain relative to the window as you zoom in and out. This is what you are looking for, right?

Try using OBJ_LABEL with Wingdings as a work around. This will draw a "rectangle" that remains relative to the window.

 


 

Thanks. Now what I wanted to do was to draw a rectangle at the top of each bar, and keep it always on the top of the chart. Do you know how to do that?
whroeder1
17081
whroeder1  
You can NOT "draw a rectangle at the top of each bar"! Each rectangle must have a starting and stopping date/time (and price). Therefor the rectangle must cover one bar to another.
Tosh5457
232
Tosh5457  
WHRoeder:
You can NOT "draw a rectangle at the top of each bar"! Each rectangle must have a starting and stopping date/time (and price). Therefor the rectangle must cover one bar to another.

Yes you can, using what MisterDog said. Now what I want to do is to keep them fixed on the top of the chart, for each bar.
whroeder1
17081
whroeder1  

You asked about drawing a rectangle. You can NOT use a rectangle object.

MisterDog said to use a LABEL. That would put a SQUARE on the window.  That means they will not stay with the bar as the chart scrolls. And you can't zoom the chart unless you repaint the objects each time.

If you want a SQUARE, you can use a wingding text object. Those will move with the bars.

MisterDog
383
MisterDog  

Yes, well put WHRoeder. It took me awhile to wrap my head around the idea that some objects are oriented to the screen and positioned with pixels. While other objects are oriented to the chart positioned by bars and pips.

From your additional comments, it sounds like my recommendation is not your solution.

Denny Muhammad Zein
1752
Denny Muhammad Zein  
Tosh5457:
How do I draw rectangles on the top of the chart? I also want them to stay there if I zoom or unzoom. 

Try this

ChartSetInteger(ChartID(),CHART_FOREGROUND,0,false);

ObjectCreate(ChartID(),"obj_rect",OBJ_RECTANGLE_LABEL,0,0,0) ;
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XDISTANCE,100);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YDISTANCE,100);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_BACK,false);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_XSIZE,300);
ObjectSetInteger(ChartID(),"obj_rect",OBJPROP_YSIZE,100);
To add comments, please log in or register