Loading…

Spread Profile Anomaly Alert

A single fixed spread threshold is wrong for more than one symbol at a time. Set it tight enough to catch a real widening on a normally tight pair and it fires constantly during a symbol whose ordinary session spread is naturally wider; set it loose enough to tolerate that wider symbol and it misses a genuine problem on the tight one until it has already gotten much worse. This tool learns instead of guessing. For every watched symbol it keeps a separate running mean and standard deviation of spread for each hour of the server-time day, using an online algorithm that needs no stored history. Once an hour-bucket has enough samples, a new reading is compared against that bucket's own mean and standard deviation as a z-score, and only a statistically unusual reading - several standard deviations above what that symbol normally shows at that hour - raises an alert. A sample that is flagged anomalous is alerted but deliberately excluded from updating the baseline for that hour. Folding a spike straight into the running average would raise the bar for the next comparison and make a sustained widening progressively harder to detect the longer it continues - the opposite of what an anomaly alert is for. Notes and limitations - Never opens, closes or modifies a trade. It only observes and alerts. - All learning is in memory only and resets when the EA is reloaded; nothing is saved between sessions. A fresh attach needs to relearn every hour bucket from zero. - Hour buckets use server time, which usually differs from the broker's local time and from GMT - check the terminal's server time before reading the dashboard's hour label. - Watches up to 20 symbols in one instance. Attach a second instance with a different list if more coverage is needed. - A structural, permanent change in a symbol's typical spread (a broker repricing it) will keep triggering alerts every re-alert interval, since anomalous samples are excluded from the baseline by design - that is the intended behaviour, not a bug, but it means a genuine repricing needs a restart to be accepted as the new normal.

Expert advisor · MT5 · v1.0 · Free

About Spread Profile Anomaly Alert

Spread Profile Anomaly Alert is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 7 settings, such as Watch symbols, Sample interval secs and Min samples for baseline. MQL source code included.

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

Settings

SettingDefaultWhat it does
Watch symbolsComma-separated symbols to watch ("" = current chart symbol only)
Sample interval secs30Seconds between spread samples
Min samples for baseline20Samples an hour-bucket needs before it can trigger an anomaly alert
Z score threshold3.0Standard deviations above the learned mean that counts as anomalous
Min std dev points0.5Floor applied to a bucket's standard deviation, so a near-flat history cannot produce a runaway z-sc
Re alert minutes15Minutes to wait before repeating an alert for a symbol still widened
Send push on alertfalseSend a mobile push notification on each new alert (needs MetaQuotes ID set up)

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Alerts · Trading Sessions · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria