Linear Mean Reversion Strategy by XiaoboFu

By XiaoboFu

Performance Metrics

Description

📘 Strategy Introduction: Linear Mean Reversion with Fixed StopThis strategy implements a simple yet powerful mean reversion model that assumes price tends to oscillate around a dynamic average over time. It identifies statistically significant deviations from the moving average using a z-score, and enters trades expecting a return to the mean.🧠 Core Logic:A z-score is calculated by comparing the current price to its moving average, normalized by standard deviation, over a user-defined half-life window.Trades are entered when the z-score crosses a threshold (e.g., ±1), signaling overbought or oversold conditions.The strategy exits positions either when price reverts back near the mean (z-score close to 0), or if a fixed stop loss of 100 points is hit, whichever comes first.⚙️ Key Features:Dynamic mean and volatility estimation using moving average and standard deviationConfigurable z-score thresholds for entry and exitPosition size scaling based on z-score magnitudeFixed stop loss to control risk and avoid prolonged drawdowns🧪 Use Case:Ideal for range-bound markets or assets that exhibit stationary behavior around a mean, this strategy is especially useful on assets with mean-reverting characteristics like currency pairs, ETFs, or large-cap stocks. It is best suited for traders looking for short-term reversions rather than long-term trends.Release NotesThe idea is simple: if an instrument’s price is truly mean-reverting, we can expect it to return to its long-term average. Most assets, however, behave more like random walks and show little tendency to revert. The VIX—an index of S&P 500 volatility—is a notable exception, exhibiting clear mean-reversion. For this strategy, I’ve assumed a trading cost of 0.1%, which seems reasonable given the typical bid-ask spread on the VIX is about 0.18 points.A z-score is calculated by comparing the current price to its moving average, normalized by standard deviation, over a user-defined half-life window.Trades are entered when the z-score crosses a threshold (e.g., ±1), signaling overbought or oversold conditions.The strategy exits positions either when price reverts back near the mean (z-score close to 0), or if a fixed stop loss is hit, whichever comes first.Designed for a 1 H window, where the VIX’s mean reversion and assumed costs tend to align well.

Browse all 5,900+ TradingView Pine Script strategies

View on TradingView