OPEN-SOURCE SCRIPT
Multi-Scale Slope Alignment Filter

Multi-Scale Slope Alignment Filter (MSSA)
█ OVERVIEW
This indicator identifies periods where the market trend, measured by the slope of a linear regression line, is aligned across multiple time scales (short, medium, and long-term). It acts as a trend confirmation filter, visually highlighting when different trend perspectives agree. The core idea is that signals or trades taken in the direction of aligned slopes might have a higher probability of success.
It plots the calculated slopes in a separate pane and colors the main chart background based on the alignment status: green for bullish alignment, red for bearish alignment.
█ HOW IT WORKS
The indicator calculates the slope of a linear regression line for three different lookback periods defined by the user inputs (`Short-Term`, `Medium-Term`, `Long-Term`).
The "slope" is determined by comparing the value of the linear regression line at the current bar (`offset=0`) to its value on the previous bar (`offset=1`).
The core calculation for a single slope is:
Based on these three slopes, the alignment state is determined:
█ HOW TO USE
The primary use of the Multi-Scale Slope Alignment Filter (MSSA) is as a trend confirmation tool or trade filter.
This indicator is generally not designed to provide direct entry or exit signals on its own. It works best when combined with your primary trading strategy or other indicators to filter their signals based on multi-timeframe trend agreement.
Example filter logic:
█ INPUTS / SETTINGS
█ VISUALIZATION
█ SUMMARY
The MSSA indicator provides a visual filter based on the consensus of trend direction across short, medium, and long-term perspectives using linear regression slopes. It helps traders align their strategies with the prevailing multi-scale trend environment. Remember to use it as part of a comprehensive trading plan and always practice sound risk management. This tool provides analysis and is not financial advice.
█ OVERVIEW
This indicator identifies periods where the market trend, measured by the slope of a linear regression line, is aligned across multiple time scales (short, medium, and long-term). It acts as a trend confirmation filter, visually highlighting when different trend perspectives agree. The core idea is that signals or trades taken in the direction of aligned slopes might have a higher probability of success.
It plots the calculated slopes in a separate pane and colors the main chart background based on the alignment status: green for bullish alignment, red for bearish alignment.
█ HOW IT WORKS
The indicator calculates the slope of a linear regression line for three different lookback periods defined by the user inputs (`Short-Term`, `Medium-Term`, `Long-Term`).
The "slope" is determined by comparing the value of the linear regression line at the current bar (`offset=0`) to its value on the previous bar (`offset=1`).
- A positive difference indicates an upward sloping regression line (potential uptrend).
- A negative difference indicates a downward sloping regression line (potential downtrend).
The core calculation for a single slope is:
Pine Script®
ta.linreg(source, length, 0) - ta.linreg(source, length, 1)
Based on these three slopes, the alignment state is determined:
- Bullish Alignment: All three slopes (Short, Medium, Long) are positive (greater than 0). This suggests an uptrend is confirmed across all measured scales.
- Bearish Alignment: All three slopes are negative (less than 0). This suggests a downtrend is confirmed across all measured scales.
- Neutral/Mixed: The slopes do not unanimously agree (i.e., some are positive while others are negative, or some are zero). This indicates conflicting signals or a potential consolidation phase.
█ HOW TO USE
The primary use of the Multi-Scale Slope Alignment Filter (MSSA) is as a trend confirmation tool or trade filter.
- Consider taking long trades only when the background is green (Bullish Alignment). This acts as confirmation that the broader trend context supports the long idea.
- Consider taking short trades only when the background is red (Bearish Alignment). This acts as confirmation that the broader trend context supports the short idea.
- Consider being cautious or avoiding trades when there is no background color (Neutral/Mixed Alignment), as the trend direction is unclear or conflicting across different timeframes.
This indicator is generally not designed to provide direct entry or exit signals on its own. It works best when combined with your primary trading strategy or other indicators to filter their signals based on multi-timeframe trend agreement.
Example filter logic:
Pine Script®
// Example Long Condition
primaryLongSignal = ta.crossover(fastMA, slowMA) // Your primary signal
longCondition = primaryLongSignal and isBullishAligned // Filter with MSSA
// Example Short Condition
primaryShortSignal = ta.crossunder(fastMA, slowMA) // Your primary signal
shortCondition = primaryShortSignal and isBearishAligned // Filter with MSSA
primaryLongSignal = ta.crossover(fastMA, slowMA) // Your primary signal
longCondition = primaryLongSignal and isBullishAligned // Filter with MSSA
// Example Short Condition
primaryShortSignal = ta.crossunder(fastMA, slowMA) // Your primary signal
shortCondition = primaryShortSignal and isBearishAligned // Filter with MSSA
█ INPUTS / SETTINGS
- Short-Term Slope Length: (Default: 20) The lookback period for calculating the short-term linear regression slope.
- Medium-Term Slope Length: (Default: 50) The lookback period for calculating the medium-term linear regression slope.
- Long-Term Slope Length: (Default: 100) The lookback period for calculating the long-term linear regression slope.
- Source: (Default: close) The price data source used for the linear regression calculations (e.g., close, HLC3, OHLC4).
█ VISUALIZATION
- Background Coloring: The background of the main price chart is colored to indicate the alignment state:
Green: Bullish Alignment (all slopes positive).
Red: Bearish Alignment (all slopes negative).
No Color: Neutral/Mixed Alignment.
- Indicator Pane: A separate pane below the main chart displays:
- Three lines representing the calculated slope values for the short (red), medium (blue), and long (yellow) terms.
- A dashed horizontal line at zero, making it easy to visually distinguish positive (above zero) from negative (below zero) slopes.
- Three lines representing the calculated slope values for the short (red), medium (blue), and long (yellow) terms.
█ SUMMARY
The MSSA indicator provides a visual filter based on the consensus of trend direction across short, medium, and long-term perspectives using linear regression slopes. It helps traders align their strategies with the prevailing multi-scale trend environment. Remember to use it as part of a comprehensive trading plan and always practice sound risk management. This tool provides analysis and is not financial advice.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
For quick access on a chart, add this script to your favorites — learn more here.
mastertop
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
For quick access on a chart, add this script to your favorites — learn more here.
mastertop
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.