PROTECTED SOURCE SCRIPT

Assets Correlation Analyzer

88
Assets Correlation Analyzer

---------------------------------------------
What is it?
The Assets Correlation Analyzer is a technical indicator that measures and visualizes the statistical relationship between any two financial assets (a 'Base Asset' vs. a 'Comparison Asset', example Gold vs. SPY or Nasdaq vs. Bitcoin). The indicator calculates dynamic correlation tracking using statistical methods, confidence intervals, and category-wide analysis capabilities.

---------------------------------------------
Why was it built? / Potential Benefits

This indicator was developed to help analyze inter-asset relationships in portfolio management and trading strategies. The indicator can be used for:
  • Risk Assessment: Identify when assets begin moving together
  • Diversification Analysis: Monitor portfolio component relationships
  • Pairs Trading: Identify when correlated assets diverge
  • Market Analysis: Recognize shifts in market conditions through correlation patterns
  • Asset Analysis: Support decision-making based on correlation dynamics
  • Hedging Analysis: Identify relationships between different instruments


---------------------------------------------
How it Works

The indicator employs established statistical methods to calculate rolling correlations between two selected assets:

  • Data Collection: Retrieves price data for both selected assets using TradingView's security function
  • Returns Calculation: Computes logarithmic or simple returns based on user preference
  • Outlier Filtering: Optionally removes extreme price movements (beyond 2.5 standard deviations) to improve accuracy
  • Correlation Computation: Calculates either Pearson or Spearman rank correlation over the specified period
  • Signal Generation: Applies smoothing and generates a signal line (EMA) for momentum detection
  • Confidence Assessment: Evaluates data quality and provides confidence metrics

---------------------------------------------
How to Read the Oscillator
Main Correlation Line
Values Range: -1.0 to +1.0
  • +1.0: Perfect positive correlation (assets move identically)
  • +0.7 to +0.99: Strong positive correlation
  • +0.3 to +0.69: Moderate positive correlation
  • -0.3 to +0.29: Weak/No significant correlation
  • -0.69 to -0.31: Moderate negative correlation
  • -0.99 to -0.7: Strong negative correlation
  • -1.0: Perfect negative correlation (assets move oppositely)

Color Coding System
  • Green shades: Positive correlation levels, with brighter green indicating stronger positive correlation
  • Red shades: Negative correlation levels, with brighter red indicating stronger negative correlation
  • Gray: Insufficient data or transitional periods
  • The color intensity reflects both correlation strength and momentum relative to the signal line.

Signal Line (Gray)
The EMA-based signal line helps identify momentum changes:
  • Correlation above signal: Positive momentum in correlation
  • Correlation below signal: Negative momentum in correlation
  • Crossovers: Potential turning points in the relationship

Background Fills
Gradient fills provide a quick visual assessment of correlation strength, with intensity indicating the degree of correlation.

---------------------------------------------
Correlation Calculation Methods and Options

Calculation Methods

Spearman Rank Correlation (Default)
  • Uses ranked values rather than raw prices
  • Less sensitive to outliers and non-linear relationships
  • Suitable for volatile or non-normally distributed assets


Pearson Correlation (Traditional)
  • Standard linear correlation method
  • More sensitive to outliers
  • Suitable for assets with normal distribution patterns


---------------------------------------------
Customization Options

  • Correlation Period (7-500 bars): Determines the lookback window for calculation
  • Signal Line Period (1-200 bars): Controls the smoothing of the signal line
  • Outlier Removal: Automatically filters extreme price movements
  • Return Type: Choose between logarithmic (recommended) or simple returns
  • Smoothing Period: Reduces noise in correlation readings


---------------------------------------------
Asset Categories

The indicator includes 80+ pre-configured assets across multiple categories:
  • Metals: Gold, Silver, Copper, Platinum, Palladium, Nickel, Zinc, Aluminum
  • Energy: WTI/Brent Crude, Natural Gas, Uranium
  • Agriculture: Corn, Soybeans, Wheat, Coffee
  • ETFs: Major indices, sector, geographic, and specialty ETFs
  • Bonds: Government and corporate bond instruments
  • Financial: Currency pairs, treasury yields, volatility indices
  • Cryptocurrencies: Major digital assets and market cap indices
  • Real Estate: REITs and real estate focused instruments


---------------------------------------------
For Whom This Indicator Is Designed

Intended Users
  • Portfolio Managers: Asset allocation and risk assessment
  • Quantitative Traders: Correlation-based strategy development
  • Risk Analysts: Correlation monitoring and analysis
  • Institutional Investors: Diversification analysis
  • Active Traders: Pairs trading and arbitrage analysis


Skill Level
  • Intermediate to Advanced: Requires understanding of correlation concepts and statistical interpretation
  • Experience with Statistics: Users should be familiar with correlation analysis concepts


---------------------------------------------
Information Tables

Main Analysis Table
Displays current correlation value, data confidence percentage, and selected asset information.

Category Correlation Table
Shows correlation strength between the selected 'Base Asset' (in the chart, Gold) and all assets in the comparison asset's category.

---------------------------------------------
Alert Conditions

Four built-in alert types:

  • Strong Stable Positive Correlation: Triggers when correlation exceeds +0.8 with low volatility
  • Strong Stable Negative Correlation: Triggers when correlation falls below -0.8 with low volatility
  • Bullish Correlation Momentum: Signals when correlation crosses above the signal line
  • Bearish Correlation Momentum: Signals when correlation crosses below the signal line


---------------------------------------------
Usage Notes

  • Longer periods (30-50 bars) provide more stable analysis
  • Shorter periods (10-20 bars) provide more responsive signals
  • Monitor confidence levels - correlations with <75% confidence should be interpreted cautiously
  • Correlations tend to increase during market stress periods
  • Should be used in conjunction with other analysis tools


---------------------------------------------
Important Disclaimer

This indicator is for educational and informational purposes only. It should not be considered as financial advice or a recommendation to buy, sell, or hold any financial instrument. Past correlation patterns do not guarantee future relationships between assets. Users should conduct their own research and consider consulting with a qualified financial advisor before making investment decisions. Trading and investing involve substantial risk of loss, and correlation analysis cannot eliminate these risks. The accuracy of correlation calculations depends on data quality and market conditions, which can change rapidly.

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.