Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Experts

Basket Close Manager - close a group of trades at a money or percent target, loss limit, trailing lock or set time - expert for MetaTrader 5

Parinya Aonpradit
Parinya Aonpradit
Hi, I'm Parinya, a solo MQL5 developer specializing in MetaTrader 5 Expert Advisors, custom indicators and utility scripts.
Views:
753
Rating:
(2)
Published:
Updated:
MQL5 Freelance Need a robot or indicator based on this code? Order it on Freelance Go to Freelance

Many traders and EAs open several positions at once: grids, multi-symbol baskets, manual scaling in. What counts is the result of the whole group, not of each trade. Basket Close Manager is a small utility EA that closes the group as one.

Basket Close Manager panel on the chart

How it works

Attach it to any one chart. It sums profit + swap of every matching position on every tick and once per second, and closes all of them when an exit is hit.

  • Basket: whole account or the chart symbol only, any magic number, manual trades only (magic 0) or one magic.
  • Optional commission per lot, so the targets are measured after costs.
  • Pending orders of the basket can be deleted at the same time.

Exits (each can be switched off)

  • Take profit in account currency and/or % of balance.
  • Loss limit in account currency and/or % of balance.
  • Trailing lock: after the basket reaches InpTrailStart, close it if it gives back InpTrailGive from its peak.
  • Close every day at HHMM and/or on Friday at HHMM (server time).

After a close

Keep watching new trades, pause until the next server day (any new matching trade is closed at once), or remove the EA from the chart.

Safe closing

  • If a basket symbol is in a closed session, the close waits until the market reopens instead of sending orders that fail.
  • Each position gets several close attempts; the panel shows "CLOSING" until the basket is flat.
  • The basket peak is kept in a terminal global variable, so restarting the terminal or VPS does not reset the trailing lock.
  • A push notification can be sent to the MT5 mobile app on every close.

Limits: the check runs on ticks and every second, so a fast move or a gap can pass a target before the close is filled. Keep that in mind when setting tight levels.

Inputs

Input Default Meaning
InpScope Whole account Whole account or chart symbol only
InpMagic -1 -1 = any, 0 = manual trades only, other = that magic
InpCommPerLot 0 Round-turn commission per lot added to the P/L
InpDelPending false Also delete matching pending orders on a close
InpTPMoney / InpTPPct 0 Take profit in money / % of balance (0 = off)
InpSLMoney / InpSLPct 0 Loss limit in money / % of balance, positive numbers (0 = off)
InpTrailStart / InpTrailGive 0 Trailing lock: start level and give-back, money (0 = off)
InpDailyHM / InpFridayHM 0 Time exits, server HHMM (0 = off)
InpAfter Keep watching Keep watching / pause until next day / remove EA
InpDeviation 50 Max slippage when closing (points)
InpRetries 3 Close attempts per position
InpPanel / InpPush true / false Chart panel / mobile push
InpDemoTrades false Strategy Tester only: random trades to watch the exits work

Try it in the Strategy Tester

Set InpDemoTrades = true, choose some exits (for example InpTPMoney = 30, InpSLMoney = 40, InpTrailStart = 15, InpTrailGive = 8) and run it in visual mode. The EA opens random trades so you can watch the basket being closed. In normal use it never opens a trade.

Tested in the MT5 Strategy Tester (XAUUSD H1, Sep–Oct 2026, demo trades): money and % targets, loss limits, trailing lock, daily and Friday time exits and the pause-until-next-day mode all closed the basket, with no failed close orders.

G7 Account Inspector Pro - Institutional Prop Firm Risk Auditor and Performance HUD G7 Account Inspector Pro - Institutional Prop Firm Risk Auditor and Performance HUD

Institutional on-chart account inspector, behavioral signature analyzer, EA vs manual breakdown, and prop firm drawdown auditor with 1-click HUD.

G7 FVG OB Confluence AutoTrader and Institutional SMC Dashboard G7 FVG OB Confluence AutoTrader and Institutional SMC Dashboard

Smart Money Concepts (SMC) Expert Advisor and on-chart analysis utility for MetaTrader 5 that detects overlapping M15 Order Blocks and Fair Value Gaps with real-time confluence scoring and daily drawdown protection.

Session Ranges + ADR Panel Session Ranges + ADR Panel

Asian, London and New York session boxes with high/low range, plus a clean panel showing ADR, today's % of ADR, spread and time to candle close.

MTF Trend Matrix MTF Trend Matrix

A compact dashboard that shows the EMA trend direction and ADX strength of several symbols across several timeframes at once.