Friday, September 25, 2015

How to solve rectangle overlapping issue in MQL4

Are you having trouble fitting the rectangles one on top of the other without the colors mixing or creating color gaps if they both have the same color?
That's not an easy one to solve, since MT4 does not allow you to set any priorities between rectangle objects. So you're left with 2 pretty complex solutions:

1. Either build your overlapping rectangles form out of small blocks that do not overlap.
2. Add a rectangle over the overlapping part and make its color complementary to the color of the recntagle that serves as background. That will nulify its RGB values and allow the rectangle on top to be displayed without any interference. 

Here is a function that I've managed to find (courtesy of the mql5 community, which gives you the "masking" color for background rectangle. 


color MaskColour(color back, color front, color chartBackground) {
   back ^= front;
   back ^= chartBackground;
   return back;
}

I've only altered it to remove the chartBackground as a parameter and read the chart background color automatically.


color mask_color(color back,color front)
  {
   color chartBackground=(color)ChartGetInteger(0,CHART_COLOR_BACKGROUND);
   back^=front;
   back^=chartBackground;
   return(back);
  }

No comments:

Post a Comment