Basket Take Profit Manager
A basket target is not the same as summing each ticket's own take-profit. Individual stops can be wide, mismatched, or missing entirely, and a strategy that opens several positions as one idea usually wants that idea closed as one unit once it has earned enough - not whenever the slowest or fastest single ticket happens to hit its own level. This EA measures the GROUP's combined floating result and closes every matching position the instant the group, not any one ticket, reaches the target. Scope is set two ways, and both apply together: InpMagicNumber narrows the group to one strategy's tag, or 0 to match every magic number, and InpScopeAllSymbols decides whether the group covers just the chart symbol or every symbol currently held on the account. The target itself is either a fixed amount of account currency or a percentage of current balance, so it does not need recalculating as position sizes change. Pending orders belonging to the same scope are optionally deleted at the same time the basket closes, since a pending order left behind after its companions have all closed is rarely still wanted. Notes and limitations - This EA only ever closes positions that are, in combination, in profit. A target set too close to zero will fire on ordinary market noise and exit a trade that had further to run - size the target to the strategy, not to the smallest visible fluctuation. - Checks run on a timer, not on every tick. A fast spike between checks can overshoot the target before the next scan closes the basket. - If the matching scope contains only pending orders and no open market position, there is no floating result to measure and the basket is left alone regardless of the target. - Setting InpMagicNumber to 0 includes positions opened manually or by any other EA on the account - confirm that is intended before running it live. - On an MQL5 netting account, InpMagicNumber selects or excludes an entire symbol's net position, not individual trades within it - see MQL4 VERSUS MQL5 DIFFERENCES above.
Expert advisor · MT5 · v1.0 · Free
About Basket Take Profit Manager
Basket Take Profit Manager is an expert advisor (trading robot) for MetaTrader 5. It can size trades from your balance and risk percent. It has 10 settings, such as Magic number, Scope all symbols and Target mode. MQL source code included.
Files in the download: BasketTakeProfit.ex5, BasketTakeProfit.mq5, BasketTakeProfit.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 |
|---|---|---|
| Magic number | 20260706 | Magic number to match, 0 = match every magic number |
| Scope all symbols | false | true = watch every symbol on the account, false = this chart's symbol only |
| Target mode | TARGET_MONEY | How the target below is measured |
| Target money | 20.0 | Target combined floating profit, account currency (used when mode = Money) |
| Target percent | 2.0 | Target combined floating profit, % of balance (used when mode = Percent) |
| Also delete pendings | true | Delete matching pending orders too when the target fires |
| Slippage pips | 5 | Slippage tolerance on the closing trades |
| Max retries | 5 | Attempts per order action before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Scan interval sec | 15 | Seconds between checks |
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: Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code