Object click priority always to rectangle label?

 

I have noticed that Rectangle Labels receive click priority over Labels, irrespective to the z-order assignment. Is this behavior deliberate?

This can be seen by creating a rectangle label with z-order 0, which partially overlaps a label with z-order 100.

When clicking on the "So" text not over the rectangle label:

 

When clicking on the "e Text" text over the rectangle label:

 

 So the higher z-order of the label is being ignored when it overlaps a rectangle label. 

#property strict
#property indicator_chart_window

int OnInit() {
   string name="Rectangle Label";
   ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,0,0,0);
   ObjectSetInteger(0, name, OBJPROP_BGCOLOR,  clrWhite);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_XSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_YSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_ZORDER,   0);   
   
   name="Label";
   ObjectCreate(0,name,OBJ_LABEL,0,0,0);
   ObjectSetInteger(0, name, OBJPROP_COLOR,    clrMagenta);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE,80);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE,110);
   ObjectSetString (0, name, OBJPROP_TEXT,     "Some Text");
   ObjectSetInteger(0, name, OBJPROP_ZORDER,   100);
   return(INIT_SUCCEEDED);}

void OnDeinit(const int reason) {
   ObjectDelete(0,"Rectangle Label");
   ObjectDelete(0,"Label");}

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[]) {
   return(rates_total);}

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) {
   if(id==CHARTEVENT_OBJECT_CLICK) {
      long z=ObjectGetInteger(0,sparam,OBJPROP_ZORDER);
      printf("I am %s, my z-order is %i",sparam,z);}}
 

Have you considered ObjectSetInteger() and the option OBJPROP_BACK (bool) = Object in the background?


 

Thanks for the reply gooly. Unfortunately, it gives exactly the same result:

 

#property strict
#property indicator_chart_window

int OnInit() {
   string name="Rectangle Label";
   ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,0,0,0);
   ObjectSetInteger(0, name, OBJPROP_BGCOLOR,  clrWhite);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE,100);
   ObjectSetInteger(0, name, OBJPROP_XSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_YSIZE,    50);
   ObjectSetInteger(0, name, OBJPROP_ZORDER,   0);
   ObjectSetInteger(0, name, OBJPROP_BACK,     true);   
   name="Label";
   ObjectCreate(0,name,OBJ_LABEL,0,0,0);
   ObjectSetInteger(0, name, OBJPROP_COLOR,    clrMagenta);
   ObjectSetInteger(0, name, OBJPROP_XDISTANCE,80);
   ObjectSetInteger(0, name, OBJPROP_YDISTANCE,110);
   ObjectSetString (0, name, OBJPROP_TEXT,     "Some Text");
   ObjectSetInteger(0, name, OBJPROP_ZORDER,   100);
   ObjectSetInteger(0, name, OBJPROP_BACK,     false);
   return(INIT_SUCCEEDED);}

void OnDeinit(const int reason) {
   ObjectDelete(0,"Rectangle Label");
   ObjectDelete(0,"Label");}

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[]) {
   return(rates_total);}

void OnChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam) {
   if(id==CHARTEVENT_OBJECT_CLICK) {
      long z=ObjectGetInteger(0,sparam,OBJPROP_ZORDER);
      printf("I am %s, my z-order is %i",sparam,z);}}
 
If I not mistaken, z-order would work like it should if it is of the same type of object. Different object would have different z-order priority. In this case, that is most probably.
 

Thanks for the reply. That may be the case, but sadly I have not found anywhere in the documentation what the hierarchy of objects is.

Also, the zorder seems to be working between certain object types. 

For example, Labels over Rectangle Labels, the rectangle label always wins.

Buttons over Rectangle Labels, the zorder system works correctly (even though they are different object types).

OBJPROP_ZORDER

Priority of a graphical object for receiving events of clicking on a chart (CHARTEVENT_CLICK). The default zero value is set when creating an object; the priority can be increased if necessary. When applying objects one over another, only one of them with the highest priority will receive the CHARTEVENT_CLICK event.

long

 

Hi,

very interesting  thread! Has anybody a solution for that Problem?

 
sunshineh:

Hi,

very interesting  thread! Has anybody a solution for that Problem?

It's a mql4 bug (tested with  build 765). The same code works well with mql5.

Bugs have to be reported to ServiceDesk.

 
Thanks a lot for that info! I hope the bug will be corrected soon because this would be a very useful functionality
 

Still not solve this bug?

I am troubled by the same bug while I creating my Virtul Trade System.

It cost me 1 hour to try to find out WHY , untile I find this article.

I give up WHY and try to find HOW.Wana make a label with background? Just use two label with different ZOder,and a character string like this "█". Do not forget to set font to NULL.

Now I got every Order Label  with background.


post

 
Still not solved and this same problem for OBJ_RECTANGLE
 

Hello please replace the OBJ_RECTANGLE with OBJ_BUTTON and set the OBJPROP_ZORDER lower priority then the button you want clickable.

Also first create the background and then the foreground so that the object you want to be clickable is created last so its stacked on top.

Reason: