Loading…

Pending Grid Builder

Placing ten pendings by hand means ten chances to fat-finger a price, and the terminal's order window will happily let you. This script builds the whole ladder in one pass: choose the flavour (buy limits below the market, sell limits above, buy stops above, sell stops below), a start price, a spacing, a rung count and a volume, and every rung is computed, validated and placed with an optional stop loss and take profit hung off its own entry price. The risk warning comes before the feature list, because a grid deserves one: a ladder of pendings is AGGREGATE exposure. Every rung that fills adds to the position, and a fully filled grid without stops has open-ended downside. The confirmation dialog does that arithmetic for you - total lots, the approximate margin to carry a full fill, and the combined loss if every rung fills and every stop is hit, in account currency, computed from tick value and tick size so it is correct on JPY crosses, gold and index CFDs, not just on EURUSD. If you run it without a stop loss, the dialog says in plain words that the downside is open-ended. Prices are snapped to the tick-size grid - not merely rounded to digits, which index CFDs with a 0.25 tick reject - and always on the side that keeps the rung outside the broker's stop and freeze levels. An explicit start price on the wrong side of the market, or inside the minimum distance, is refused with the nearest legal price printed rather than silently moved: a level you chose should never be quietly re-chosen for you. In auto mode (start price 0) the first rung goes one spacing from the market, pushed out to the legal minimum if the spacing is tighter. A rung that fails permanently does not abort the run - a grid missing one rung is still a grid - but the journal names every uncovered level and the summary counts them, so nothing fails in silence. Notes and limitations - This script places orders once and exits. It does not replace filled rungs, trail anything, or close the basket - it is a builder, not a grid robot. - Pending orders reserve no margin. A grid that fits today can be rejected rung by rung at trigger time if the account cannot carry the fills. - The worst-case loss figure assumes every rung fills and every stop is hit with no slippage; a gap through the ladder can exceed it. - On a netting MT5 account the per-rung stops overwrite each other as rungs fill; manage the merged position's stop yourself. - Tick value is read from the broker; on an unsynchronised symbol it can be zero, in which case the money figure is omitted rather than invented. - Use Delete All Pending Orders (or your platform's order window) to remove a half-built or stale ladder; this script only builds.

Script · MT4 · v1.0 · Free

About Pending Grid Builder

Pending Grid Builder is an expert advisor (trading robot) for MetaTrader 4. It opens a grid of orders at fixed price steps and places pending buy/sell stop or limit orders. It has 12 settings, such as Grid kind, Order count and Lots per order. MQL source code included.

Files in the download: PendingGridBuilder.ex4, PendingGridBuilder.mq4, PendingGridBuilder.txt.

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

Settings

SettingDefaultWhat it does
Grid kindGRID_BUY_LIMITLadder type
Order count5Number of rungs
Lots per order0.01Lots per rung
Start price0.0First rung price (0 = auto)
Spacing pips15.0Spacing between rungs, pips
Stop loss pips0.0Stop loss per rung, pips (0 = none)
Take profit pips0.0Take profit per rung, pips (0 = none)
ExpiryD'1970.01.01'Expiry (leave 1970 = no expiry)
Magic0Magic number
Max retries5Attempts per rung before giving up
Retry wait ms500Pause between attempts, ms
Confirm firsttrueAsk for confirmation first

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 → Experts.
  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 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: Grid · Volume · Pending Orders · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria