Linear Regression + Moving Average
May 25, 2021

The Linear Regression + Moving Average indicator combines a dynamic linear regression channel with dual moving average crossovers to identify trend direction and volatility-based entry or exit zones.
Usage
The Usage section describes how the script can be used to identify trend shifts and potential reversal points. Traders can utilize the indicator in the following ways:
- Trend Identification: The Symmetrically Weighted Moving Average (SWMA) changes color based on its relationship with its previous value (offset -1). A green line indicates an upward trajectory, while a red line indicates a downward trajectory.
- Momentum Crossovers: The interaction between the SWMA and the Exponential Weighted Moving Average (EMA) provides crossover signals. When the SWMA crosses above the EMA, the area between them fills green, suggesting bullish momentum. Conversely, a cross below suggests bearish momentum.
- Volatility Channels: The linear regression component plots a center line with multiple deviations. The dashed lines represent the high/low range of the period, while the dotted lines represent the first and second standard deviations.
- Mean Reversion: Green zones (lower deviations) often indicate potential long opportunities in an uptrend, while red zones (upper deviations) indicate potential short opportunities in a downtrend.
Details
The script executes by calculating a linear regression slope over a user-defined period to establish a baseline. Surrounding this baseline, it calculates standard deviations and absolute high/low offsets to create a comprehensive channel.
The moving average component utilizes a Symmetrically Weighted Moving Average (SWMA), which applies fixed weights to a window of data, and an Exponential Moving Average (EMA). The relationship between these two averages, specifically the crossover of the SWMA against the EMA, is used to determine the primary trend bias and visual fills on the chart.
Settings
- Extend Lines: Determines whether the linear regression channel lines extend infinitely to the right of the chart or remain fixed to the calculation window.
- Moving Average Length: Adjusts the period used for the Exponential Weighted Moving Average calculation.
- Linear Regression Length: Sets the lookback period (between 1 and 300) for calculating the linear regression slope, intercept, and associated deviation bands.
FAQ
How do I interpret the different line styles in the channel? The solid middle line is the linear regression base. Dotted lines represent the 1st and 2nd standard deviations, while the dashed lines represent the maximum price excursions (High/Low) within the specified length.
What triggers the color change in the moving averages? The SWMA changes color based on its directional slope (relative to its previous value), while the cloud fill changes based on whether the SWMA is above or below the EMA.
How can I access this indicator? 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.
Unlock the entire LuxAlgo Library
Every indicator, every strategy, full charts, and complete access to Quant — our AI agent.