Drawing Filled Rectangles in MQL4/MQL5

(This post will be interesting only to those who code in MQL4 or MQL5 languages.)
Drawing a rectangle in MQL-coded indicator or expert advisor is quite an easy task in both MetaTrader 4 and MetaTrader 5 platforms. All you have to do is to call the ObjectCreate() function with rather simple parameters. For example, in MQL4 it goes like this:

ObjectCreate("Rectangle", OBJ_RECTANGLE, 0, Time[0], price1, Time[1], price2);

And in MQL5 it would look almost the same:

ObjectCreate(0, "Rectangle", OBJ_RECTANGLE, 0, Time[0], price1, Time[1], price2);

But filling the rectangle in MQL5 or drawing it unfilled in MQL4 wasn’t so obvious to me. The rectangles come unfilled by default in MT5 and filled by default in MT4. OBJPROP_BACK is the property that responds for that. For example, to make a rectangle unfilled in MQL4 you can call this function:

ObjectSet("Rectangle", OBJPROP_BACK, false);

And to fill the rectangle in MQL5 you would change the property to true:

ObjectSetInteger(0, "Rectangle", OBJPROP_BACK, true);


If you have any questions or comments regarding drawing of the rectangles in MQL4 or MQL5, please, use the commentary form below.

Leave a Reply

Your email address will not be published. Required fields are marked *

28 − = twenty two