Loading…

Kill Switch Listener

A kill switch is only as useful as the thing that actually acts on it. Tripping a flag by hand or from a Script does nothing on its own unless something is watching for it and reacting - this EA is that watcher. It polls the KILLSWITCH_ACTIVE GlobalVariable on a timer. The instant it sees the switch trip, it collects every order ticket in its configured scope - optionally filtered by magic number and/or symbol - closes every market order and deletes every pending order in that scope, and logs and alerts the result. With InpContinuousEnforcement left on (the default) it does not stop there: it keeps sweeping on every poll for as long as the switch stays tripped, so an order opened by a straggler EA mid-outage gets closed too, not just whatever was open at the instant of the trip. The GlobalVariable names it watches (KILLSWITCH_ACTIVE, KILLSWITCH_REASON_CODE, KILLSWITCH_TRIPPED_AT) are deliberately identical to the ones this catalogue's KillSwitchProtocol Library defines, so any tool that trips the switch via that Library's KillSwitchTrip() function is understood here without any extra wiring. This EA does not #include that Library, though - every CodeBase submission must stand alone, so the same three names are redeclared locally and kept in sync by hand rather than shared as source. Notes and limitations - Requires AutoTrading to be enabled to act; if the switch trips while AutoTrading is off, it alerts loudly and logs the situation but cannot close or delete anything until AutoTrading is turned back on. - Reads the KILLSWITCH_ACTIVE convention only - it does not itself provide a way to trip the switch. Pair it with a Script, panel, or this catalogue's KillSwitchProtocol Library on the trip side. - The GlobalVariable name mirroring is a manual convention, not a shared code dependency - if the KillSwitchProtocol Library's names ever change upstream, this file needs its own #define block updated separately. - On attach, it seeds its "was active" state from whatever the switch currently reads, so it will not re-flatten on startup if the switch was already tripped and already handled by an earlier run.

Expert advisor · MT5 · v1.0 · Free

About Kill Switch Listener

Kill Switch Listener is an expert advisor (trading robot) for MetaTrader 5. It has 7 settings, such as Magic filter, Symbol filter and Poll interval sec. MQL source code included.

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

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

Settings

SettingDefaultWhat it does
Magic filter-1Magic number to flatten; -1 flattens every magic on this account
Symbol filterSymbol to flatten; "" flattens every symbol
Poll interval sec2How often the GlobalVariable is checked
Continuous enforcementtrueKeep re-flattening new positions for as long as the switch stays tripped
Max retries5Attempts per position/order action before giving up
Retry wait ms500Pause between attempts, milliseconds
Dry runfalsetrue = alert only, never actually closes or deletes anything

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

Expert advisors (EA) for MT4 & MT5 · PolyMaria