Cusum Break Detector
A moving average crossing tells you price direction changed; it says nothing about whether that change was actually a meaningful shift in behaviour or just noise wobbling around an unchanged mean. The CUSUM control chart, standard in industrial process monitoring, is built exactly for that distinction: it accumulates small deviations from a reference mean over time, so a shift too small to notice on any single bar becomes visible once enough of it has accumulated, while pure noise around an unchanged mean keeps resetting itself back toward zero. The reference mean and its sigma are estimated from a baseline window that sits strictly before the window being tested for a break - never from the tested window's own data. Using the tested window's own mean as the reference would let a genuinely drifting mean chase its own tail and never accumulate a signal, which is the trap that makes a naive CUSUM implementation quietly useless. Both cumulative sums also restart from zero at the start of every bar's own trailing window rather than accumulating from the first bar of the whole chart, so a signal always reflects a shift within the visible window, not carried-over history from years earlier on the same chart. A corner panel shows the live threshold and sigma in price-return units alongside a plain-language UP BREAK / DOWN BREAK / no break status, since the two plotted lines alone do not show what threshold they are being measured against on any given bar. Notes and limitations - The baseline window sits immediately before the CUSUM window; a baseline that itself already contains an old, stale shift will bias the reference mean and can suppress a genuine current break. - InpDriftK and InpThresholdH trade sensitivity against false alarms the same way they do in industrial CUSUM charts - a smaller k and h catch smaller shifts sooner at the cost of more false positives. - This flags a statistical shift in the mean of returns, not a specific price level or a trade signal on its own. - This does not size a position, place a stop, or account for spread and slippage.
Indicator · MT5 · v1.0 · Free
About Cusum Break Detector
Cusum Break Detector is an indicator for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 9 settings, such as Window period, Baseline period and Drift k. MQL source code included.
Files in the download: CusumBreakDetector.ex5, CusumBreakDetector.mq5, CusumBreakDetector.txt.
Settings
| Setting | Default | What it does |
|---|---|---|
| Window period | 50 | Bars over which the cumulative sums accumulate |
| Baseline period | 50 | Bars strictly before the window, used for reference mean/sigma |
| Drift k | 0.5 | Allowance k, in sigma units, subtracted from every deviation |
| Threshold h | 4.0 | Decision threshold h, in sigma units |
| Alerts | true | Alert once per closed bar on a new breach |
| Corner | CORNER_LEFT_UPPER | Panel corner |
| X distance | 10 | Panel horizontal offset, pixels |
| Y distance | 20 | Panel vertical offset, pixels |
| Font size | 10 | Panel font size |
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 → Indicators.
- 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 indicator from the Navigator onto a chart and adjust the settings.
Tags: Moving Average · Alerts · MT5 Indicator · MQL5 Source Code