Skip to content
All library documents

Using Markov Transition Matrices to Choose Trend or Mean-Reversion Strategies

Article MQL5 articles

Summary

The article explains how an Expert Advisor can use a Markov transition matrix to classify market behavior and choose between trend-following and mean-reversion approaches. It defines two states from whether a candle closes above or below a moving average, then estimates the chance of each state persisting or switching on the next candle. A persistence probability above one half is treated as evidence favoring trend-following; a lower probability points toward mean-reversion. The example uses EUR/USD data and a 20-period simple moving average, and reports an 88% chance of remaining above the average after an above-average close.

The article outlines implementations in Python with MetaTrader 5 data and in MQL5, including functions to identify the current state and select a trade direction. The example is educational rather than a validated trading study: it supplies no out-of-sample results, transaction-cost analysis, or risk controls, and the state definitions and probability estimates may need adaptation across instruments and timeframes.

Key ideas

  • A transition matrix estimates the probabilities of moving between defined market states.
  • The example defines states by whether the close is above or below a simple moving average.
  • High state persistence is interpreted as a reason to favor trend-following, while lower persistence suggests mean-reversion.
  • The article demonstrates matrix construction using Python and describes using the result in an MQL5 Expert Advisor.
  • The example does not establish profitability through robust backtesting or account for trading costs.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.