Equity Anomaly Detector
Most equity guards only ever watch for the account going down. A sudden, unexplained jump upward can be just as worth flagging: a copier double-filling the same signal, a broker booking error, or rogue logic sizing far outside its normal range can all show up first as an equity change that simply does not look like the account's own recent history, regardless of which direction it moves. This detector keeps a rolling window of past per-sample equity changes and scores every new change with a z-score against that window's mean and standard deviation. The scoring is deliberately leave-one-out: the window's mean and stdev are computed BEFORE the newest change is added to it, so one already-large move cannot inflate its own baseline and mask the next one - a subtlety a naive "include everything so far" version of this idea gets wrong, letting real anomalies hide inside a baseline they themselves distorted. An alert only fires once enough samples have accumulated to make the baseline meaningful, and repeat alerts for an ongoing anomaly are throttled by a cooldown rather than firing on every single sample while the condition persists. Notes and limitations - Purely a monitor - it never opens, closes, or modifies a trade. It only logs and alerts. - The baseline resets on every restart; a freshly attached or restarted instance needs InpMinSamplesBeforeArming fresh samples again before it will alert on anything. - A single very large legitimate move (a big planned withdrawal or deposit, for example) will itself register as an anomaly - the tool has no way to distinguish a deliberate balance change from an unexpected one, since AccountEquity() reflects both. - The z-score is a population statistic over a fixed-size rolling window, not a formal statistical test - treat the threshold as a tunable alert sensitivity, not a hard significance level.
Expert advisor · MT5 · v1.0 · Free
About Equity Anomaly Detector
Equity Anomaly Detector is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Sample interval sec, Window size and Min samples before arming. MQL source code included.
Files in the download: EquityAnomalyDetector.ex5, EquityAnomalyDetector.mq5, EquityAnomalyDetector.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Sample interval sec | 60 | How often equity is sampled |
| Window size | 50 | Rolling window of past changes used as the baseline |
| Min samples before arming | 10 | Samples required before anomaly scoring begins (avoids startup noise) |
| Z score threshold | 3.0 | |z-score| at or above this triggers an alert |
| Alert cooldown sec | 600 | Minimum time between repeat alerts |
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: Buy/Sell Arrows · Trade Copier · Alerts · MT5 Expert Advisor · MQL5 Source Code