All indicators

Mean Reversion and Trendfollowing

Mar 25, 2023

Static chart image
SignalsOscillatorsMoving Averages

The Mean Reversion and Trendfollowing indicator is a hybrid trading tool that combines short-term mean reversion techniques with long-term trend following momentum to capitalize on various market conditions. By integrating a 200-period Simple Moving Average (SMA) and a 2-period Relative Strength Index (RSI), the tool identifies high-probability entry points during both price corrections and trending phases.

Usage

The script operates in two primary modes determined by the price's relationship to the 200-period SMA:

  • Mean Reversion Mode: Active when the price is below the SMA200. In this regime, the script looks for oversold conditions using a 2-period RSI. A buy signal is generated when RSI drops below 20, and the position is closed when RSI rises above 80.
  • Trend Following Mode: Active when the price is above the SMA200. This mode aims to ride upward momentum. A buy signal is triggered when price remains above the SMA200. The exit for trend trades is more conservative, triggering if the price falls below 95% of the SMA200 value.

Users can toggle either mode on or off to specialize the script for specific market environments. Additionally, the position sizing can be adjusted independently for each mode to manage risk exposure.

Details

The implementation is grounded in behavioral finance theories regarding market under- and overreactions. According to research on investor overconfidence and biased self-attribution, markets often exhibit short-term momentum (trend following) followed by long-term reversals (mean reversion).

The script uses a fast 2-period RSI to capture the "overreaction-correction" pattern within broader trends. The SMA200 serves as the primary filter to distinguish between a bullish environment where momentum is favored and a bearish environment where mean-reverting pullbacks offer better risk-to-reward ratios.

Settings

  • Starting Date: Filters historical data to start calculations and trades from a specific timestamp.
  • Enable Mean Reversion: Toggles the RSI-based mean reversion logic.
  • Enable Trend Following: Toggles the SMA-based trend following logic.
  • Trend Position Factor: Adjusts the quantity of the position when a trend-following signal is triggered.
  • Mean Reversion Position Factor: Adjusts the quantity of the position when a mean reversion signal is triggered.

FAQ

How do I use the Mean Reversion and Trendfollowing indicator?

You can apply the script to your chart and use the inputs to select whether you want to see both signals or focus on one specific methodology. The SMA lines on the chart provide visual context for the trend regime.

Can I change the sensitivity of the RSI entries?

While the period is fixed at 2 for optimal short-term mean reversion, the logic is designed to trigger at specific oversold (20) and overbought (80) thresholds.

Where can I access this tool?

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.