Discussing the article: "A Categorical Hidden Markov Model in MQL5"
Thank you for your feedback.
You see, filtering and a moving average are completely different things. A moving average is simply an average calculated over a sliding window. Filtering is the process of calculating the probability distribution of hidden states. It is a set of probabilities. In other words, it is an assessment of the state we are in at the current moment in time. If the probability is higher for an uptrend, it means the market is most likely in that state, and you can then open a position in line with the trend. If the probability of being in a state of noise (a 50/50 chance of a white candle) is higher, it means the market is currently random and opening trades is not recommended. That is the main idea. Therefore, if you use moving averages to determine an entry point, the HMM acts as a safeguard that will prevent you from opening a trade if it determines that there is no trend at the moment.
But before implementing the trading algorithm, we need to detect these hidden states. How can we do this if we only have a dataset? Using a learning algorithm (EM). It’s like finding parameters in an MLP via gradient descent. By analysing the parameters obtained, we can conclude whether any hidden states are present in the data at all, or whether the market is in a state of chaos and there is only one mode (equal emission probabilities for each state).
Train the model for the coin-toss scenario (white/black candlestick) for two states (fair/biased); you will then be able to better understand the model’s capabilities.
Check out the new article: A Categorical Hidden Markov Model in MQL5.
The subject of this article is the categorical hidden Markov model (HMM) — a classic example of the SSM class with discrete latent states and a categorical distribution of observed data. Transitions between states in the system are described using a transition probability matrix.
For example, the model allows you to identify hidden market regimes based on a sequence of market events (white or black candles). In one regime (let's call it an uptrend), white candles appear much more frequently; in another (a downtrend), black candles are more common; and in a third (a sideways market), their probabilities are equal. Of course, we do not observe the regimes themselves; they are hidden. The model's goal is to infer the current market state by analyzing only the available data (candlestick colors).
To test such hypotheses, the CCategoricalHMM class was implemented in MQL5. Using simple and clear examples, we will explore the class's main features:Author: Evgeniy Chernish