Duration-Aware Market Regime Detection with Hidden Semi-Markov Models
Summary
This article presents a Hidden Semi-Markov Model (HSMM) for detecting market regimes while estimating how much time may remain in the current state. Unlike a standard Hidden Markov Model, which implies geometrically distributed regime durations, the HSMM assigns each state an explicit duration distribution. Its live filter tracks probabilities across states and remaining durations, updates them as bars arrive, and derives an expected remaining duration that can inform trade entries and exits.
The example distinguishes upward and downward trends, range conditions, and high-volatility chop. It uses rolling volatility deviation, price-path efficiency, and return skew as inputs, with Gaussian emissions and discretized negative-binomial durations. Parameters are fitted offline with Expectation-Maximization, then used by native MQL5 code. The article includes synthetic feature-separation illustrations and describes an XAUUSD five-minute implementation, but the supplied figures are sanity checks rather than market-performance evidence. Duration limits and feature windows need reconsideration and retraining for other instruments or timeframes; no universal settings or independent profitability validation are established.
Key ideas
- An HSMM models regime duration explicitly, avoiding the constant exit probability implied by a standard HMM.
- The filter tracks probability by both regime and remaining duration, then updates that estimate bar by bar.
- Volatility deviation, efficiency ratio, and return skew are used to distinguish four market states.
- Model parameters are fitted offline, while the duration-aware inference runs natively in MQL5.
- Synthetic feature plots demonstrate separation in generated data, not trading performance.
- Duration limits and feature windows should be adapted and retrained for each instrument and timeframe.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.