Loading…

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 · MT4 · v1.0 · Free

About Cusum Break Detector

Cusum Break Detector is an indicator for MetaTrader 4. 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.ex4, CusumBreakDetector.mq4, CusumBreakDetector.txt.

Settings

SettingDefaultWhat it does
Window period50Bars over which the cumulative sums accumulate
Baseline period50Bars strictly before the window, used for reference mean/sigma
Drift k0.5Allowance k, in sigma units, subtracted from every deviation
Threshold h4.0Decision threshold h, in sigma units
AlertstrueAlert once per closed bar on a new breach
CornerCORNER_LEFT_UPPERPanel corner
X distance10Panel horizontal offset, pixels
Y distance20Panel vertical offset, pixels
Font size10Panel font size

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Indicators.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the indicator from the Navigator onto a chart and adjust the settings.

Download the PDF guide

Tags: Moving Average · Alerts · MT4 Indicator · MQL4 Source Code

MetaTrader 4 & 5 indicators · PolyMaria