Bayesian Online Change-Point Detection (BOCPD) in MQL5: One Regime-Break Signal, Three Ways to Use It
Найти файл
Файлы репозитория (в начале последний коммит)
Имя файла Текст последнего коммита Дата последнего коммита
2026-08-14 00:09:38 +00:00
Experts/BOCPD initial commit 2026-07-12 02:30:13 +00:00
Include/BOCPD initial commit 2026-07-12 02:29:16 +00:00
Indicators/BOCPD initial commit 2026-07-12 02:29:48 +00:00
README.md Add README 2026-08-14 00:09:38 +00:00

BOCPD

Bayesian Online Change-Point Detection in MQL5. Maintains a probability distribution over how long the current regime has lasted, and updates it bar by bar, so a break is flagged as it happens rather than after a lookback window catches up.

Companion code for the MQL5 article: https://www.mql5.com/en/articles/23482

What it does

The run-length posterior is the whole method. At every bar the model asks how likely it is that the current regime started 1 bar ago, 2 bars ago, and so on. A break shows up as probability mass collapsing from a long run length onto zero. Nothing here is a threshold on a moving average.

CBOCPD in BOCPDModel.mqh carries the recursion. Three consumers sit on top of it, which is the point of the article: the same signal is useful in more than one place.

  • BOCPDRegime.mq5 plots the break probability directly, as a monitor.
  • BOCPDAdaptiveMA.mq5 is a moving average that resets itself when the model says the regime changed, instead of dragging stale history across the break.
  • BOCPDRiskOverlay.mq5 uses it as a meta-layer over position sizing rather than as an entry signal.

Layout

Include/BOCPD/BOCPDModel.mqh          the recursion, CBOCPD
Indicators/BOCPD/BOCPDRegime.mq5      break probability monitor
Indicators/BOCPD/BOCPDAdaptiveMA.mq5  self-resetting adaptive average
Experts/BOCPD/BOCPDRiskOverlay.mq5    risk meta-layer

Copy the folders into your terminal's MQL5 directory and compile.

Disclaimer

Educational code. Past behaviour of any model or dataset says nothing about future results. Test on your own data and broker conditions before drawing conclusions.