PROTECTED SOURCE SCRIPT
Credit Spread Alpha Signal

Credit Spread Alpha Signal: Complete Description
Introduction and Purpose
The Credit Spread Alpha Signal is a custom indicator developed for TradingView, designed to monitor the credit spread between High Yield (HY) bond yields and the 10-Year US Treasury yield (US10Y). This indicator serves as an advanced macroeconomic tool for traders and investors, helping to identify shifts in risk sentiment, monetary policy adjustments, or financial stress in the economy. It combines credit market data with statistical analysis to generate inverted buy and sell signals, where wider spreads (deteriorated conditions) are seen as buy opportunities (green), and tight spreads (risk-on) as sell opportunities (red).
The script is original, inspired by macroeconomic concepts, and visualizes data intuitively with histograms, background colors, and signal arrows. It is particularly useful for portfolio traders seeking confirmation signals or early warnings, integrating seamlessly into charts of stocks, bonds, or crypto assets.
Key Concepts
- HY Spread: Calculated as the difference between the High Yield Corporate Effective Yield (symbol: BAMLH0A0HYM2EY) and the US10Y Yield. Wider spreads indicate higher credit risk and economic deterioration (buy opportunity in the inverted logic). Tight spreads reflect market optimism (risk-on, sell opportunity).
- Inverted Signal Logic: Unlike traditional interpretation, here widening spreads (stress) trigger green and buy arrows (↑ below the chart), suggesting entry into long positions during panics. Compressing spreads trigger red and sell arrows (↓ above the chart), indicating exit during optimism peaks.
- Visual Highlights: Green for spread > +2.2σ (financial stress, buy); Red for spread < low threshold (risk-on, sell); Optional orange for recession risk (inverted curve + high spread, strong buy).
The indicator uses statistics like simple moving average (SMA) and standard deviation for dynamic thresholds, making it adaptable to different market periods.
How It Works: Internal Calculations
1. Data Sources: Uses `request.security` to fetch daily data ("D") from US10Y, US02Y (for inverted curve), and HY Yield.
2. Spread Calculation: `spread_hy = hy_yield - us10y`.
3. Statistics:
- Average (SMA) of the spread over the last `sma_length` days (default: 120).
- Standard deviation (stdev) over the same period.
- High threshold: `avg_spread_hy + std_mult * std_spread_hy` (default: multiplier 2.2).
- Low threshold: Editable value (default: 1.5%).
4. Conditions:
- High stress (green/buy): `spread_hy > high_threshold`.
- Compression (red/sell): `spread_hy < low_threshold`.
- Recession risk (orange/strong buy, optional): Inverted curve (`us10y < us2y`) + spread > `recession_spread_threshold`.
5. Crossings for Signals:
- Buy (green ↑ below): Crossover above high threshold (`ta.crossover`).
- Sell (red ↓ above): Crossunder below low threshold (`ta.crossunder`).
These calculations are processed bar by bar, ensuring real-time updates.
Visual Elements
- Histogram: Plots the spread as columns (`plot.style_columns`), dynamically colored: Light green (90% transparency) for stress/buy; Light red (90%) for compression/sell; Gray for neutral; Orange for recession.
- Reference Line: Horizontal red line at zero for benchmark.
- Background Coloring: Applies color to the main chart (overlay=true via force_overlay): Light green for buy, Light red for sell, Orange for recession, no color for neutral.
- Signal Arrows: ↑ Green below the bar for buy (widening_cross); ↓ Red above the bar for sell (compressed_cross).
- Floating Legend: Label in the lower panel explaining thresholds and conditions, dynamically updated with editable values.
Editable Settings (Inputs)
- SMA Period (days): Default 120; adjusts the horizon for average and standard deviation.
- Standard Deviation Multiplier: Default 2.2; sets sensitivity of the high threshold (e.g., 2.2σ for moderate alerts).
- Low Threshold for Compression (%): Default 1.5; level to detect risk-on/sell.
- Enable Recession Risk?: Default false; activates combined condition of inverted curve + high spread.
- Spread Threshold for Recession (%): Default 2.0; level for recession (visible if enabled).
These inputs allow customization via the TradingView interface, without editing the code.
Integrated Alerts
The indicator includes alert conditions (`alertcondition`) for notifications in TradingView:
- "ALERT: HY Spread High": Spread exceeds threshold - financial stress (Buy).
- "ALERT: HY Spread Compressed": Spread compressed - risk-on conditions (Sell).
- "ALERT: HY Spread Widening (Buy)": Crossover above - buy opportunity in stress.
- "ALERT: HY Spread Compressed (Sell)": Crossunder below - sell opportunity in risk-on.
- "ALERT: Recession Risk (Strong Buy)": Inverted curve + high spread - high recession risk, consider buy (if enabled).
Set up alerts for email, SMS, or webhook notifications.
Usage Tips and Considerations
- Recommended Timeframe: Daily ("D"), but works on others; data is forced to daily for consistency.
- Practical Application: Add to charts of indices like SPY or QQQ to correlate with market moves. Test on historical periods (e.g., 2020 for widening, 2021 for compressing) to validate signals.
- Limitations: Relies on external data (US10Y, HY Yield), which may have delays; spreads are typically positive. Not financial advice – use with complementary analysis.
- Advanced Customization: Adjust thresholds for volatile markets; enable recession for more robust macro signals.
This indicator transforms credit data into actionable alpha, helping navigate economic cycles with visual precision. For support or modifications, refer to the source code or TradingView community.
Introduction and Purpose
The Credit Spread Alpha Signal is a custom indicator developed for TradingView, designed to monitor the credit spread between High Yield (HY) bond yields and the 10-Year US Treasury yield (US10Y). This indicator serves as an advanced macroeconomic tool for traders and investors, helping to identify shifts in risk sentiment, monetary policy adjustments, or financial stress in the economy. It combines credit market data with statistical analysis to generate inverted buy and sell signals, where wider spreads (deteriorated conditions) are seen as buy opportunities (green), and tight spreads (risk-on) as sell opportunities (red).
The script is original, inspired by macroeconomic concepts, and visualizes data intuitively with histograms, background colors, and signal arrows. It is particularly useful for portfolio traders seeking confirmation signals or early warnings, integrating seamlessly into charts of stocks, bonds, or crypto assets.
Key Concepts
- HY Spread: Calculated as the difference between the High Yield Corporate Effective Yield (symbol: BAMLH0A0HYM2EY) and the US10Y Yield. Wider spreads indicate higher credit risk and economic deterioration (buy opportunity in the inverted logic). Tight spreads reflect market optimism (risk-on, sell opportunity).
- Inverted Signal Logic: Unlike traditional interpretation, here widening spreads (stress) trigger green and buy arrows (↑ below the chart), suggesting entry into long positions during panics. Compressing spreads trigger red and sell arrows (↓ above the chart), indicating exit during optimism peaks.
- Visual Highlights: Green for spread > +2.2σ (financial stress, buy); Red for spread < low threshold (risk-on, sell); Optional orange for recession risk (inverted curve + high spread, strong buy).
The indicator uses statistics like simple moving average (SMA) and standard deviation for dynamic thresholds, making it adaptable to different market periods.
How It Works: Internal Calculations
1. Data Sources: Uses `request.security` to fetch daily data ("D") from US10Y, US02Y (for inverted curve), and HY Yield.
2. Spread Calculation: `spread_hy = hy_yield - us10y`.
3. Statistics:
- Average (SMA) of the spread over the last `sma_length` days (default: 120).
- Standard deviation (stdev) over the same period.
- High threshold: `avg_spread_hy + std_mult * std_spread_hy` (default: multiplier 2.2).
- Low threshold: Editable value (default: 1.5%).
4. Conditions:
- High stress (green/buy): `spread_hy > high_threshold`.
- Compression (red/sell): `spread_hy < low_threshold`.
- Recession risk (orange/strong buy, optional): Inverted curve (`us10y < us2y`) + spread > `recession_spread_threshold`.
5. Crossings for Signals:
- Buy (green ↑ below): Crossover above high threshold (`ta.crossover`).
- Sell (red ↓ above): Crossunder below low threshold (`ta.crossunder`).
These calculations are processed bar by bar, ensuring real-time updates.
Visual Elements
- Histogram: Plots the spread as columns (`plot.style_columns`), dynamically colored: Light green (90% transparency) for stress/buy; Light red (90%) for compression/sell; Gray for neutral; Orange for recession.
- Reference Line: Horizontal red line at zero for benchmark.
- Background Coloring: Applies color to the main chart (overlay=true via force_overlay): Light green for buy, Light red for sell, Orange for recession, no color for neutral.
- Signal Arrows: ↑ Green below the bar for buy (widening_cross); ↓ Red above the bar for sell (compressed_cross).
- Floating Legend: Label in the lower panel explaining thresholds and conditions, dynamically updated with editable values.
Editable Settings (Inputs)
- SMA Period (days): Default 120; adjusts the horizon for average and standard deviation.
- Standard Deviation Multiplier: Default 2.2; sets sensitivity of the high threshold (e.g., 2.2σ for moderate alerts).
- Low Threshold for Compression (%): Default 1.5; level to detect risk-on/sell.
- Enable Recession Risk?: Default false; activates combined condition of inverted curve + high spread.
- Spread Threshold for Recession (%): Default 2.0; level for recession (visible if enabled).
These inputs allow customization via the TradingView interface, without editing the code.
Integrated Alerts
The indicator includes alert conditions (`alertcondition`) for notifications in TradingView:
- "ALERT: HY Spread High": Spread exceeds threshold - financial stress (Buy).
- "ALERT: HY Spread Compressed": Spread compressed - risk-on conditions (Sell).
- "ALERT: HY Spread Widening (Buy)": Crossover above - buy opportunity in stress.
- "ALERT: HY Spread Compressed (Sell)": Crossunder below - sell opportunity in risk-on.
- "ALERT: Recession Risk (Strong Buy)": Inverted curve + high spread - high recession risk, consider buy (if enabled).
Set up alerts for email, SMS, or webhook notifications.
Usage Tips and Considerations
- Recommended Timeframe: Daily ("D"), but works on others; data is forced to daily for consistency.
- Practical Application: Add to charts of indices like SPY or QQQ to correlate with market moves. Test on historical periods (e.g., 2020 for widening, 2021 for compressing) to validate signals.
- Limitations: Relies on external data (US10Y, HY Yield), which may have delays; spreads are typically positive. Not financial advice – use with complementary analysis.
- Advanced Customization: Adjust thresholds for volatile markets; enable recession for more robust macro signals.
This indicator transforms credit data into actionable alpha, helping navigate economic cycles with visual precision. For support or modifications, refer to the source code or TradingView community.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Korumalı komut dosyası
Bu komut dosyası kapalı kaynak olarak yayınlanmaktadır. Ancak, özgürce ve herhangi bir sınırlama olmaksızın kullanabilirsiniz – daha fazla bilgi burada.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.