Rebuild Position As Exit Ladder
A single flat target on a large position is an all-or-nothing decision: the whole thing bags its profit at one price or it does not. Scaling out manually after the fact means clicking a partial close at exactly the right moment, which most traders miss. This script turns one ticket into a ladder of several, each free to hit its own target independently, in one run. It works by closing the original ticket completely and reopening its size as InpRungs new market orders, spaced from InpTargetStartPips and stepping out by InpTargetStepPips per further rung. That is the whole trick, and it is also the whole cost: closing and reopening the same net exposure pays the spread twice instead of once. The script does not pretend this is free. It reads the live spread at the moment it runs and prints an estimate of the round trip cost in account currency, so the trade-off against a plain partial close is visible rather than assumed. The lot split respects the symbol's lot step exactly, folding any rounding remainder into the last rung so the sum matches the original size to the lot step - not an approximation that leaves a sliver of size unaccounted for. If the position is too small to split at the symbol's minimum lot, the script refuses rather than silently opening fewer rungs than asked. Each candidate target and the optional carried-over stop loss are checked against the broker's stop and freeze distance before being sent; a level that would be rejected is dropped for that one rung rather than aborting the whole rebuild. The most important thing this script gets right is what happens when a rung fails to reopen after the original ticket is already closed. That is a real gap in market exposure, not a rounding error, and it is reported as loudly as the summary alert allows rather than folded quietly into a lower total. Notes and limitations - The original ticket is closed before any rung is reopened. Between those two moments there is genuinely no position open - this is not an atomic operation and cannot be made one on this platform. - The spread cost reported is an estimate at the moment the script runs, not a guaranteed figure; slippage on the actual fills can move it either way. - Commission, where the broker charges one, is not included in the cost estimate - it is not knowable from the terminal before the trade is sent. - Every rung gets the same stop-loss price, not a scaled one. A rung's risk in money terms is smaller than the original only because its lot size is smaller, not because the stop distance changed. - Works on market positions only. Pending orders are rejected outright.
Script · MT5 · v1.0 · Free
About Rebuild Position As Exit Ladder
Rebuild Position As Exit Ladder is an expert advisor (trading robot) for MetaTrader 5. It opens a grid of orders at fixed price steps. It has 9 settings, such as Ticket, Rungs and Target start pips. MQL source code included.
Files in the download: RebuildPositionAsLadder.ex5, RebuildPositionAsLadder.mq5, RebuildPositionAsLadder.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 |
|---|---|---|
| Ticket | 0 | Position ticket to rebuild |
| Rungs | 3 | Number of new tickets to split into |
| Target start pips | 20.0 | Distance from entry to the first rung's target, pips |
| Target step pips | 20.0 | Extra distance added per further rung, pips |
| Keep stop loss | true | Give every new ticket the original stop-loss price |
| Magic number | 20200 | Magic number tagged on the new tickets |
| Slippage points | 30 | Maximum acceptable slippage, points |
| Max retries | 5 | Attempts per trade action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 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 · MT5 Script · MQL5 Source Code