Respace Grid By ATR
A grid built with a fixed pip spacing during a quiet session becomes wrong the moment volatility changes. Too tight during an expansion and every rung fills within minutes of each other, loading the account far faster than intended; too wide during a quiet spell and the grid never engages at all. This script re-reads the grid's own structure and rebuilds it at a spacing proportional to the current ATR, so the same grid logic keeps making sense as the market's behaviour changes. Each existing pending order on the chart's symbol is read, ranked by its distance from the current price on its own side of the market (nearest first), then deleted and re-sent at rank multiplied by the new ATR-based spacing. Lot size and order type are carried over unchanged. Stop loss and take profit are preserved as a distance from that rung's OWN entry price, not as the original absolute price - a rung's stop stays the same number of points behind its new entry instead of landing at a stale price left over from the old spacing. Because this rebuilds the grid by deleting and re-sending, a rung that fails to resend after being deleted is a real gap in the grid, not a cosmetic issue - the script raises an Alert() for this case specifically, and reports every outcome by rank so a partial rebuild is never mistaken for a complete one. Notes and limitations - This is a one-shot rebuild, not a running EA. Run it again whenever the grid should be respaced to the current ATR. - Only pending limit and stop orders on the chart's own symbol are read. Open positions and other symbols are not touched. - The rebuild deletes each rung before re-sending it. If the re-send fails after the delete succeeded (network hiccup, requote exhausted retries), that rung is genuinely gone from the book, not merely unmodified - the summary and an Alert() call this out explicitly. - Rank is computed fresh from each rung's current distance from price at the moment the script runs, not from any stored "grid level" concept - a grid that has already partially filled will only respace whatever pending rungs remain. - If the computed ATR-based spacing is inside the broker's stop/freeze minimum for the symbol, the script refuses the whole rebuild rather than sending an invalid grid.
Script · MT4 · v1.0 · Free
About Respace Grid By ATR
Respace Grid By ATR is an expert advisor (trading robot) for MetaTrader 4 based on ATR. It increases the lot size after a losing trade (martingale), opens a grid of orders at fixed price steps and places pending buy/sell stop or limit orders. It has 9 settings, such as Magic filter, Atr period and Atr timeframe. MQL source code included.
It also has a news filter.
Files in the download: RespaceGridByAtr.mq4, RespaceGridByAtr.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic filter | -1 | Only rebuild orders with this magic (-1 = ignore magic) |
| Atr period | 14 | ATR period used to compute spacing |
| Atr timeframe | PERIOD_H1 | Timeframe the ATR is read from |
| Atr multiplier | 1.0 | New spacing = ATR value * this multiplier |
| Min spacing pips | 5.0 | Floor on spacing, pips (guards against a near-zero ATR) |
| Slippage pips | 3 | Slippage tolerance on the re-send, pips |
| Max retries | 5 | Attempts per order before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Confirm first | true | Ask for confirmation before touching anything |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: Grid · ATR · Trading Sessions · Risk & Lot Size · Martingale · Pending Orders · News Trading · MT4 Script · MQL4 Source Code