Loading…

Snap Pendings To Round Numbers

A pending order placed by dragging the crosshair onto a chart rarely lands on a clean number - 1.09517 instead of 1.09500, or 1948.3 instead of 1950. Round numbers matter to a lot of price action around them (order clusters, psychological levels), so a level that was meant to sit on 1.09500 but actually sits 17 points off it is a small but real difference between the plan and the order sitting on the server. This script rounds every matching pending's entry price to the nearest level on a grid spaced InpRoundStepPips apart, then moves the stop loss and take profit by the identical price delta - the distance from entry to stop, and from entry to target, is preserved exactly. It never widens or tightens a level; it only relocates the whole set together. A safety limit (InpMaxDriftPips) refuses to snap anything whose nearest round level is further away than expected. That catches the case where an order was never meant to sit near a round number at all (a level derived from a swing high/low, not a round-number strategy) - snapping it several pips just because the maths says so would be actively wrong, so the script leaves it alone and reports it as skipped instead. The script always prints a full plan first. Nothing is sent to the server unless InpApply is set to true. Notes and limitations - Only touches pending orders (buy/sell limit and stop). Open market positions have no "entry price" left to move and are ignored entirely. - The round-number grid is anchored at price zero, so it is the same XX.X000 / XX.X050-style set of levels regardless of where the symbol's price currently sits - it does not adapt to a custom reference price. - A modification can still be rejected by the broker if the new entry, stop or target falls inside the symbol's stop level or freeze level; such a rejection is reported per ticket, not retried indefinitely. - Snapping a stop or target by the same delta as the entry can occasionally push one of them slightly closer to (or further from) the current market price than before, purely as a side effect of the shift - it is not re-optimised independently. - Running it repeatedly on a basket that is already on-grid does nothing further; those orders are reported as "already on grid" and skipped.

Script · MT4 · v1.0 · Free

About Snap Pendings To Round Numbers

Snap Pendings To Round Numbers is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Round step pips, Max drift pips and Current symbol only. MQL source code included.

Files in the download: SnapPendingsToRound.mq4, SnapPendingsToRound.txt.

Settings

SettingDefaultWhat it does
Round step pips50.0Grid spacing to snap to, in pips (e.g. 50 = snap to XX.X050/XX.X000 levels)
Max drift pips8.0Skip an order if the nearest round level is farther than this many pips away
Current symbol onlyfalseRestrict to this chart's symbol
Magic filter-1Only touch orders with this magic (-1 = every magic)
ApplyfalseMust be true to actually send order modifications
Max retries3Attempts per order before giving up
Retry wait ms400Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Scripts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Grid · Price Action · Pending Orders · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria