OPEN-SOURCE SCRIPT
Updated

Asset Class Correlation Matrix

517
Asset Class Correlation Matrix

█ OVERVIEW

This indicator displays a Pearson correlation matrix for instruments in the asset class of the symbol you are currently viewing. Open a EUR pair and you see the forex matrix. Open gold and you see the metals matrix. Open Bitcoin and you see the crypto matrix. The relevant basket loads automatically, so there is nothing to configure for the common cases.

Each cell shows the rolling correlation between two instruments over a lookback period you control. The goal is to make cross-instrument relationships inside an asset class visible at a glance, rather than checking pairs one at a time, or relying on visual comparison.

snapshot

█ AUTOMATIC ASSET CLASS DETECTION

The current symbol is matched to a category in three stages:

1. Exact ticker match against the built-in lists below.
2. Name-fragment match for common broker and CFD names. For example XAU and GOLD map to Metals, US500, SP500, NAS100, US100, US30 and DJ30 map to US Indices, DAX, FTSE and NIKKEI map to Global Indices, and WTI, BRENT and NATGAS map to Energy.
3. Asset type fallback using the instrument type, covering crypto, forex, and stocks.

If the current symbol is not already part of a built-in list, it is added as the first row and column of the matrix, so the instrument you are on is always included. If no category can be determined, the table shows a short prompt to use the custom symbol list instead of rendering empty.

█ BUILT-IN CATEGORIES

Forex: 28 majors and crosses across USD, EUR, GBP, JPY, AUD, CAD, CHF and NZD.
US Indices: ES, NQ, YM, EMD, RTY.
Global Indices: DAX, Euro Stoxx 50, Nikkei, FTSE, ASX 200, Hang Seng.
Metals: Gold, Silver, Copper, Platinum, Palladium.
Energy: WTI Crude, Natural Gas, Heating Oil, RBOB Gasoline.
Agricultural: Corn, Soybeans, Wheat, Soybean Oil, Soybean Meal, Cocoa, Coffee, Sugar, Cotton, Orange Juice.
Livestock: Live Cattle, Lean Hogs, Feeder Cattle.
Interest Rates: 2Y, 10Y, 30Y US notes, Euro Bund, Euro Buxl.
Crypto: BTC, ETH, BCH, LTC.
Stocks: SPX, QQQ, AAPL, MSFT, NVDA, AMZN, GOOGL, META, TSLA, AMD.

█ READING THE MATRIX

Pearson correlation ranges from -1 to +1.

Values near +1 mean the two instruments move strongly together. Values near -1 mean they move strongly opposite to each other, which is still a strong relationship, just inverted. Values near 0 mean little to no linear relationship.

The strength of a relationship is the distance from zero, in either direction. A reading of -0.9 is just as tight as +0.9.

█ COLORS

Positive correlation is shown in green, with a stronger shade above the high threshold and a lighter shade above the moderate threshold. Inverse correlation is shown in purple, using the same two strength levels. Everything between the negative and positive moderate threshold is shown as low. All five colors and both thresholds are adjustable in the settings. The thresholds apply symmetrically to positive and inverse values.

█ CUSTOM SYMBOL LIST

You can override the auto-detected basket with your own comma-separated list of symbols. Spaces are ignored. The custom list is applied only when the current chart symbol is one of the symbols in the list, which keeps the chart instrument anchored in the matrix.

You can include an exchange or broker prefix, for example OANDA:EURUSD. A bare ticker such as GBPJPY inherits the current chart prefix. Bare futures contracts such as ES1! resolve on their native exchange.

█ SETTINGS

Period: lookback in bars for the correlation calculation. Shorter reacts faster and is noisier. Longer is more stable and slower to update.
High and Moderate Correlation Thresholds: the cutoffs for the color bands.
Colors: the five correlation colors.
Symbol List: the optional custom basket.
Table Size: text size of the matrix.

█ HOW TO USE IT

Add the indicator to any chart in a supported asset class. Use it to find pairs that move together or opposite each other, to check diversification across a basket, to spot when a normally correlated pair is diverging, or to choose hedges and pairs-trade candidates. The left column shows the full applied symbol for each row, so you can confirm exactly which feed each value comes from.

█ NOTES AND LIMITATIONS

Correlation is period-dependent. For tightly linked instruments, a long lookback pushes most values toward the extremes, while a short lookback spreads them out and reacts faster. Choose the period to match the question you are asking.

Correlation measures linear co-movement of closing prices on the chart timeframe. It does not imply causation and does not capture non-linear relationships.

Broker naming for CFDs varies widely, so some instruments may not auto-detect. When that happens, use the custom symbol list.

A maximum of 28 instruments can be loaded in one matrix.
Release Notes
Correlation is now calculated on returns instead of raw price. Price-based correlation reads high whenever two assets trend in the same direction, even when their bar-to-bar moves are unrelated, which overstates how connected they are. Calculating on returns removes that distortion and measures how the instruments actually move relative to each other. Existing values will read lower than before, which is expected and correct.

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.