All indicators

Mean Reversion Algorithm

Sep 4, 2018

Static chart image
SignalsMoving Averages

The Mean Reversion Algorithm indicator identifies potential trend reversal and continuation points by comparing short-term and long-term price averages to detect overextended market conditions.

Usage

The Mean Reversion Algorithm is designed to highlight specific market conditions where the price deviates significantly from its historical mean.

  • Buy Signals: Represented by green squares at the bottom of the chart. These occur when the typical price (HLC3) is above the long-term mean and the ratio between the short-term and long-term means (Beta) exceeds the user-defined Buy Threshold.
  • Sell Signals: Represented by red squares at the bottom of the chart. These occur when the typical price (HLC3) is below the short-term mean and the Beta ratio falls below the user-defined Sell Threshold.

Users can adjust the thresholds to make the algorithm more or less sensitive to price fluctuations, depending on the volatility of the asset being traded.

Details

The script operates on the principle of mean reversion, which suggests that asset prices tend to return to their long-term average over time. It calculates two distinct averages:

  1. Short Mean: Captures immediate price momentum over a small window (default 5 periods).
  2. Long Mean: Establishes a baseline for the broader trend (default 20 periods).

The core logic revolves around the Beta variable, which is the ratio of the Short Mean to the Long Mean. By analyzing how these two averages interact relative to specific thresholds, the script filters out noise and highlights moments where price action suggests a sustainable move or a correction back toward the mean.

Settings

  • Source: Determines the price data used for the calculations (default is Close).
  • Short Mean Period: The lookback period for the short-term average calculation.
  • Long Mean Period: The lookback period for the long-term average baseline.
  • Buy Threshold: The minimum Beta ratio required to trigger a buy condition.
  • Sell Threshold: The maximum Beta ratio allowed to trigger a sell condition.

FAQ

How do I interpret the Beta ratio?

The Beta ratio represents the relationship between short-term momentum and the long-term trend. A ratio above 1.0 indicates that the short-term average is higher than the long-term average, while a ratio below 1.0 indicates the opposite.

Can I use this for automated alerts?

Yes, the script includes built-in alert functionality for both Buy and Sell conditions, optimized to trigger once per bar close to avoid repaint issues.

How do I access the Mean Reversion Algorithm?

You can get access on the LuxAlgo Library for charting platforms like TradingView, MetaTrader (MT4/MT5), and NinjaTrader for free.

Free indicator

Get free access to this indicator on the platforms below.

TradingView
NinjaTrader
MetaTrader 4/5

Unlock the entire LuxAlgo Library

Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.