Loading…

Slave Kill Chain Guard

A copier that keeps faithfully mirroring a master in the middle of a genuine loss streak, or a master that has silently crashed, is doing exactly what it was built to do - which is precisely the danger. This EA runs on the master's chart in MASTER role to publish three simple health metrics on a timer: a heartbeat timestamp, the number of CONSECUTIVE losing closed trades (scanning backward from the most recent, stopping at the first win or breakeven), and the account's drawdown from its own session peak equity. Running on the slave's chart in SLAVE role, it watches those published metrics and trips the instant any one of three conditions is met: the heartbeat has gone stale beyond InpHeartbeatGraceSec, the consecutive-loss count reaches InpLossBurstTrigger, or the drawdown reaches InpMaxDrawdownTrigger. Once tripped, it does not just close positions once - it re-checks and re-flattens on every poll for as long as the trip condition (or the tripped state itself) persists, so a different EA on the same slave account reopening a position mid-incident gets flattened again rather than being allowed to quietly rebuild exposure. By default the trip requires a human to restart the EA to clear it (InpAutoRecover = false), on the reasoning that a loss burst or drawdown breach is a genuine event worth a second look before trading resumes; setting InpAutoRecover = true instead clears the trip automatically once the master's metrics have been continuously healthy for InpRecoverySustainSec. Notes and limitations - The consecutive-loss and drawdown metrics describe the MASTER's own account, not the slave's - this project answers "should the slave stop following this master", not "is the slave itself losing". - Drawdown is measured from this session's own peak equity (persisted via a tagged global variable so it survives an EA reload, but never shared between terminals) - restarting the terminal resets the peak to current equity at that moment, which understates drawdown measured from before the restart. This is a known limitation of not persisting the peak to a file. - With InpAutoRecover = false (the default), the guard stays tripped - and keeps re-flattening - until the trader manually removes and re-attaches the EA. There is no separate "clear" input by design; a loss-burst or drawdown trip is meant to require a deliberate decision to resume, not a config toggle flipped in the heat of the moment. - Only reacts to what the master PUBLISHES - if the master-side EA itself is not running, this looks identical to a genuine heartbeat failure and trips accordingly, which is the intended behaviour. - Reimplements its own order-flatten and heartbeat-file helpers inline rather than including another project's file, per this catalogue's no-cross-project-include rule.

Expert advisor · MT5 · v1.0 · Free

About Slave Kill Chain Guard

Slave Kill Chain Guard is an expert advisor (trading robot) for MetaTrader 5. It has 13 settings, such as Role, Instance tag and Master instance tag. MQL source code included.

Files in the download: SlaveKillChainGuard.ex5, SlaveKillChainGuard.mq5, SlaveKillChainGuard.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
RoleROLE_SLAVEWhich side of the copy relationship this chart plays
Instance tagShared filename tag for THIS master; blank = auto from account number (MASTER role only)
Master instance tagThe MASTER's tag to watch (SLAVE role only)
Heartbeat interval sec15MASTER: how often it rewrites its metrics file
Heartbeat grace sec60SLAVE: master heartbeat older than this trips the guard
Loss scan cap50MASTER: how many recent closed deals it scans for a consecutive-loss streak
Loss burst trigger4SLAVE: consecutive master losses at or above this trips the guard
Max drawdown trigger15.0SLAVE: master drawdown-from-peak percent at or above this trips the guard
Magic filter0SLAVE: 0 = flatten every own position; otherwise only this magic number
Slippage points50SLAVE: slippage tolerance for the emergency flatten (wide - getting out matters more than the fill)
Auto recoverfalseSLAVE: automatically clear the trip once the master is healthy again for InpRecoverySustainSec
Recovery sustain sec900SLAVE: master metrics must stay healthy continuously this long before an auto-recover clears the tri
Poll interval sec5Seconds between polls of the master's metrics / rescans of own positions

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: Trade Copier · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria