Camovia Tray™

Blog · Knowledge

How to Check Open Orders in MQL4 – And Why the Usual Method Can Be a Trap

Camovia Tray Team · 2026-09-14

If you've written even a basic Expert Advisor in MQL4, you've probably used OrdersTotal() inside a for loop to scan through open orders. It's in every beginner tutorial, and it's often copied and pasted without a second thought. The assumption is simple: OrdersTotal() gives you the count, OrderSelect() lets you loop through them, and you're good to go.

But this "standard" approach has a blind spot that can break your EA or script at the worst possible moment.

The core issue is that OrdersTotal() returns the total number of market and pending orders . When you loop from 0 to OrdersTotal() - 1 while using OrderSelect() by position, you're working with a live, constantly changing list. If an order is closed or modified by another part of your code, a different terminal, or even the trader manually, the order pool shifts. This means an order you already processed might be gone, or a new one could appear before you've finished your loop.

Another common pitfall is misunderstanding the OrderSelect() function itself. It copies the order's data into a program environment. If you select an order and don't reselect it before reading its properties, you might be working with stale data . The official MQL4 documentation strongly recommends calling OrderSelect() directly before you request any order data to ensure it's current .

So, what's the less error-prone way? Many seasoned developers loop backward: for(int i = OrdersTotal() - 1; i >= 0; i--) . This simple change means that even if an order is closed and the list shrinks, you won't accidentally skip an order or try to access an index that no longer exists. It's a small adjustment, but it makes your code significantly more robust.

Another layer of complexity is the pool parameter in OrderSelect(). By default, it uses MODE_TRADES, which selects from open and pending orders . But if you're not careful, you might find your script returning errors because it's trying to select an order that has already moved to the history pool (closed or canceled orders). To work with those, you need to explicitly use MODE_HISTORY .

This brings us to a broader point about how we interact with MT4. Many traders who don't code rely on the Terminal window's "Trade" tab to manually check their open orders . While this works, it requires keeping the MT4 platform visible and navigating through its interface. For a trader who prefers a clean desktop, having the entire terminal window open just to peek at a P&L or close a position is a distraction.

This is where a tool like Camovia Tray changes the workflow. Instead of coding a loop to check orders or switching to the MT4 window, Camovia Tray turns the MetaTrader terminal into a system tray tool [citation:Product Knowledge]. It reads the open positions directly from your local MT4 instance and displays them in a floating order window. You can see the symbol, direction, lot size, open price, and current profit/loss at a glance [citation:Product Knowledge].

And it doesn't just show you the information—it lets you act on it. The "how to check" problem is often followed by "how to close." Camovia Tray includes a one-click close function for any displayed position, with a simple two-step confirmation to prevent accidental clicks [citation:Product Knowledge]. This eliminates the need to open the full terminal, find the order, right-click, and select "Close Order."

Furthermore, while building a proper EA to manage orders with robust error handling takes time and expertise, Camovia Tray provides a ready-made solution for local order management. It acts as a companion that sits quietly in your system tray, ensuring your order data is always visible without being intrusive, all while keeping that data entirely on your machine [citation:Product Knowledge].

The technical details of OrdersTotal() and OrderSelect() are fundamental for any MQL4 developer. But if your goal is simply to check and manage your positions efficiently, the solution doesn't have to be another complex script—it can be a smarter way to interact with the terminal itself.

MT4/MT5 Tray Assistant

Silent tracking, one-click close - check quotes and manage positions right from the tray.

Download Camovia Tray

Frequently Asked Questions

How do I restore the MT5/MT4 window after hiding it?

Choose "Show MT5/MT4" from the system tray menu and the window returns to its previous position. You can also hover the tray to check quotes and manage positions without opening the terminal.

Can it replace MT5/MT4 for trading?

No - Camovia Tray is a local shortcut tool. You can close positions right from the popup; all trading operations (opening, closing, etc.) are submitted by your local MT5/MT4 terminal to your own broker account. The app does not hold your funds or provide investment advice.

Can the tray icon be disguised?

Yes. The tray icon can disguise itself as a cloud drive or a common system tool, so market watching stays low-key.

What is the tray lock feature?

Lock the tray function instantly at key moments to protect your privacy and prevent private information from leaking.

Popular Symbols Trading Hours

Open/close times, weekend hours & live market status: