OPEN-SOURCE SCRIPT
已更新

Markov Chain Trend Probability

228
A Markov Chain is a mathematical model that predicts future states based on the current state, assuming that the future depends only on the present (not the past). Originally developed by Russian mathematician Andrey Markov, this concept is widely used in:
  • Finance: Risk modeling, portfolio optimization, credit scoring, algorithmic trading
  • Weather Forecasting: Predicting sunny/rainy days, temperature patterns, storm tracking

Here's an example of a Markov chain: If the weather is sunny, the probability that will be sunny 30 min later is say 90%. However, if the state changes, i.e. it starts raining, how the probability that will be raining 30 min later is say 70% and only 30% sunny.
Similar concept can be applied to markets price action and trends.

Mathematical Foundation
The core principle follows the Markov Property: P(X_{t+1}|X_t, X_{t-1}, ..., X_0) = P(X_{t+1}|X_t)

Transition Matrix :
-------------Next State
Current----[Up] [Down]
[Up]--------P11 P12
[Down]-----P21 P22

Probability Calculations:
P(Up→Up) = Count(Up→Up) / Count(Up states)
P(Down→Down) = Count(Down→Down) / Count(Down states)
Steady-state probability: π = πP (where π is the stationary distribution)

State Definition:
State = UPTREND if (Price_t - Price_{t-n})/ATR > threshold
State = DOWNTREND if (Price_t - Price_{t-n})/ATR < -threshold

How It Works in Trading
This indicator applies Markov Chain theory to market trends by:
  • Defining States: Classifies market conditions as UPTREND or DOWNTREND based on price movement relative to ATR (Average True Range)
  • Learning Transitions: Analyzes historical data to calculate probabilities of moving from one state to another
  • Predicting Probabilities: Estimates the likelihood of future trend continuation or reversal


How to Use
Parameters:
  • Lookback Period: Number of bars to analyze for trend detection (default: 14)
  • ATR Threshold: Sensitivity multiplier for state changes (default: 0.5)
  • Historical Periods: Sample size for probability calculations (default: 33)


Trading Applications:
  • Trend confirmation for entry/exit decisions
  • Risk assessment through probability analysis
  • Market regime identification
  • Early warning system for potential trend reversals


The indicator works on any timeframe and asset class. Enjoy!
發行說明
Update Notes for Version 2.0
New Feature: Brier Score Accuracy Measurement
I've added a rolling Brier Score to measure the real-time accuracy of the Markov Chain predictions. This provides traders with immediate feedback on model performance.

The Brier Score is a statistical measure that evaluates how well probabilistic predictions match actual outcomes. It calculates the mean squared difference between predicted probabilities and actual binary results (uptrend/downtrend). The score ranges from 0 (perfect predictions) to 1 (worst possible predictions), with 0.25 being the baseline for random guessing. Lower scores indicate better calibrated predictions. So the lower, the better.

Brier Score Line: Orange line showing rolling prediction accuracy (lower is better)
Accuracy Classification: Table now displays model performance categories:
  • Exceptional (<10%)
  • Excellent (10-15%)
  • Very Good (15-20%)
  • Good (20-25%)
  • Fair (25-30%)
  • Poor (>30%)


The Brier Score helps identify when market conditions are favorable for the Markov approach versus when they're too chaotic.
Scores below 25% indicate the model is beating random chance, with scores below 15% showing excellent predictive accuracy.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。