AssetCorrelationUtils

Auto-detection library for correlated asset pairings across futures, CFD, and crypto markets. Given any chart, returns the correct secondary and tertiary (and optionally quaternary) tickers for multi-asset divergence analysis, along with inversion flags and asset-category metadata.
Designed to eliminate the boilerplate of hardcoded ticker lists and manual "if EURUSD then GBPUSD" branching in every indicator that needs correlated data.
What it does
Consumer scripts call one function — resolveCurrentChart() — and receive a fully resolved AssetConfig object describing the current chart's correlated pair or triad. The library handles:
Symbol root extraction from full ticker IDs (with expiry suffixes, exchange prefixes, micro variants)
Asset category routing (futures / CFD / crypto branches)
Family-specific triad or dyad selection
Inversion detection (e.g. 6C inverse of USDCAD, DXY inverse of EUR/GBP)
Futures session and back-adjustment modifiers
Optional GXT mode for metals (currency-cross triads on Gold/Silver)
Optional Quad mode for metals (four-leg configurations)
Micro contracts always resolve to their higher-volume full-size correlated partners — MNQ correlates against ES/YM, not MES/MYM — matching the "trade the micros, read the majors" convention.
Supported asset classes
Futures
Indices: NQ, ES, YM, RTY + micros (MNQ, MES, MYM, M2K)
Metals: GC, SI, HG + micros (MGC, SIL, MHG)
Forex: 6E, 6B, 6A, 6N, 6C + micros (M6E, M6B, M6A, M6C)
Energy: CL, RB, HO + micros (MCL, MRB, MHO)
Treasury: ZB, ZF, ZN
Crypto: BTC, ETH + micros (MBT, MET)
CFD / Spot
Forex: EURUSD, GBPUSD, DXY, USDJPY, USDCHF, USDCAD
Metals: XAUUSD, XAGUSD, COPPER + cross-pairs (XAUEUR, XAUGBP, XAGEUR, XAGGBP)
Indices: NAS100, SP500, DJ30
EU Stocks: GER40, EU50 (dyad only)
Crypto (spot / perp)
Major: BTC, ETH, SOL, XRP
Alt: ZEC, DOGE, ADA, BNB, TAO
All routed via BINANCE perpetual (.P) pairs for consistent OHLC quality
Core functions
resolveCurrentChart(gxtMode = false, quadMode = false)
The one-liner entry point for most consumers. Wraps resolveAssets() with sensible defaults (uses syminfo.ticker, syminfo.tickerid, syminfo.type, syminfo.session, back-adjustment on).
resolveAssets(ticker, tickerId, assetType, session, useBackadjust, gxtMode, quadMode)
The full-control entry point. Same detection logic, but with explicit control over back-adjustment and session modification — useful for indicators with a strategy toggle (e.g. RTH vs ETH sessions).
Category detectors
detectIndicesFutures(ticker)
detectMetalsFutures(ticker) / detectMetalsFuturesGxt(ticker) / detectMetalsFuturesQuad(ticker)
detectForexFutures(ticker) / detectCADFutures(ticker)
detectEnergyFutures(ticker)
detectTreasuryFutures(ticker)
detectCryptoFutures(ticker)
detectForexCFD(ticker, tickerId)
detectCrypto(ticker, tickerId)
detectMetalsCFD(ticker, tickerId) / detectMetalsCFDGxt(ticker, tickerId) / detectMetalsCFDQuad(ticker, tickerId)
detectIndicesCFD(ticker, tickerId)
detectEUStocks(ticker, tickerId)
Each returns an AssetPairing — usable directly if you want to bypass the automatic category routing.
Resolution helpers
resolveTriad(chartTickerId, pairing) — returns primary + secondary + tertiary with inversion flags
resolveDyad(chartTickerId, pairing) — returns primary + secondary for two-asset configs
resolveQuad(chartTickerId, pairing) — returns four-asset config with inversion flags
Utility functions
applySessionModifierWithBackadjust(ticker, session) / applySessionModifierNoBackadjust(ticker, session) — apply ticker.modify with back-adjustment on or off
isTriadMode(pairing) — check whether a pairing has a valid tertiary
getAssetTicker(tickerId) — extract the clean ticker string from a full ticker ID
Fallback
getDefaultFallback(tickerId) — returns a pairing with the chart ticker as primary and empty secondaries. Used automatically when no category matches.
Return types
AssetConfig
detected (bool) — true if the chart asset was recognized
isTriadMode (bool) — true if 3 assets resolved, false for dyad
isQuadMode (bool) — true if 4 assets resolved
primary (string) — resolved primary ticker ID
secondary (string) — resolved secondary ticker ID
tertiary (string) — resolved tertiary ticker ID (empty for dyad)
quaternary (string) — resolved quaternary ticker ID (empty unless quad mode)
invertSecondary (bool)
invertTertiary (bool)
invertQuaternary (bool)
assetCategory (string) — category tag (e.g. "index_futures", "metal_cfd_gxt")
AssetPairing
Internal pairing structure used by detector functions. Consumers rarely construct this directly, but resolveTriad / resolveDyad / resolveQuad accept it if you're bypassing the auto-routing.
Quick start
import I_quacker_I/AssetCorrelationUtils/7 as AC
AC.AssetConfig config = AC.resolveCurrentChart()
string secondary = config.secondary
string tertiary = config.tertiary
bool inv2 = config.invertSecondary
bool inv3 = config.invertTertiary
bool detected = config.detected
For metals with currency-cross triads:
AC.AssetConfig config = AC.resolveCurrentChart(true)
// On Gold: secondary = "FOREXCOM:XAUEUR", tertiary = "FOREXCOM:XAUGBP"
// On Copper or non-metals: identical to resolveCurrentChart(false)
Full integration patterns (Off / Auto / Manual tri-state, explicit back-adjust control, and manual pairing) are documented inline in the library source.
Design notes
Robust ticker matching. All detectors use str.contains() on the root symbol, so any ticker format is recognized — bare (NQ), continuous (NQ1!), or dated with expiry (NQZ2025). Exchange prefixes are ignored during detection.
Consistent inversion semantics. DXY as the third leg of USD-base forex triads is marked inverted (rises when the pair falls). 6C as USDCAD's futures counterpart is fully inverted. Micros carry their parent's inversion flags unchanged.
Category tags. Every resolved AssetConfig carries an assetCategory string ("index_futures", "metal_cfd_gxt", "crypto", "fallback", etc.). Useful for consumer scripts that want to conditionally enable features per category (e.g. "only compute GXT confluence on metals").
Fallback safety. When no category matches, the library returns the chart ticker as primary with empty secondary / tertiary, detected = false, and assetCategory = "fallback". Consumer scripts should check detected before assuming correlated data is available.
Credits
Original library concept — fstarcapital
Modifications and extensions — I_quacker_I [QKR]
Crypto remapped to BINANCE .P perpetuals
Micro contracts always correlate against higher-volume mini/full contracts
AUD/NZD forex futures family (6A, M6A, 6N)
GXT mode for metals (currency-cross triads)
Quad mode for four-leg metal configurations
Crypto tertiary swapped from TOTAL3 (market-cap index, no clean OHLC) to XRP (tradeable asset with proper sweep behavior)
License: Mozilla Public License 2.0
Perpustakaan pine
Dengan semangat TradingView yang sesungguhnya, penulis telah menerbitkan kode Pine ini sebagai pustaka sumber terbuka agar programmer Pine lain dari komunitas kami dapat menggunakannya kembali. Salut untuk penulis! Anda dapat menggunakan pustaka ini secara pribadi atau dalam publikasi sumber terbuka lainnya, tetapi penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib.
Pernyataan Penyangkalan
Perpustakaan pine
Dengan semangat TradingView yang sesungguhnya, penulis telah menerbitkan kode Pine ini sebagai pustaka sumber terbuka agar programmer Pine lain dari komunitas kami dapat menggunakannya kembali. Salut untuk penulis! Anda dapat menggunakan pustaka ini secara pribadi atau dalam publikasi sumber terbuka lainnya, tetapi penggunaan kembali kode ini dalam publikasi diatur oleh Tata Tertib.