Rectangle overlay and mix color ...

Back to topics list To post a new topic, please log in or register
avatar
57
haemse 2011.11.25 14:12
 

Hello Everybody,

when i set rectangle objects that overlay, their color mixes up like they are transparent. However, how can i change that, so the color stays the color i set up for the rectangle?

really annoying ...

thanks for any help!

 
avatar
14167
RaptorUK 2011.11.25 15:24 #
 
haemse:

really annoying ...

thanks for any help!

Yep, I think you have to live with it, there is no concept of moving object in front or behind others . . .
 
avatar
57
haemse 2011.11.25 16:49 #
 
RaptorUK:
Yep, I think you have to live with it, there is no concept of moving object in front or behind others . . .


THX,

ok and how about making them intransparent?

avatar
13006
WHRoeder 2011.11.25 17:24 #
 

Actually this is, at least for lines Displaying of Support/Resistance Levels - MQL4 Articles

Won't help with rectangles though. You'll have to split the 'non-top' rectangle into pieces and remove the overlapped portions.

Just typed, not checked, not tested:
rectangleMinus(
    string name, double hi, double lo, datetime left, datetime right, color clr,
    double top_h, double top_l, datetime top_left, datetime top_right
){
    if (hi > top_h){
        rect(name+"1", hi, MathMax(lo, top_h), left, right, clr);
        hi = top_h;
    }
    if (lo < top_l){
        rect(name+"2", MathMin(hi, top_l), lo, left, right, clr);
        lo = top_l;
    }
    if (left < top_left){
        rect(name+"3", hi, lo, left, MathMinDt(right,top_left), clr);
        left = top_right;
    }
    rect(name+"4", hi, lo, left, right, clr);
}
datetime MathMaxDt(datetime a, datetime b){ if (a > b)  return(a);  return(b); }
datetime MathMinDt(datetime a, datetime b){ if (a < b)  return(a);  return(b); }
void rect(string name, double hi, double lo, datetime left, datetime right, clr)
    if (hi <= lo || left >= right) return;
    if      (ObjectMove( name, 0, left, hi ))     ObjectMove(name, 1, right, lo);
    else if (!ObjectCreate( name, OBJ_RECTANGLE, WINDOW_MAIN, left, hi, right, lo ))
        Alert("ObjectCreate(",name,",OBJ_RECTANGLE) failed: ", GetLastError() );
    if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError());
}
 
avatar
57
haemse 2011.11.27 13:42 #
 
WHRoeder:

Actually this is, at least for lines Displaying of Support/Resistance Levels - MQL4 Articles

Won't help with rectangles though. You'll have to split the 'non-top' rectangle into pieces and remove the overlapped portions.

Just typed, not checked, not tested:


Thank you for that code, although this would be to complicated for that issue ... i chooesed colores that mix up to the color i want it to be ...

The graphical interface of mt4 ist not very friendly ;-)

 
avatar
4
bruce_loco 2011.12.08 17:57 #
 
haemse:


Thank you for that code, although this would be to complicated for that issue ... i chooesed colores that mix up to the color i want it to be ...

The graphical interface of mt4 ist not very friendly ;-)

It is a lot simpler, the color is a bit mask

This function gives you the required value

color mask_color(color back, color front)
{
back ^=front;
return(back);

}

The first object you give any color you like, IE, Blue, the second object you do:

ObjectSet(objname, OBJPROP_COLOR, mask_color(Blue,Green)); -> green is the desired color

Have fun ;-)

 
avatar
4
bruce_loco 2011.12.08 19:34 #
 
bruceloco:

It is a lot simpler, the color is a bit mask

This function gives you the required value

color mask_color(color back, color front)
{
back ^=front;
return(back);

}

The first object you give any color you like, IE, Blue, the second object you do:

ObjectSet(objname, OBJPROP_COLOR, mask_color(Blue,Green)); -> green is the desired color

Have fun ;-)


avatar
57
haemse 2011.12.09 09:26 #
 

@bruceloco:

Oh thank you, that is a nice way!

avatar
40
Hoodlum 2015.01.07 17:56 #
 

Excuse me for dredging up an old thread, but this has been bugging me for a while. I've been having to use rect labels in my indis to get overlapping colours to display how I want them.

The function above works great, but only on a chart with a black background. If your chart has a background of any other colour, you need to add a third parameter to get the correct mask colour:

 

color MaskColour(color back, color front, color chartBackground) {
   back ^= front;
   back ^= chartBackground;
   return back;
}
Back to topics list  

To add comments, please log in or register