Monte Carlo Mean Reversion Heatmap [LuxAlgo]The Monte Carlo Mean Reversion Heatmap indicator is a statistical forecasting tool that uses Geometric Brownian Motion (GBM) to simulate 100+ potential future price paths and visualize the mathematical probability of price returning to a specific mean.
🔶 USAGE
The indicator provides a visual "probability cloud" projecting from the current price into the future. It helps traders identify statistical overextensions and the likelihood of a trend reversal toward a long-term average.
🔹 1. Assessing Mean Reversion Probability
The dashboard shows a Mean Reversion % . This tells you how many of the 100 simulated paths "touched" or "crossed" the EMA ribbon within the projection window (e.g., the next 30 bars).
High Probability (>70%): If the current price is far from the EMA but the probability of reversion is high, it suggests the market is "overextended." You might look for a counter-trend trade back toward the EMA.
Low Probability (<30%): This suggests that volatility is so high or the trend is so strong that price is statistically unlikely to return to the mean anytime soon. This often happens during "parabolic" runs.
🔹 2. Trading the "Probability Fan"
The dotted lines (5%, 50%, 95%) represent the statistical boundaries of where price is expected to stay.
Overbought/Oversold: If price moves outside the 5% or 95% lines, it is making a move that only happens in 1 out of 20 scenarios. This is a "statistical extreme." Traders often look for reversals or profit-taking when price enters these outer edges of the cone.
The Median Path (50%): This dashed line represents the "most likely" path based on current momentum (drift). It serves as a realistic target for trend-following trades.
🔹 Heatmap Density
The heatmap represents the density of the simulated paths. Darker areas indicate a higher concentration of paths, marking the price zones with the highest mathematical probability of being reached according to the model.
🔶 DETAILS
The engine behind this script is the Geometric Brownian Motion (GBM) model. GBM is a continuous-time stochastic process used in mathematical finance to model stock prices.
The model assumes that price changes follow a random walk with two components:
Drift: The deterministic trend of the mean (directional bias).
Volatility: The random "noise" or shocks based on historical log-returns.
By running 100 individual simulations simultaneously, the script generates a distribution of outcomes rather than a single linear prediction. This allows the user to see the "width" of uncertainty in the current market environment.
🔶 SETTINGS
🔹 Mean Calculation
Mean Length: The period of the EMA used as the target for mean reversion analysis.
Mean Color: The color of the target EMA line on the chart.
🔹 Monte Carlo Simulation
Simulations: The number of random paths to calculate (higher values increase accuracy but may impact performance).
Projection Length: How many bars into the future the simulation projects.
Volatility Lookback: The window used to calculate historical log-volatility for the simulation.
Include Drift: When enabled, the simulation accounts for the slope (trend) of the Mean EMA.
🔹 Visuals
Price Bins: Determines the vertical resolution of the heatmap.
Heatmap Color: The base color used for the probability density cloud.
Show Percentile Lines: Toggles the visibility of the 5%, 50%, and 95% projection lines.
🔹 Dashboard
Show Dashboard: Toggles the statistical information table.
Position/Size: Controls the location and scale of the dashboard on the chart.
Indicateur Pine Script®






















