Basket Stop Loss Manager
This is a safety net, not a guarantee. It checks on a timer (InpScanIntervalSec), not on every tick, so a gap or a fast spike between checks can breach the cap before this EA reacts, and the broker can still slip or requote the close once it tries. Do not rely on this as the only protection on a large account, and do not treat the cap as a promise the account can never lose more than that amount. Individual tickets may or may not carry their own stop-loss - this EA does not touch those, and does not require them. It watches the GROUP total, matched by InpMagicNumber (or every magic number, with 0) and optionally scoped to every symbol on the account rather than just the chart's own symbol, and closes everything in that scope together the instant the combined floating loss, not any single ticket, breaches the configured cap. The cap is either a fixed amount of account currency or a percentage of current balance, so it does not need recalculating by hand as the account balance changes. Pending orders in the same scope are optionally deleted at the same time the basket flattens, since a pending order left behind after an emergency close is rarely still wanted. Notes and limitations - This is an emergency close, not a graceful exit - it uses market orders and accepts InpSlippagePips of slippage to get out promptly. - Checks run on a timer, not on every tick, so the realised loss can be worse than the configured cap if price gaps through it between checks. - If the matching scope contains only pending orders and no open market position, there is no floating result to measure and nothing is closed regardless of the cap. - Setting InpMagicNumber to 0 includes positions opened manually or by any other EA on the account - confirm that is intended before running it live, since it means one runaway strategy can trigger a close of everything, including unrelated positions. - 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 · MT4 · v1.0 · Free
About Basket Stop Loss Manager
Basket Stop Loss Manager is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 10 settings, such as Magic number, Scope all symbols and Cap mode. MQL source code included.
Files in the download: BasketStopLoss.ex4, BasketStopLoss.mq4, BasketStopLoss.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Magic number | 20260707 | 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 |
| Cap mode | CAP_PERCENT | How the loss cap below is measured |
| Cap money | 50.0 | Loss cap, account currency (used when mode = Money) |
| Cap percent | 5.0 | Loss cap, % of balance (used when mode = Percent) |
| Also delete pendings | true | Delete matching pending orders too when the cap 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 4 open File → Open Data Folder, then go to MQL4 → Scripts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Alerts · MT4 Expert Advisor · MQL4 Source Code