The MarkovV2 strategy is a backtesting strategy that uses a Markov Regression model to predict the probabilities of different market states. It calculates and populates several indicators based on the provided data, such as returns, volume gap, fractal high, and fractal low. The strategy starts by fitting the Markov Regression model on a large amount of historical data.
Then, it iterates through the data and predicts the probabilities of the next market state using the fitted model.
These probabilities are stored in the 'prob_up', 'prob_side', and 'prob_down' columns of the dataframe.
In the 'populate_buy_trend' method, the strategy generates buy signals when the probability of an upward market movement ('prob_up') is greater than 0.8, and the probabilities of sideways movement ('prob_side') and downward movement ('prob_down') are both less than 0.5. Similarly, in the 'populate_sell_trend' method, the strategy generates sell signals when the probability of a downward market movement ('prob_down') is greater than 0.8, and the probabilities of sideways movement ('prob_side') and upward movement ('prob_up') are both less than 0.5. Overall, the strategy uses the Markov Regression model to assess the probabilities of different market states and generates buy and sell signals based on these probabilities.