Correlation Table

Chart-Based Correlation: Correlations are calculated based on the asset you have loaded in your chart, providing relevant insights for your current market focus.
Configurable Pairs: Choose from a list of 32 symbols (e.g., AUDUSD, EURUSD, GBPUSD, etc.) with individual checkboxes to include or exclude each pair in the correlation analysis.
Custom Correlation Length: Adjust the lookback period for the correlation calculation to suit your analysis needs.
Optional EMA Smoothing: Enable an Exponential Moving Average (EMA) on the price data, with a configurable EMA length, to smooth the series before calculating correlations.
Color-Coded Output: The table cells change color based on the correlation strength and direction—neutral, bullish (green), or bearish (red)—making it easy to interpret at a glance.
Clear Table Layout: The indicator outputs a neatly organized vertical table with headers for "Pair" and "Correlation," ensuring the information is displayed cleanly and is easy to understand.
Ideal for traders who want a quick visual overview of how different instruments correlate with their current asset, this tool supports informed multi-asset analysis
ITALIANO:
Questo indicatore visualizza una tabella verticale che mostra la correlazione tra l'asset attualmente caricato sul grafico e fino a 32 coppie di trading selezionate. Offre le seguenti funzionalità:
Correlazione basata sul grafico: le correlazioni vengono calcolate in base all'asset caricato nel grafico, fornendo informazioni pertinenti per il tuo attuale focus di mercato.
Coppie configurabili: scegli da un elenco di 32 simboli (ad esempio, AUDUSD, EURUSD, GBPUSD, ecc.) con caselle di controllo individuali per includere o escludere ciascuna coppia nell'analisi della correlazione.
Lunghezza di correlazione personalizzata: regola il periodo di lookback per il calcolo della correlazione in base alle tue esigenze di analisi.
Smoothing EMA opzionale: abilita una media mobile esponenziale (EMA) sui dati dei prezzi, con una lunghezza EMA configurabile, per smussare la serie prima di calcolare le correlazioni.
Output codificato a colori: le celle della tabella cambiano colore in base alla forza e alla direzione della correlazione, neutra, rialzista (verde) o ribassista (rosso), rendendola facile da interpretare a colpo d'occhio.
Clear Table Layout: l'indicatore genera una tabella verticale ordinatamente organizzata con intestazioni per "Coppia" e "Correlazione", assicurando che le informazioni siano visualizzate in modo chiaro e siano facili da comprendere.
Ideale per i trader che desiderano una rapida panoramica visiva di come diversi strumenti siano correlati con il loro asset corrente, questo strumento supporta un'analisi multi-asset informata
Optimized Default Pairs:
Set 11 major forex pairs as active by default:
-EURUSD
-USDCHF
-USDCAD
-NZDJPY
-AUDJPY
-NZDUSD
-AUDUSD
-GBPJPY
-GBPUSD
-USDJPY
-CADJPY
Other pairs available but disabled by default
Sort System:
Added the ability to sort correlations in:
-Ascending order
-Descending order
-Custom order (default)
-Fixed the ConcurrentModificationException issue in sorting
Improved Documentation:
-Added bilingual tooltip (Italian/English) for the Correlation Length parameter
-Clear explanation of how the correlation calculation works
-Practical example with timeframes (e.g. M5 with 50 periods = 250 minutes)
User Interface:
-Cleaner and more organized layout
-View options customizable for each pair
-Adjustable table size (Large, Medium, Small)
These improvements make the indicator more user-friendly and functional for analyzing correlations between forex pairs.
- Moved array declaration outside the "if" block
- Added "array.clear()" to clear arrays before filling them
- Removed "var" from array declaration inside the block
1. **New Sorting Approach**:
if sortType != 'Personalizzato'
n = array.size(pairs)
sorted = array.new<PairData>() // Create a new array instead of modifying the existing one
// First copy all values
for i = 0 to n - 1
array.push(sorted, array.get(pairs, i))
- Instead of modifying the original array, we create a new `sorted` array
- first copy all values into this new array
- This prevents modifications to the array while we're reading it
2. **Improved Sorting Algorithm**:
for i = 0 to n - 2
minIdx = i
for j = i + 1 to n - 1
curr = array.get(sorted, minIdx)
next = array.get(sorted, j)
shouldSwap = sortType == 'Crescente' ? curr.correlation > next.correlation : curr.correlation < next.correlation
if shouldSwap
minIdx := j
- implemented selection sort instead of bubble sort
- This algorithm is more stable because it makes fewer swaps
- keep track of the minimum index instead of continuously swapping elements
3. **Safer Swap Management**:
temp = array.get(sorted, i)
array.set(sorted, i, array.get(sorted, minIdx))
array.set(sorted, minIdx, temp)
- Swaps are only made when necessary (minIdx != i)
- use a temporary variable for swapping
- This makes the operation safer and prevents data corruption
4. **Clearer Data Flow**:
pairs = get_pairs_data() // 1. Get data
sorted_pairs = sort_pairs(pairs) // 2. Sort data safely
update_table(sorted_pairs) // 3. Update table with sorted data
- made the data flow clearer
- Each operation has a specific and well-defined purpose
- The original array remains intact while we work on a sorted copy
These changes have made the code more stable because:
- We avoid concurrent modifications to arrays
- We use a more robust sorting algorithm
- We maintain a clear separation between original and sorted data
- We reduce the risk of data corruption during sorting
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.
Declinazione di responsabilità
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Per un accesso rapido a un grafico, aggiungi questo script ai tuoi preferiti: per saperne di più clicca qui.