Alert Manager With Throttling
An alert call placed directly inside OnTick fires every time its condition evaluates true. "Spread is wide" or "margin level is low" can stay true for minutes at a time, which turns one real event into dozens of popups, push notifications or emails - the kind of noise that gets an EA's alerts muted entirely, including the ones that mattered. This header keys each distinct alert by a caller-chosen string and remembers when it last actually fired. Calling Notify() again for the same key inside its cooldown window is silently skipped and counted, not sent - no matter how many times OnTick calls it in between. A different key with its own cooldown is tracked independently, so "wide spread" and "low margin" throttle on their own schedules without interfering with each other. Time is passed through as an explicit optional parameter rather than always read from TimeLocal() internally. Real trading code leaves it at the default and gets the wall clock; a caller that wants to test the throttle logic itself - or this library's own demo - can supply a synthetic clock and advance it by hand, which makes the cooldown behaviour deterministic and testable without a real Sleep() or a multi-minute test run. Four channels are supported and can be combined with bitwise OR: a modal Alert() popup, SendNotification() for mobile push, SendMail() for terminal email, and a plain Print() to the log that most callers should leave enabled alongside whichever real channel they use, since the log is the only channel that is never silently dropped by an unconfigured terminal. Key tracking uses a small linear array, not a hash map. This library does not include HashMap.mqh from this catalogue - self-containment is a hard rule for every submission here - and the number of distinct alert keys a real EA tracks is small enough that a linear scan is not worth the dependency. Notes and limitations - SendNotification() requires push notifications enabled in the terminal and a device paired via MetaQuotes ID; SendMail() requires SMTP configured in Tools > Options > Email. Neither is validated by this header - if they are not configured, the terminal itself silently fails to deliver them while still returning from the call, and this header cannot detect that from inside, on either platform. - The cooldown clock is per key, not per channel. A key with mixed channels either fires on all of them together or is throttled on all of them together; there is no per-channel cooldown. - Keys are compared with an exact string match. "WideSpread_EURUSD" and "WideSpread_eurusd" are different keys - build the key consistently at every call site, typically with the chart symbol rather than a literal. - Linear key lookup costs nothing measurable at the handful of distinct alerts a typical EA raises. It is not intended for hundreds of keys.
Script · MT5 · v1.0 · Free
About Alert Manager With Throttling
Alert Manager With Throttling is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Cooldown seconds. MQL source code included.
Files in the download: AlertManager.mq5.mqh, AlertManager.txt, AlertManagerDemo.ex5, AlertManagerDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Cooldown seconds | 30 | Cooldown applied to the simulated "wide spread" alert |
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 → Scripts.
- 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 script onto a chart to run it once.
Tags: Alerts · MT5 Script · MQL5 Source Code