Camovia Tray™

Blog · Knowledge

How to Modify Orders with MQL4 OrderModify Without Breaking Your Strategy

Camovia Tray Team · 2026-09-14

You've just opened your MetaTrader 4 terminal, and there it is—a position that's moving in your favor. You know you should adjust the stop loss to lock in some profit, but modifying the order feels like a gamble. Will the function work? Will it throw an error? And why does it seem so finicky sometimes?

If you've ever stared at an EA that refused to trail stops properly or got error 130 when trying to adjust a simple stop loss, you're not alone. The OrderModify() function in MQL4 is one of the most powerful yet misunderstood tools in a trader's arsenal. Let's break down how to use it correctly, what the common pitfalls are, and—here's the twist—how managing orders from the system tray can actually make your life easier.

Understanding OrderModify: The Basics

At its core, OrderModify() does exactly what it says: it changes the parameters of an existing order. The official MQL4 documentation defines it as:

bool OrderModify(
   int ticket,        // order ticket
   double price,      // new open price (pending orders only)
   double stoploss,   // new StopLoss level
   double takeprofit, // new TakeProfit level
   datetime expiration, // pending order expiration
   color arrow_color   // color for modification arrows
);

Simple enough, right? But here's where traders get into trouble.

The Silent Killer: Passing Zero Instead of Original Values

One of the most common mistakes is assuming you can pass 0 for parameters you don't want to change. You can't.

Let's say you're implementing a trailing stop and only want to update the stop loss. A rookie EA might look like this:

OrderModify(ticket, price, new_sl, 0, 0, Blue); // WRONG

This zeros out your take profit and expiration time. The order will lose its take profit entirely. As one MQL5 forum contributor noted, "when modifying an order, those parameters that remain unchanged should be passed in their original form, and not zeroed out."

The correct approach:

OrderModify(ticket, OrderOpenPrice(), new_sl, OrderTakeProfit(), OrderExpiration(), Blue);

Always retrieve the existing values with OrderSelect() first, then pass them through unchanged.

The Selection Trap: You Must Select Before You Modify

Another pitfall: trying to modify an order without selecting it first. MQL4 requires explicit order selection before any operation. Even if you think you "know" the ticket number, you still need to call:

OrderSelect(ticket, SELECT_BY_TICKET);

This is non-negotiable. And if you're managing multiple orders, don't rely on a single variable storing the ticket—it can be overwritten. Use distinct variables for buy and sell order tickets.

The Distance Constraints: Why Error 130 Haunts You

Error 130 (ERR_INVALID_STOPS) is the bane of every MQL4 developer's existence. It usually means one of two things:

  1. Your stop loss is too close to the current price. Each broker sets a minimum stop level (MODE_STOPLEVEL). If your SL is within this distance, the order modification will fail.
  1. You're in a freeze zone. Some brokers "freeze" pending orders or stops when price is within a certain range of your entry. During this freeze, modifications are blocked.

The recommended practice? Before calling OrderModify(), check if the new values actually differ from the current ones:

if (new_sl != OrderStopLoss() || new_tp != OrderTakeProfit())
{
   // Only then call OrderModify()
}

This isn't just defensive coding—it prevents unnecessary modification attempts that could trigger errors.

Why This Matters for Real-World Trading

Here's the thing: you don't always want to be glued to your screen watching price action. You might have a trailing stop logic in an EA, or maybe you just want to adjust a stop loss manually while stepping away from your desk.

But what if you're not in front of the terminal? Or what if you're in a meeting, but you still need to check if your trailing stop triggered correctly?

This is where a tool like Camovia Tray comes in. Instead of constantly switching back to MT4 to check position details or modify orders, you can keep an eye on your open positions right from the Windows system tray. Hover over the tray icon, and you'll see real-time data: current profit, open price, and stop loss levels—all without pulling up the full MT4 interface.[citation:camovia]

When you need to modify a stop loss or take profit, the tray doesn't do the modification for you—but it gives you the visibility to know when you need to act. For coders testing EA modifications, it's a convenient way to monitor whether OrderModify() calls are behaving as expected. You can quickly see if a trailing stop is stuck or if a modification error has left a position unprotected.

A Practical Example: Trailing Stop Logic

Let's put this all together with a realistic trailing stop implementation:

void TrailStop(int ticket, int trailPoints)
{
   if (!OrderSelect(ticket, SELECT_BY_TICKET)) return;
   
   double newSL = 0;
   if (OrderType() == OP_BUY)
   {
      newSL = NormalizeDouble(Bid - trailPoints * Point, Digits);
      if (newSL > OrderStopLoss())
      {
         // Only modify if the new SL is higher (tighter)
         if (OrderModify(ticket, OrderOpenPrice(), newSL, 
                         OrderTakeProfit(), OrderExpiration(), Blue))
            Print("Stop loss trailed successfully");
         else
            Print("Error trailing stop: ", GetLastError());
      }
   }
}

Notice we're passing OrderOpenPrice(), OrderTakeProfit(), and OrderExpiration() unchanged. We're only touching the stop loss. And we check that the new SL actually improves the position before attempting the modification.

The Bottom Line

OrderModify() is a straightforward function with a few sharp edges. Select the order first. Never zero out unchanged parameters. Respect your broker's distance rules. And always check if you actually need to modify before calling the function.

If you're a developer building trading tools or an EA, testing modifications becomes much easier when you can monitor positions without constantly switching windows. With Camovia Tray, your MT4 positions are always a hover away—so you can focus on writing better code, not on babysitting the terminal.

MT4/MT5 Tray Assistant

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

Download Camovia Tray

Frequently Asked Questions

What is Camovia Tray?

A tray assistant for MT4/MT5 - silent tracking, one-click close: hover the system tray to check the latest quotes and manage open positions (click an order to close it), hide the MT5/MT4 main window in one click, and keep quote and position data entirely on your computer.

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).

Popular Symbols Trading Hours

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