Download MetaTrader 5
To add comments, please log in or register
Do you want to become a well-known developer? Execute the orders of traders in the Freelance service!
kerso4
203
kerso4 2015.10.31 12:22 

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 

Marco vd Heijden
Moderator
4073
Marco vd Heijden 2015.10.31 12:51  
does it exist in Object List ?
kerso4
203
kerso4 2015.10.31 12:57  
No it doens't exist in ObjectList
Ndumiso Mavuso
4305
Ndumiso Mavuso 2015.10.31 15:59  
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);
  }
Stuart Browne
5534
Stuart Browne 2015.11.01 01:06  
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?

kerso4
203
kerso4 2015.11.01 09:43  
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
Stuart Browne
5534
Stuart Browne 2015.11.01 09:59  
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?
Doerk Hilger
1074
Doerk Hilger 2015.11.01 14:29  

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 

kerso4
203
kerso4 2015.11.01 19:59  

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. 

Doerk Hilger
1074
Doerk Hilger 2015.11.01 20:18  
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. 
/
To add comments, please log in or register