Multi-Scale Slope Alignment Filter

█ 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:
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:
█ 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.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.