Drawing Filled Rectangles in MQL4 and MQL5: A Practical Guide for MetaTrader Developers
Camovia Tray Team · 2026-09-11
There’s a moment every MetaTrader developer knows well. You've just coded a custom indicator or a script that needs to visually highlight a specific price zone on the chart—a support level, a breakout range, or a time-based session. You write the ObjectCreate() function, define your OBJ_RECTANGLE, and compile. But when you attach it to the chart, the rectangle doesn't look quite right. In MT4, it's filled solid, hiding the price action beneath it. In MT5, it's just an empty outline, barely visible. Getting the filled state right across both platforms is one of those small but critical details that can derail a perfectly good implementation.
The root of the confusion lies in how the two MetaTrader versions handle the same visual property. In MQL4, the OBJPROP_BACK property controls whether a rectangle is filled. Setting it to false makes it unfilled (transparent), while true or the default state makes it a solid, opaque block . If you're coming from an MQL4 background, you might instinctively try the same approach in MQL5. But in MQL5, OBJPROP_BACK only controls whether the object is drawn behind the chart's price bars or in front of them—it has nothing to do with the fill state . To get a filled rectangle in MQL5, you need to use the OBJPROP_FILL property and set it to true .
Let's look at a typical scenario. Suppose you're building a range-breakout indicator that draws a filled rectangle to visually mark the consolidation zone. In MT4, your code might look something like this to create an unfilled box:
ObjectCreate("RangeBox", OBJ_RECTANGLE, 0, time1, price1, time2, price2);
ObjectSet("RangeBox", OBJPROP_BACK, false); If you ported this logic directly to MT5, you'd need to adjust it to:
ObjectCreate(0, "RangeBox", OBJ_RECTANGLE, 0, time1, price1, time2, price2);
ObjectSetInteger(0, "RangeBox", OBJPROP_FILL, true); As shown in the MQL5 documentation, OBJPROP_FILL is the dedicated property for this purpose, and it even applies to other shapes like triangles and ellipses .
Now, what if you need to manage these objects on a live chart that's constantly updating? You might want a box that follows the latest price. One practical approach is to redraw your rectangle so its second anchor point always ties to the current time, ensuring the highlight moves with the market . But repeatedly creating and deleting graphical objects can be computationally expensive and might slow down your chart's performance . This becomes especially noticeable when managing multiple instances simultaneously. This is where having an efficient workflow matters. If you're frequently switching between coding, testing your indicator in MT4, then porting it to MT5, juggling terminal windows becomes another distraction.
This is where a tool like Camovia Tray offers a subtle but practical benefit. While it won't write your code for you, it can streamline the environment where you do your development and testing. Camovia Tray lets you run your MetaTrader 4 or 5 instance minimized directly from your system tray [Product Knowledge]. It provides quick access to view live quotes and even manage open positions without needing to restore the full terminal window [Product Knowledge]. Instead of wrestling with Alt+Tab to find your terminal among multiple open windows, you can hover over the tray icon to check if a new price tick has triggered your rectangle condition. Your charts and scripts can continue running in the background, while you manage your development and testing from a single, unobtrusive point on your taskbar.
Whether you're debugging a for loop that cycles through all rectangles on a chart to toggle their filled status, or you're meticulously setting the OBJPROP_FILL property in MQL5's ObjectSetInteger function, the focus should be on the logic, not on window management . By keeping your MT5 or MT4 tucked away, Camovia Tray lets you maintain that focus, ensuring your environment is as streamlined as your code.
Turn MT5 / MT4 into a Tray Tool
Check quotes, manage positions, and hide in one click.
Download Camovia TrayFrequently Asked Questions
Do I need MT5/MT4 installed? Does the terminal need to stay open?
Yes. Camovia Tray reads quote and position data from your locally running MT5/MT4 terminal, so the terminal must be installed, running, and logged in. MT5 connects directly with no EA; MT4 needs the bundled bridge EA attached once (one-click copy in Settings, then double-click in the Navigator - see the docs).
Are my quotes and positions uploaded anywhere?
No. Quote and position data is read 100% from your local MT5/MT4 terminal and never leaves your computer. See the privacy policy for details.
Which systems and terminals are supported?
Windows 10 / 11, with MetaTrader 5 or MetaTrader 4 (installed and logged in; MT4 needs the bridge EA attached once).
Is the MT4 bridge EA safe? What do I need to enable?
Yes. The bridge EA (CamoviaBridge) is bundled with the app - it only reads quotes/positions locally and executes close commands; no DLLs, no data uploads. Closing positions requires turning on AutoTrading in the MT4 toolbar.
Popular Symbols Trading Hours
Open/close times, weekend hours & live market status:
Related Articles
MT5 Position Sizer: Size Your Lots by Risk Percentage
Looking for an MT5 position sizer? The order dialog only asks for lots — learn the risk-percentage formula, a worked example, and the tools that automate it.
Why Isn’t There a Built-In Position Drawdown Analyzer in MT4/MT5? (And How to Fix That)
Learn how to monitor position drawdown risk in real time without opening MT4/MT5. Camovia Tray shows open positions and P&L from your system tray for faster risk decisions.
Best MT5 Tray Monitor: Why Every Trader Needs One (And How to Choose)
Discover the best MT5 tray monitor for quick quotes, position management, and privacy. Camovia Tray turns MT5/MT4 into a discreet tray tool—data stays local.
VPS for MT4/MT5 EAs: Why You Need One and How to Choose the Right One
Learn why a VPS is essential for MT4/MT5 EAs, how to choose the right provider, and how Camovia Tray simplifies terminal access from your local machine.
The Fibonacci EA Trap: Why Your Expert Advisor Isn't Working (And How to Fix It)
Discover why your Fibonacci EA fails on lower timeframes and different pairs. Learn to monitor MT5/MT4 positions efficiently with Camovia Tray.