Loading…

Multi Target Exit Manager

A single take-profit forces an all-or-nothing exit: either the whole position rides to one level, or none of it does. This EA manages up to three staged exits on one position instead - a first partial close, a second, and a full close of whatever is left - which is a common way to bank some profit early while leaving room for the trade to keep working. The percentages for the first two targets are taken against the ORIGINAL volume the position opened with, not against whatever remains at that moment. A 33% first target genuinely means a third of the starting size; computing it against the already-reduced remainder after an earlier partial would silently shrink every later target below what the trader configured. The EA captures the starting volume the first time it sees a given ticket and keeps using that figure for the life of the position. The third target always closes the entire remainder, so the position is guaranteed to end at exactly zero rather than leaving an unmanaged dust lot that neither target logic nor the trader remembers to close. An optional stage moves the stop to breakeven plus a small buffer the moment the first target fills, locking in a floor before the position is left to work toward the remaining targets. This EA never opens a position. It manages whatever is already open under InpMagicNumber on the chart symbol - attach it after entering by hand, or alongside another EA that opens trades under the same magic number. Notes and limitations - Tracks one position per InpMagicNumber per chart symbol. A new ticket under the same magic resets all target state and captures a fresh starting volume. - Target 1 and target 2 percentages must together leave something under 100% for target 3 to close - InpOnInit refuses to start otherwise. - Broker lot-step rounding means the actual closed volume at each stage can differ slightly from the exact percentage requested; the shortfall or excess carries forward into what target 3 closes. - Does not touch take profit - if the order already has one set, it stays in place unless the broker closes it first.

Expert advisor · MT4 · v1.0 · Free

About Multi Target Exit Manager

Multi Target Exit Manager is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 11 settings, such as Magic number, Target1 pips and Target1 percent. MQL source code included.

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

Settings

SettingDefaultWhat it does
Magic number20260305Magic number of the position to manage
Target1 pips20Profit distance for the first partial, in pips
Target1 percent33.0Percent of the ORIGINAL volume closed at target 1
Target2 pips40Profit distance for the second partial, in pips
Target2 percent33.0Percent of the ORIGINAL volume closed at target 2
Target3 pips60Profit distance for the final close, in pips
Move sl to breakeven after t1trueMove the stop to breakeven once target 1 fills
Breakeven buffer pips2.0Pips beyond entry kept as the breakeven floor
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria