Drawing a rectangle

 

Hi there, forum MQL5,

I have been trying to draw a rectangle in MQL5 with no success. I surfed many post about it, some about sth I don't want and others that corrects the code i have, but even changing as in the post it doesn't paint anything.

ObjectCreate(0,"box",OBJ_RECTANGLE,0,time1,price1,time2,price2);
if(!ObjectCreate(0,"box",OBJ_RECTANGLE,0,time1,price1,time2,price2)) 
     { 
      Print(__FUNCTION__,": failed to create a rectangle! Error code = ",GetLastError()); 
      return(false); 
     } 
ObjectSetInteger(0,"box",OBJPROP_COLOR,clrRed);
ChartRedraw(0);

 I might have some problems with times and prices.

I drawn a box last week and don't remember how. I remember i wrote the 2 points in % of the chart window, but seems it doesn't match times and prices any more lol so i might be getting lost.

I also know a couple of functions which change from time and price to XY coordinates and viceversa but don't know how to mix everything and get a simple red rectangle.

 

Thanks for your attention and help in advance.

kerso 

 
does it exist in Object List ?
 
No it doens't exist in ObjectList
 
void OnTick()
{
RectLabelCreate();//This where Your EA receive ticks

}
Return;


void RectLabelCreate(const long             chart_ID=0,               // chart's ID
                     const string           name="RectLabel",         // label name
                     const int              sub_window=0,             // subwindow index
                     const int              x=0,                      // X coordinate
                     const int              y=0,                      // Y coordinate
                     const int              width=250,                 // width
                     const int              height=116,                // height
                     const color            back_clr=clrSkyBlue,  // background color
                     const ENUM_BORDER_TYPE border=BORDER_FLAT,     // border type
                     const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // chart corner for anchoring
                     const color            clr=clrNONE,               // flat border color (Flat)
                     const ENUM_LINE_STYLE  style=STYLE_DOT,        // flat border style
                     const int              line_width=1,             // flat border width
                     const bool             back=false,               // in the background
                     const bool             selection=false,          // highlight to move
                     const bool             hidden=true,              // hidden in the object list
                     const long             z_order=0)  
  {
   ObjectCreate(chart_ID,name,OBJ_RECTANGLE_LABEL,sub_window,0,0);
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
   ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
   ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
   ObjectSetInteger(chart_ID,name,OBJPROP_BGCOLOR,clrSkyBlue);
   ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clrNONE);
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,2);
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,true);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,false);
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,true);
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,0);
  }
 
kerso4:
No it doens't exist in ObjectList

Does the error message print out? Or does it appear to work (eg no error message)?

If not, I had the exact same problem last week in MQL4 drawing a rect in a subwindow. Drove me crazy for hours as the code was 100% correct and it wasn't throwing any error messages. But the rect simply did not exist. In the end, I moved the code into a new function and it suddenly started working. Very bizarre. Maybe give that a try?

 
I have tried to draw a button and a rectanglelabel and both work, but then once i change it to rectangle it just doesnt want to work. Will try to move it to a new function and will let you know the results
 
kerso4:
I have tried to draw a button and a rectanglelabel and both work, but then once i change it to rectangle it just doesnt want to work. Will try to move it to a new function and will let you know the results
Please do mate. Are you getting an error message?
 

You write a function with presetted parameters and don´t use them. Where is the sense?

This is MQL5, and the reasons are much simpler for things like these:

#include <Controls/Panel.mqh>
CPanel panel;

//...
//...

panel.Create(ChartID(),"RectLabel",0,0,0,250,116);
panel.ColorBackground(clrSkyBlue);

Done. 

Doerk 

 

No, it runs perfectly, except it doesnt draw the rectangle. Its not in Object List, it doesnt exist.

Hi Doerk, thanks for your attention, im a newbie in programming so thanks again for you help, but next time come in other mood. 

 
kerso4:

No, it runs perfectly, except it doesnt draw the rectangle. Its not in Object List, it doesnt exist.

Hi Doerk, thanks for your attention, im a newbie in programming so thanks again for you help, but next time come in other mood. 

Oops. Sorry, wasn´t meant like that at all. 
Reason: