OPEN-SOURCE SCRIPT
Singular Spectrum Decomposition [LuxAlgo]

The Singular Spectrum Decomposition [LuxAlgo] indicator is a powerful analytical tool that decomposes price action into distinct, interpretable components—Trend, Periodic cycles, and Noise—using the Singular Spectrum Analysis (SSA) methodology.
It provides traders with a clear view of underlying market structures and offers a jump-free, extrapolated trend forecast based on Linear Recurrence Relations (LRR).
Warning: This decomposition is displayed retrospectively; historical values observed are subject to repainting.
🔶 USAGE
The indicator operates by analyzing a specific window of recent price data to extract its most significant internal dynamics. It splits the "messy" raw price into four visual layers:
🔹 Cycle Exhaustion (P1/P2 Extremes)
Traders can monitor the separate indicator pane to identify when cyclical components (P1 and P2) reach historical extremes. When the Long Term Periodic (P1) line begins to curve back toward the zero line after a prolonged extension, it often signals "cycle exhaustion," suggesting that the current swing is losing momentum and a reversal or consolidation may be imminent.
🔹 Trend-Forecast Confluence & Mean Reversion
The dashed Trend extrapolation acts as a projected path for the market's core bias. If the current market price is significantly far from the solid Trend line while the forecast indicates a flattening or reversal, traders can look for mean-reversion opportunities. A price returning to a rising Trend forecast confirms the trend's strength, while a price crossing through a flat Trend forecast suggests a structural shift.
🔹 Timing Entries with Dashboard Metrics
The "Average Period" displayed on the dashboard provides a mathematical blueprint for entry timing. For example, if the Short Term (P2) Average Period is 20 bars, a trader might look for long entries approximately 10 bars after a peak (the expected trough). By aligning these peak-to-trough measurements with the Trend's direction, users can improve the precision of their entries within a trending market.
🔹 Filtering Fakeouts with the Noise Component
The Noise component helps distinguish between high-conviction moves and market "static." A sharp price breakout accompanied by a relatively flat Noise component suggests a sustainable, structurally supported move. Conversely, if a breakout occurs while the Noise component is spiking aggressively, it may indicate a "washout" or a liquidity-driven fakeout that lacks a fundamental trend shift.
🔶 DETAILS
The script implements a full SSA pipeline: Embedding (creating a trajectory matrix), Singular Value Decomposition (via eigendecomposition of the covariance matrix), and Diagonal Averaging (reconstructed the time series).
🔹 Jump-Free Extrapolation
A common issue with LRR-based forecasts is a vertical "jump" at the connection point between historical data and the forecast. This tool solves this by calculating the relative deltas of the LRR projection and anchoring them to the final value of the smoothed SSA reconstruction. This ensures a seamless visual transition while maintaining the mathematical integrity of the projected trajectory.
🔹 Dashboard Metrics
The indicator includes a real-time dashboard that calculates the "Average Period" of the periodic components using zero-crossing detection. This allows traders to quantify the frequency of cycles (e.g., a 40-bar cycle vs. a 15-bar cycle) without manual measurement.
🔶 SETTINGS
It provides traders with a clear view of underlying market structures and offers a jump-free, extrapolated trend forecast based on Linear Recurrence Relations (LRR).
Warning: This decomposition is displayed retrospectively; historical values observed are subject to repainting.
🔶 USAGE
The indicator operates by analyzing a specific window of recent price data to extract its most significant internal dynamics. It splits the "messy" raw price into four visual layers:
- Trend (Overlay): The primary low-frequency component, plotted directly on the price chart. This represents the core directional bias of the asset.
- Long Term Periodic (P1): The most dominant cyclical component, typically representing major swings or seasonalities.
- Short Term Periodic (P2): The second most dominant cycle, capturing faster oscillations and intermediate pullbacks.
- Noise: The high-frequency residual data that lacks a consistent pattern, useful for identifying market volatility or "washout" periods.
🔹 Cycle Exhaustion (P1/P2 Extremes)
Traders can monitor the separate indicator pane to identify when cyclical components (P1 and P2) reach historical extremes. When the Long Term Periodic (P1) line begins to curve back toward the zero line after a prolonged extension, it often signals "cycle exhaustion," suggesting that the current swing is losing momentum and a reversal or consolidation may be imminent.
🔹 Trend-Forecast Confluence & Mean Reversion
The dashed Trend extrapolation acts as a projected path for the market's core bias. If the current market price is significantly far from the solid Trend line while the forecast indicates a flattening or reversal, traders can look for mean-reversion opportunities. A price returning to a rising Trend forecast confirms the trend's strength, while a price crossing through a flat Trend forecast suggests a structural shift.
🔹 Timing Entries with Dashboard Metrics
The "Average Period" displayed on the dashboard provides a mathematical blueprint for entry timing. For example, if the Short Term (P2) Average Period is 20 bars, a trader might look for long entries approximately 10 bars after a peak (the expected trough). By aligning these peak-to-trough measurements with the Trend's direction, users can improve the precision of their entries within a trending market.
🔹 Filtering Fakeouts with the Noise Component
The Noise component helps distinguish between high-conviction moves and market "static." A sharp price breakout accompanied by a relatively flat Noise component suggests a sustainable, structurally supported move. Conversely, if a breakout occurs while the Noise component is spiking aggressively, it may indicate a "washout" or a liquidity-driven fakeout that lacks a fundamental trend shift.
🔶 DETAILS
The script implements a full SSA pipeline: Embedding (creating a trajectory matrix), Singular Value Decomposition (via eigendecomposition of the covariance matrix), and Diagonal Averaging (reconstructed the time series).
🔹 Jump-Free Extrapolation
A common issue with LRR-based forecasts is a vertical "jump" at the connection point between historical data and the forecast. This tool solves this by calculating the relative deltas of the LRR projection and anchoring them to the final value of the smoothed SSA reconstruction. This ensures a seamless visual transition while maintaining the mathematical integrity of the projected trajectory.
🔹 Dashboard Metrics
The indicator includes a real-time dashboard that calculates the "Average Period" of the periodic components using zero-crossing detection. This allows traders to quantify the frequency of cycles (e.g., a 40-bar cycle vs. a 15-bar cycle) without manual measurement.
🔶 SETTINGS
- Window Length (L): The embedding window. Larger values capture longer cycles and provide a smoother trend, but may increase lag in the decomposition.
- Buffer Length (N): The number of recent bars used for the static decomposition.
- Forecast Length: The number of bars to extrapolate the Trend component into the future.
- Show Trend on Price: Toggles the visibility of the reconstructed trend line on the main chart.
- Show Periodic/Noise: Toggles the visibility of the individual sub-components in the indicator pane.
- Show Extrapolation: Enables or disables the dashed forecast line for the trend.
- Dashboard Settings: Controls the visibility, position, and size of the metrics table.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
Build your own edge with AI: luxalgo.com
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.