Loading…

Pyramid Position Builder

RISK WARNING: this EA opens additional live market positions automatically as price moves. Shrinking each add's size caps how fast exposure grows, but it does not make the position risk-free - a full group that gives back its trailing stop distance in one move can still lose more than the base position alone would have. It never adds to a position that has moved against it. Confirm every input on a demo account before running it live. This is classic pyramiding, and it is deliberately different from the flat-size ScaleInManager already in this catalogue. Each add's size is InpBaseLots * InpAddSizeMultiplier raised to the power of the add's stage number, so with the default multiplier of 0.5 the first add is half the base, the second is a quarter, and so on - every add smaller than the one before it. That is the opposite of a martingale, where later additions would grow instead of shrink, and it means a losing reversal after several adds gives back proportionally less than an equal-size scale-in would. Once at least one add exists, every open ticket in the group has its stop trailed behind the current price by InpTrailStopPips on every scan. The trail only ever tightens - a ticket's stop never moves further from price - so the group's worst-case outcome improves monotonically as the pyramid grows, without needing a separate breakeven step. The base position is not opened by this EA - it is adopted. Open a position by hand, or with any other EA, tagged with InpMagicNumber, and this manager picks it up on its next scan. Notes and limitations - If adds already exist under InpMagicNumber when this EA is first attached (for example after a terminal restart), they are counted toward InpMaxAdds and InpMaxTotalLots on adoption rather than ignored, so the caps still hold going forward. - The trailing stop is a simple fixed pip distance behind current Bid or Ask, not an ATR or structure-based trail, and it is only applied once the group has grown beyond the base position. - This EA only manages one base position per magic number per symbol at a time. Running two unrelated positions under the same magic number on the same symbol will confuse which one it treats as the base. - It never closes the group itself - only stop-losses, take-profits, and the trader's own decisions end the trade.

Expert advisor · MT5 · v1.0 · Free

About Pyramid Position Builder

Pyramid Position Builder is an expert advisor (trading robot) for MetaTrader 5. It increases the lot size after a losing trade (martingale), opens a grid of orders at fixed price steps and moves the stop loss behind price (trailing stop / break-even). It has 12 settings, such as Magic number, Pyramid step pips and Add size multiplier. MQL source code included.

It also has a news filter.

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

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

Settings

SettingDefaultWhat it does
Magic number20260705Magic number identifying the base position and every add
Pyramid step pips25Favourable move required since the last entry before the next add
Add size multiplier0.5Each add's lots = base lots * this ^ stage number (below 1.0 = shrinking adds)
Max adds4Maximum number of adds beyond the original base position
Max total lots0.20Hard cap on combined lots across base + every add
Stop loss pips40Stop-loss attached to each add, in pips from that add's own entry (0 = none)
Take profit pips0Take-profit attached to each add, in pips (0 = none)
Trail stop pips30Once the first add exists, trail every ticket's stop this many pips behind price (0 = no trailing)
Slippage pips5Slippage tolerance on market entries
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds
Scan interval sec10Seconds between checks

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 · Martingale · Grid · News Trading · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria