PINE LIBRARY
AssetCorrelationUtils

- Open source Library Used for Indicators that utilize correlation between assets for divergence calculations. It has no drawing elements.
ASSET CORRELATION UTILS
PineScript library for automatic detection of correlated asset pairs and triads for multi-asset analysis.
WHAT IT DOES
This library automatically identifies correlated assets based on the current chart symbol. It returns properly configured asset pairings for use in SMT divergence detection, inter-market analysis, and multi-asset comparison tools.
HOW IT WORKS
The library matches your chart symbol against known correlation groups:
- Index Futures: NQ/ES/YM/RTY triads (including micros)
- Metals: Gold/Silver/Copper triads (futures and CFD)
- Forex: EUR/GBP/DXY and USD/JPY/CHF triads
- Energy: Crude/Gasoline/Heating Oil triads
- Treasury: ZB/ZF/ZN bond triads
- Crypto: BTC/ETH/TOTAL3 and major altcoin pairings
Inversion flags are automatically computed for assets that move inversely (e.g., DXY vs EUR pairs).
HOW TO USE
import fstarcapital/AssetCorrelationUtils/1 as acu
// Simple: auto-detect from current chart
config = acu.resolveCurrentChart()
// Access resolved assets
primary = config.primary
secondary = config.secondary
tertiary = config.tertiary
EXPORTED FUNCTIONS
- resolveCurrentChart(): One-call auto-detection using chart syminfo
- resolveAssets(): Full detection with custom parameters
- resolveTriad() / resolveDyad(): Manual resolution with inversion logic
- detect*() functions: Category-specific detectors for custom workflows
TYPES
- AssetPairing: Core structure for primary/secondary/tertiary tickers with inversion flags
- AssetConfig: Full resolution result with detection status and asset category
DISCLAIMER
This library is a utility for building multi-asset indicators. Asset correlations are not guaranteed and may change over time. Always validate pairings for your specific trading context.
Full Default Function type and Field descriptions below.
Library "AssetCorrelationUtils"
detectIndicesFutures(ticker)
Detects Index Futures (NQ/ES/YM/RTY + micro variants)
Parameters:
ticker (string): The ticker string to check (typically syminfo.ticker)
Returns: AssetPairing with secondary and tertiary assets configured
detectMetalsFutures(ticker)
Detects Metal Futures (GC/SI/HG + micro variants)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectForexFutures(ticker)
Detects Forex Futures (6E/6B + micro variants)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectEnergyFutures(ticker)
Detects Energy Futures (CL/RB/HO + micro variants)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectTreasuryFutures(ticker)
Detects Treasury Futures (ZB/ZF/ZN)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectCryptoFutures(ticker)
Detects CME Crypto Futures (BTC/ETH + micro variants)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectCADFutures(ticker)
Detects CAD Forex Futures (6C + micro variants)
Parameters:
ticker (string): The ticker string to check
Returns: AssetPairing with secondary and tertiary assets configured
detectForexCFD(ticker, tickerId)
Detects Forex CFD pairs (EUR/GBP/DXY, USD/JPY/CHF triads)
Parameters:
ticker (string): The ticker string to check
tickerId (string): The full ticker ID (syminfo.tickerid) for primary asset
Returns: AssetPairing with secondary and tertiary assets configured
detectCrypto(ticker, tickerId)
Detects major Crypto assets (BTC, ETH, SOL, XRP, alts)
Parameters:
ticker (string): The ticker string to check
tickerId (string): The full ticker ID for primary asset
Returns: AssetPairing with secondary and tertiary assets configured
detectMetalsCFD(ticker, tickerId)
Detects Metals CFD (XAU/XAG/Copper)
Parameters:
ticker (string): The ticker string to check
tickerId (string): The full ticker ID for primary asset
Returns: AssetPairing with secondary and tertiary assets configured
detectIndicesCFD(ticker, tickerId)
Detects Indices CFD (NAS100/SP500/DJ30)
Parameters:
ticker (string): The ticker string to check
tickerId (string): The full ticker ID for primary asset
Returns: AssetPairing with secondary and tertiary assets configured
detectEUStocks(ticker, tickerId)
Detects EU Stock Indices (GER40/EU50) - Dyad only
Parameters:
ticker (string): The ticker string to check
tickerId (string): The full ticker ID for primary asset
Returns: AssetPairing with secondary asset configured (tertiary empty for dyad)
getDefaultFallback(tickerId)
Returns default fallback assets (chart ticker only, no correlation)
Parameters:
tickerId (string): The full ticker ID for primary asset
Returns: AssetPairing with chart ticker as primary, empty secondary/tertiary (no correlation)
applySessionModifierWithBackadjust(tickerStr, sessionType)
Applies futures session modifier to ticker WITH back adjustment
Parameters:
tickerStr (string): The ticker to modify
sessionType (string): The session type (syminfo.session)
Returns: Modified ticker string with session and backadjustment.on applied
applySessionModifierNoBackadjust(tickerStr, sessionType)
Applies futures session modifier to ticker WITHOUT back adjustment
Parameters:
tickerStr (string): The ticker to modify
sessionType (string): The session type (syminfo.session)
Returns: Modified ticker string with session and backadjustment.off applied
isTriadMode(pairing)
Checks if a pairing represents a valid triad (3 assets)
Parameters:
pairing (AssetPairing): The AssetPairing to check
Returns: True if tertiary is non-empty (triad mode), false for dyad
getAssetTicker(tickerId)
Extracts clean ticker string from full ticker ID
Parameters:
tickerId (string): The full ticker ID (e.g., "BITGET:BTCUSDT.P")
Returns: Clean ticker string (e.g., "BTCUSDT.P")
resolveTriad(chartTickerId, pairing)
Resolves triad asset assignments with proper inversion flags
Parameters:
chartTickerId (string): The current chart's ticker ID (syminfo.tickerid)
pairing (AssetPairing): The detected AssetPairing
Returns: Tuple [primaryAsset, secondaryAsset, tertiaryAsset, invertSecondary, invertTertiary]
resolveDyad(chartTickerId, pairing)
Resolves dyad asset assignment with proper inversion flag
Parameters:
chartTickerId (string): The current chart's ticker ID
pairing (AssetPairing): The detected AssetPairing (dyad: tertiary is empty)
Returns: Tuple [primaryAsset, secondaryAsset, invertSecondary]
resolveAssets(ticker, tickerId, assetType, sessionType, useBackadjust)
Main auto-detection entry point. Detects asset category and returns fully resolved config.
Parameters:
ticker (string): The ticker string to check (typically syminfo.ticker)
tickerId (string): The full ticker ID (typically syminfo.tickerid)
assetType (string): The asset type (typically syminfo.type)
sessionType (string): The session type for futures (typically syminfo.session)
useBackadjust (bool): Whether to apply back adjustment for futures session alignment
Returns: AssetConfig with fully resolved assets, inversion flags, and detection status
resolveCurrentChart()
Simplified auto-detection using current chart's syminfo values
Returns: AssetConfig with fully resolved assets, inversion flags, and detection status
AssetPairing
Core asset pairing structure for triad/dyad configurations
Fields:
primary (series string): The primary (chart) asset ticker ID
secondary (series string): The secondary correlated asset ticker ID
tertiary (series string): The tertiary correlated asset ticker ID (empty for dyad)
invertSecondary (series bool): Whether secondary asset should be inverted for divergence calc
invertTertiary (series bool): Whether tertiary asset should be inverted for divergence calc
AssetConfig
Full asset resolution result with mode detection and computed values
Fields:
detected (series bool): Whether auto-detection succeeded
isTriadMode (series bool): True if triad (3 assets), false if dyad (2 assets)
primary (series string): The resolved primary asset ticker ID
secondary (series string): The resolved secondary asset ticker ID
tertiary (series string): The resolved tertiary asset ticker ID (empty for dyad)
invertSecondary (series bool): Computed inversion flag for secondary asset
invertTertiary (series bool): Computed inversion flag for tertiary asset
assetCategory (series string): String describing the detected asset category
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
For access to my Invite Only Indicators, visit fstarlabs.com
All my tutorials on Tradingview Tips / Tricks and my tools are uploaded on my youtube. I do not upload How-To videos on tradingview for fear of a ban.
All my tutorials on Tradingview Tips / Tricks and my tools are uploaded on my youtube. I do not upload How-To videos on tradingview for fear of a ban.
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
ไลบรารีไพน์
ด้วยเจตนารมณ์หลักของ TradingView ผู้เขียนได้เผยแพร่ Pine code นี้เป็นโอเพนซอร์สไลบรารีเพื่อให้ Pine โปรแกรมเมอร์คนอื่นในชุมชนของเราสามารถนำไปใช้ซ้ำได้ ต้องขอบคุณผู้เขียน! คุณสามารถใช้ไลบรารีนี้ในแบบส่วนตัวหรือในการเผยแพร่แบบโอเพนซอร์สอื่น ๆ แต่การนำโค้ดนี้ไปใช้ในการเผยแพร่ซ้ำจะต้องอยู่ภายใต้ กฎระเบียบการใช้งาน
For access to my Invite Only Indicators, visit fstarlabs.com
All my tutorials on Tradingview Tips / Tricks and my tools are uploaded on my youtube. I do not upload How-To videos on tradingview for fear of a ban.
All my tutorials on Tradingview Tips / Tricks and my tools are uploaded on my youtube. I do not upload How-To videos on tradingview for fear of a ban.
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน