Loading…

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

SettingDefaultWhat it does
Magic number20260706Magic number to match, 0 = match every magic number
Scope all symbolsfalsetrue = watch every symbol on the account, false = this chart's symbol only
Target modeTARGET_MONEYHow the target below is measured
Target money20.0Target combined floating profit, account currency (used when mode = Money)
Target percent2.0Target combined floating profit, % of balance (used when mode = Percent)
Also delete pendingstrueDelete matching pending orders too when the target fires
Slippage pips5Slippage tolerance on the closing trades
Max retries5Attempts per order action before giving up
Retry wait ms500Pause between attempts, milliseconds
Scan interval sec15Seconds 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: Risk & Lot Size · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria