Loading…

Order Modify No Change Demo

Almost every trailing-stop expert eventually logs an "OrderModify failed, error 1" line that looks like a bug but isn't. Error 1 is ERR_NO_RESULT - the server's way of saying the request already matched the order, so it did nothing. A trailing loop that calls OrderModify() on every tick with whatever stop the trailing logic currently wants will ask for the same unchanged stop on most of those ticks, since price only moves enough to justify a new stop level occasionally. Every one of those redundant calls logs as a failure, drowning the log in noise that looks identical to a genuine broker rejection. This script reproduces the error live against a real, minimal test order: it calls OrderModify() with the order's own current stop loss, take profit and price, unchanged, and prints the exact GetLastError() result. It then shows the fix, which is not a retry or a try/catch - it is avoiding the redundant request in the first place. A guard function reads the order's current price, stop loss, take profit and expiration, compares each one to what is being requested within half a point of tolerance, and skips the OrderModify() call entirely when nothing would change. The same guard then executes a genuine trail by a few points, to show it still calls through normally the moment there is a real change to make. The half-point comparison tolerance matters on its own: comparing doubles with == is the same trap this catalogue documents separately in FloatComparisonTrap - a price rebuilt through arithmetic can differ from the order's stored value by a fraction of a point even when both represent the same broker-rounded price, so an exact == guard would occasionally fail to recognise "no real change" and call OrderModify() anyway. Notes and limitations - Sends one real market order at the symbol's minimum lot on a demo account and closes it automatically at the end of the run. It still carries real (if minimal) execution risk on the connected account, which is why the demo-account check and confirmation prompt exist. - The guard function (GuardedOrderModify) is reimplemented directly in this file rather than reused from the catalogue's existing SafeOrderModify library, per house style: no project may #include another project's source. The comparison-and-skip logic here is deliberately small and self-contained, not a copy of that library's fuller retry/error-classification machinery. - Whether the very first OrderModify() call in the demo returns false with error 1, or returns true with no visible change, is broker- dependent - both outcomes are printed and explained, since some servers echo success on a no-op request instead of ERR_NO_RESULT. Either way, nothing about the order actually changes.

Script · MT5 · v1.0 · Free

About Order Modify No Change Demo

Order Modify No Change Demo is an expert advisor (trading robot) for MetaTrader 5. It moves the stop loss behind price (trailing stop / break-even) and has a news filter. It has 4 settings, such as Require demo account, Confirm first and Stop loss points. MQL source code included.

Files in the download: OrderModifyNoChangeDemo.ex5, OrderModifyNoChangeDemo.mq5, OrderModifyNoChangeDemo.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Require demo accounttrueRefuse to run unless the connected account is a demo
Confirm firsttrueAsk for confirmation before sending the test order
Stop loss points300Points away from entry for the test order's stop loss
Trail step points50Points the guarded re-trail moves the stop by, to show a real change

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: Trailing Stop & Break-even · News Trading · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria