Discussing the article: "Bayesian Online Change-Point Detection (BOCPD) in MQL5: One Regime-Break Signal, Three Ways to Use It"

 

Check out the new article: Bayesian Online Change-Point Detection (BOCPD) in MQL5: One Regime-Break Signal, Three Ways to Use It.

This article delivers Bayesian Online Change-Point Detection as a single, dependency-free MQL5 class that maintains a per-bar, causal probability of a regime break. We use it three ways: a live monitor, a moving average that flushes on breaks, and a risk overlay with a matched-frequency random control. Readers get a reusable primitive to watch structural change, adapt indicators, and gate exposure after detected shifts.

Ask most standard change-detection tools when the market "changed", and they answer in the past tense. A Chow test is handed a fixed block of history and told to find the break that already happened inside it. A CUSUM chart accumulates deviations until, some bars after the fact, the running sum crosses a line. Even the regime classifiers built on autocorrelation or volatility describe the state you are already in, not the moment you left the last one. These are all valuable, and the MQL5 community has produced excellent implementations of them, but they share a stance: look back over a window and decide, retrospectively, where the seam was.

Live trading needs the present tense. When a volatility regime flips or a trend quietly dies, the useful question is not "where, in this old window, was the break?" but "given everything up to this bar and nothing after it, what is the probability that the regime just ended?" That is a fundamentally online question, and it wants a fundamentally online answer: causal, updated every bar, and honest about its own uncertainty.

There is a method built precisely for this, and it is conspicuously absent from the MQL5 landscape. Bayesian Online Change-Point Detection (BOCPD), introduced by Adams and MacKay in 2007, maintains a full probability distribution over one hidden quantity: the run length, the number of bars since the last change-point. Every new observation revises that distribution. When the data stop looking like the current regime, the probability mass collapses back toward a run length of zero, and that collapse is the alarm. No future data, no fixed window, no retrospection. Just a per-bar, probabilistic statement about whether the ground has shifted under your feet.

The point of this article is not to add one more regime detector to a crowded shelf. That shelf is already well stocked with strong work, from a custom regime-detection system built on autocorrelation and volatility to Hidden Markov Models for volatility prediction, and BOCPD is not meant to displace any of them. What it offers instead is a different primitive: rather than classifying which state you are in, it produces the probability that the state just broke, and that one primitive drives three different jobs. We build the model once, as a self-contained class with no external dependencies, and then put it to work three ways: as a live regime monitor you read, as a moving average that resets itself so an indicator can react to breaks internally, and as a risk overlay that de-risks a strategy the moment the market turns dangerous. See it, let an indicator use it, let your account use it.

Offline retrospective window versus online causal per-bar detection


Author: Muhammad Minhas Qamar