Loading…

Markov Regime Switch Probability

Most regime tools bucket the market with a single hard rule - price above or below a moving average, an oscillator above or below a midline. A hidden Markov read is different: it treats "bull" and "bear" as two hidden states, each with its own typical return and typical noise, and asks how likely the most recent stretch of returns is to have come from one state rather than the other, given how often the market tends to stay in a state versus flip out of it. Each bar, the indicator takes the trailing window of 1-bar log returns, splits them by sign to estimate a mean and standard deviation for the "up" state and the "down" state, counts how often an up bar was followed by another up bar (and the equivalent for down) to estimate a transition matrix, then runs the standard forward algorithm through the window to produce a filtered probability of being in the bull state at the most recent bar. Every quantity is re-estimated independently for every bar's own trailing window - nothing carries over from a global fit - so a historical reading never moves once its bar has closed, which is the property a hidden Markov filter does not get for free when it is estimated only once across the whole chart. Thin data is handled explicitly rather than left to blow up: if a window happens to contain too few up bars or too few down bars to fit a trustworthy variance, the indicator falls back to splitting the window's overall mean and standard deviation symmetrically instead of fitting two near-degenerate Gaussians from a handful of points. Notes and limitations - This is a descriptive filter on past returns, not a forecast: a high bull probability describes how the recent window has behaved, not what the next bar will do. - The two states are separated purely by return sign and its distribution; it does not know about news, sessions or any external regime driver. - Re-fitting the full model on every bar is deliberate for non-repainting correctness but means InpWindowPeriod directly controls per-bar cost - very large windows on very long histories will take noticeably longer on the first calculation pass. - This does not size a position, place a stop, or account for spread and slippage.

Indicator · MT5 · v1.0 · Free

About Markov Regime Switch Probability

Markov Regime Switch Probability is an indicator for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 5 settings, such as Window period, Min state samples and Bull threshold. MQL source code included.

Files in the download: MarkovRegimeSwitch.ex5, MarkovRegimeSwitch.mq5, MarkovRegimeSwitch.txt.

Settings

SettingDefaultWhat it does
Window period60Returns in the rolling window used to fit the model
Min state samples5Minimum returns needed in a state before its own mean/variance is trusted
Bull threshold70.0Probability at/above this = bull regime
Bear threshold30.0Probability at/below this = bear regime
AlertstrueAlert once per closed bar on a regime flip

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Indicators.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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 · Oscillator · Alerts · MT5 Indicator · MQL5 Source Code

MetaTrader 4 & 5 indicators · PolyMaria