Loading…

Structure Target Partial Closer

This is a trade manager, not a signal generator - it opens no positions, only manages ones already open. Staged partial-close systems are usually built around fixed R-multiples (1R, 2R, 3R), a convenient number that means nothing to the market itself - a 2R level can land in the middle of an obvious prior high where price often stalls anyway, wasting the stage, or well past it, giving back gains the market already offered a natural point to lock in. This EA instead builds its partial-close targets directly from confirmed swing points using the same fractal confirmation test as the other trailing-stop tools in this catalogue: a pivot bar only counts once InpSwingStrength bars have closed on each side of it proving it held. Each newly confirmed swing high (above price) is queued as the next long-side target in the order it confirms; each newly confirmed swing low is queued the same way for shorts. As price clears each queued target in turn, the position takes a partial close of InpPartialPercent of its ORIGINAL size, up to InpMaxPartials stages - so a strong trend that clears several structural levels in a row takes several partials, one per level, exactly where the market has already proven it can pause. Per-position progress (which stage has been taken) is tracked in memory only, keyed by order ticket, and is lost if the EA is removed and reattached or the terminal restarts - stated plainly rather than implied to be persistent. Notes and limitations - This EA never opens a position, only partially closes ones already open, and never fully closes one - the final scrap of a position is deliberately left for the trader or a separate exit manager. - If a partial would leave less than the broker's minimum lot size behind, the slice is reduced to leave exactly the minimum rather than being skipped outright, and if that is still not possible the stage is skipped for that check. - Per-ticket stage progress lives in memory only and does not survive an EA restart - a position already partway through its staged exits when the EA reattaches starts its structural targets over from whatever swing points confirm after that point. - Target queues fill only from swing points that confirm AFTER a position is being watched; a target that already existed before attach is not retroactively queued.

Expert advisor · MT5 · v1.0 · Free

About Structure Target Partial Closer

Structure Target Partial Closer is an expert advisor (trading robot) for MetaTrader 5. It has 8 settings, such as Swing strength, Max targets and Max partials. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Swing strength5Bars required on EACH side of a pivot to confirm it as a swing point
Max targets60Maximum number of confirmed swing points remembered per side
Max partials3Maximum number of partial-close stages taken per position
Partial percent25.0Percent of the ORIGINAL position size closed at each stage
Magic number-1Magic number to manage; -1 manages every position on this symbol
Max retries5Order action attempts before giving up
Retry wait ms500Pause between retry attempts, milliseconds
Slippage pips3Slippage tolerance for the partial-close, in pips

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: Buy/Sell Arrows · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria