Correlation Matrix

Correlation Matrix is a free indicator by DinexSpace for MT5 and TradingView. A table of correlation coefficients between the symbols you choose.

Download .zipDetailed installation guide35.5 KB · 8 files · no sign-up

What Correlation Matrix does

Correlation Matrix is a free indicator by DinexSpace for MT5 and TradingView. A table of correlation coefficients between the symbols you choose.

Correlation Matrix on an XAUUSD H1 chart in MT5
Correlation Matrix on an XAUUSD H1 chart in MT5

MT5 version

Correlation Matrix shows how closely up to six symbols have moved together. It helps to avoid holding several positions that are really the same bet, and to see when a usual relationship between markets breaks down.

TradingView version

Correlation Matrix shows how closely up to six symbols have moved together. It is useful to avoid holding several positions that are really the same bet, or to see when a usual relationship (for example gold and the dollar index) breaks down.

When to use it

Use it to avoid stacking positions that are really the same bet.

Features and modes

Correlation Matrix has 12 documented features, listed below.

MT5 version

How it works

  • The reference bars are the last N closed bars (60 by default) of the chosen timeframe (D1 by default) on the chart symbol.
  • For each symbol the indicator finds the bar at the same time with iBarShift and takes its return, so symbols with different trading hours are compared on the same moments.
  • It calculates the Pearson correlation for every pair: +1 = moved in the same direction in proportion, −1 = opposite directions, near 0 = no clear linear relation.
  • Values at or beyond the highlight threshold (0.7 by default) are coloured: green for strong positive, aqua for strong negative.
  • Only bars where both symbols have data are used for a pair. Pairs with fewer than five common bars show "n/a".
  • The panel refreshes on a timer (every 30 seconds by default), which is enough for daily or hourly data and keeps the terminal light.

TradingView version

How it works

  • For each symbol, the script takes the return of every closed bar on the chosen timeframe (daily by default).
  • It keeps the last N returns (60 by default) and calculates the Pearson correlation between every pair of symbols.
  • +1 means the two moved in the same direction in proportion, −1 means opposite directions, and values near 0 mean no clear linear relation.
  • Pairs at or beyond the highlight threshold (0.7 by default) are coloured: green for strong positive, aqua for strong negative.
  • Only bars where both symbols have data are used for each pair. A pair with fewer than five common bars shows "n/a".
  • Returns are collected as the chart loads, so a longer chart history gives a fuller window.

Parameters

Correlation Matrix has 12 inputs in the MT5 version and 10 in the TradingView version; every input and its default is listed below.

MT5 version

  • Symbols: up to six broker symbol names; Symbol 1 empty = the chart symbol. Unknown names are skipped with a message in the Experts log.
  • Calculation: timeframe, number of returns, highlight threshold, refresh interval.
  • Display: font size, panel corner.

TradingView version

  • Symbols: up to six, any market (leave a slot empty to skip it).
  • Calculation: timeframe, number of returns, highlight threshold, table position.
Correlation Matrix inputs – MT5 version
InputDefaultLabel in MT5
Symbols (leave empty to skip; use your broker's exact names)
InpSym1""Symbol 1 (empty = chart symbol)
InpSym2"EURUSD"Symbol 2
InpSym3"USDJPY"Symbol 3
InpSym4"GBPUSD"Symbol 4
InpSym5""Symbol 5
InpSym6""Symbol 6
Calculation
InpTfPERIOD_D1Timeframe
InpBars60Bars (returns)
InpStrong0.7Highlight when |r| >=
InpRefresh30Refresh every (seconds)
Display
InpFont9Font size
InpCornerCORNER_RIGHT_UPPERPanel corner
Correlation Matrix inputs – TradingView version
InputDefault
Symbols (leave empty to skip)
Symbol 1"OANDA:XAUUSD"
Symbol 2"OANDA:EURUSD"
Symbol 3"OANDA:USDJPY"
Symbol 4"BITSTAMP:BTCUSD"
Symbol 5"TVC:DXY"
Symbol 6""
Calculation
Timeframe"D"
Bars (returns)60
Highlight when |r| ≥0.7
Table position"Top right"

Signals

Correlation Matrix does not generate buy or sell signals. It is an analysis tool: you read what it plots and make your own decisions.

Alerts

No. Correlation Matrix has no built-in alerts.

Buffers for Expert Advisors

No. Correlation Matrix draws chart objects (lines, boxes, labels or a panel) and has no indicator buffers for EAs.

Timeframes and markets

Correlation Matrix runs on any chart timeframe. Its calculation reads the chart timeframe or a fixed timeframe (for example D1 or a higher timeframe), as described under Features.

Limitations

Correlation Matrix is an analysis tool, not a trading system. Its documented limitations are listed below.

MT5 version

  • To read their history, the symbols are added to Market Watch.
  • Correlation describes the past window only and can change quickly.

The indicator does not trade, give signals or use DLLs or web requests.

TradingView version

  • Symbols with different trading hours (for example crypto and stocks) are compared on the bars of the first symbol's timeframe, so some bars may be missing for one side.
  • Correlation describes the past window only and can change quickly, especially around news.
  • It is a statistic, not a signal. The script does not say when to buy or sell.

This script is an analysis aid only. It does not give trade signals or investment advice.

Pine Script code

Paste the whole script into the Pine Editor on TradingView.

correlation_matrix.pine · 106 lines
//@version=6
// DinexSpace | Correlation Matrix
// A table of correlation coefficients between the returns of up to six symbols you choose, measured over
// the last N closed bars of a timeframe you choose. +1 = the two moved together, −1 = they moved in
// opposite directions, around 0 = no clear relation. It only shows statistics; it gives no trade signals.
// Free and open source. License: MIT. (c) 2026 DinexSpace
indicator("DinexSpace | Correlation Matrix", shorttitle = "DNX Correlation", overlay = true)

// ===== Brand colours =====
C_GREEN = #00FF7F   // SpringGreen: positive
C_AQUA  = #00FFFF   // Aqua: negative
C_GRAY  = #9AA0A6

// ===== Inputs =====
GRP_S  = "Symbols (leave empty to skip)"
s1     = input.symbol("OANDA:XAUUSD", "Symbol 1", group = GRP_S)
s2     = input.symbol("OANDA:EURUSD", "Symbol 2", group = GRP_S)
s3     = input.symbol("OANDA:USDJPY", "Symbol 3", group = GRP_S)
s4     = input.symbol("BITSTAMP:BTCUSD", "Symbol 4", group = GRP_S)
s5     = input.symbol("TVC:DXY", "Symbol 5", group = GRP_S)
s6     = input.symbol("", "Symbol 6", group = GRP_S)

GRP_C  = "Calculation"
tf     = input.timeframe("D", "Timeframe", group = GRP_C)
lenN   = input.int(60, "Bars (returns)", minval = 10, maxval = 500, group = GRP_C)
strong = input.float(0.7, "Highlight when |r| ≥", minval = 0.1, maxval = 1.0, step = 0.05, group = GRP_C)
tblPos = input.string("Top right", "Table position", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group = GRP_C)

// Return of the last closed bar on `tf` for one symbol, plus that bar's time (to update once per bar).
ret(string sym) =>
    float r = na
    int t = na
    if sym != ""
        [c0, c1, t0] = request.security(sym, tf, [close[1], close[2], time[1]], lookahead = barmerge.lookahead_on, ignore_invalid_symbol = true)
        r := na(c0) or na(c1) or c1 == 0 ? na : c0 / c1 - 1
        t := t0
    [r, t]

[r1, t1] = ret(s1)
[r2, t2] = ret(s2)
[r3, t3] = ret(s3)
[r4, t4] = ret(s4)
[r5, t5] = ret(s5)
[r6, t6] = ret(s6)

// One row of returns per closed `tf` bar (keyed on the time of symbol 1, or the first symbol set).
var matrix<float> rets = matrix.new<float>(0, 6)
var int lastT = na
int tKey = nz(t1, nz(t2, nz(t3, nz(t4, nz(t5, t6)))))
if not na(tKey) and tKey != lastT
    lastT := tKey
    rets.add_row(rets.rows(), array.from(r1, r2, r3, r4, r5, r6))
    if rets.rows() > lenN
        rets.remove_row(0)

// Pearson correlation of columns a and b over rows where both are available.
corr(int a, int b) =>
    float sx = 0.0
    float sy = 0.0
    float sxx = 0.0
    float syy = 0.0
    float sxy = 0.0
    int n = 0
    for i = 0 to rets.rows() - 1
        float x = rets.get(i, a)
        float y = rets.get(i, b)
        if not na(x) and not na(y)
            sx += x
            sy += y
            sxx += x * x
            syy += y * y
            sxy += x * y
            n += 1
    float vx = sxx - sx * sx / math.max(n, 1)
    float vy = syy - sy * sy / math.max(n, 1)
    n >= 5 and vx > 0 and vy > 0 ? (sxy - sx * sy / n) / math.sqrt(vx * vy) : na

tPos = switch tblPos
    "Top left"     => position.top_left
    "Bottom right" => position.bottom_right
    "Bottom left"  => position.bottom_left
    => position.top_right
var table tbl = table.new(tPos, 7, 9, bgcolor = color.new(color.black, 10), border_color = color.new(color.gray, 70), border_width = 1)

short(string s) =>
    array<string> parts = str.split(s, ":")
    parts.size() > 1 ? parts.get(1) : s

if barstate.islast and rets.rows() > 0 and (s1 != "" or s2 != "" or s3 != "" or s4 != "" or s5 != "" or s6 != "")
    array<string> syms = array.from(s1, s2, s3, s4, s5, s6)
    array<int> used = array.new<int>()
    for i = 0 to 5
        if syms.get(i) != ""
            used.push(i)
    int m = used.size()
    for a = 0 to m - 1
        string nm = short(syms.get(used.get(a)))
        table.cell(tbl, a + 1, 0, nm, text_color = color.gray, text_size = size.small)
        table.cell(tbl, 0, a + 1, nm, text_color = color.gray, text_size = size.small, text_halign = text.align_left)
        for b = 0 to m - 1
            float r = a == b ? 1.0 : corr(used.get(a), used.get(b))
            color col = na(r) ? C_GRAY : r >= strong ? C_GREEN : r <= -strong ? C_AQUA : color.white
            color bg = na(r) or a == b ? na : r >= strong ? color.new(C_GREEN, 85) : r <= -strong ? color.new(C_AQUA, 85) : na
            table.cell(tbl, b + 1, a + 1, na(r) ? "n/a" : str.tostring(r, "0.00"), text_color = col, bgcolor = bg, text_size = size.small)
    table.cell(tbl, 0, m + 1, tf + " · " + str.tostring(rets.rows()) + " bars", text_color = color.gray, text_size = size.tiny, text_halign = text.align_left)
    table.cell(tbl, 0, m + 2, "DinexSpace", text_color = C_GREEN, text_size = size.tiny, text_halign = text.align_left)

Correlation Matrix FAQ

Correlation Matrix is free, runs on MT5 and TradingView and does not place trades.

Is Correlation Matrix free?

Yes. Correlation Matrix is free to download from this page with no sign-up, and the download includes the full source code.

Which platforms does Correlation Matrix run on?

Correlation Matrix is available for MetaTrader 5 (MQL5) and TradingView (Pine Script v6).

Does Correlation Matrix give buy and sell signals?

Correlation Matrix does not generate buy or sell signals. It is an analysis tool: you read what it plots and make your own decisions.

Does Correlation Matrix have alerts?

No. Correlation Matrix has no built-in alerts.

Can an EA read Correlation Matrix?

No. Correlation Matrix draws chart objects (lines, boxes, labels or a panel) and has no indicator buffers for EAs.

Which timeframes does Correlation Matrix work on?

Correlation Matrix runs on any chart timeframe. Its calculation reads the chart timeframe or a fixed timeframe (for example D1 or a higher timeframe), as described under Features.

Does Correlation Matrix place trades?

No. It is a read-only indicator: it only reads market data and shows the result on the chart or writes it to a file. The source contains no calls that open, close or modify orders.

How do I install Correlation Matrix?

Download the .zip and follow the step-by-step installation guide for MT5 and TradingView: https://indicators.dinexspace.com/install-guide/

Measured win rates (backtest)

Measured (signal-by-signal check against MT5: in progress)

Out of sample on H1: 7 of 17 symbols above break-even after costs.

Swipe sideways to see every timeframe.

Out of sample: 2024-01-01 to 2026-11-16
SymbolM15H1H4D1
AUDUSD–46.0% (n=961; break-even 55.2%)––
AUS200–35.7% (n=56; break-even 56.6%)––
BNB––––
BTCUSD––––
ETHUSD––––
EURUSD–43.9% (n=1555; break-even 53.6%)––
GBPUSD–45.5% (n=1389; break-even 53.7%)––
GER40–57.7% (n=78; break-even 51.3%)––
JP225–54.2% (n=72; break-even 52.5%)––
NAS100–55.8% (n=120; break-even 50.8%)––
NZDUSD–44.5% (n=1012; break-even 56.9%)––
SOLUSD––––
UK100–59.6% (n=52; break-even 54.1%)––
US30–54.3% (n=116; break-even 51.0%)––
US500–59.6% (n=136; break-even 52.1%)––
USDCAD–47.0% (n=713; break-even 55.6%)––
USDCHF–44.5% (n=1214; break-even 56.0%)––
USDJPY–50.1% (n=531; break-even 53.6%)––
WTI–54.8% (n=42; break-even 50.8%)––
XAGUSD–46.0% (n=113; break-even 54.2%)––
XAUUSD–46.3% (n=82; break-even 51.5%)measured up to 2024-10-16––

No data: HK50, KOSPI

Swipe sideways to see every timeframe.

In sample: through 2023-12-31
SymbolM15H1H4D1
AUDUSD–47.2% (n=1962; break-even 51.3%)––
AUS200–48.8% (n=82; break-even 54.2%)––
BNB––––
BTCUSD––––
ETHUSD––––
EURUSD–46.8% (n=3513; break-even 53.1%)––
GBPUSD–48.8% (n=2124; break-even 51.5%)––
GER40–53.5% (n=71; break-even 50.6%)––
JP225–36.8% (n=76; break-even 50.8%)––
NAS100–49.5% (n=107; break-even 50.5%)––
NZDUSD–43.8% (n=1872; break-even 52.2%)––
SOLUSD––––
UK100–46.9% (n=32; break-even 50.0%)––
US30–58.7% (n=150; break-even 50.5%)––
US500–51.6% (n=157; break-even 51.0%)––
USDCAD–47.1% (n=1162; break-even 51.0%)––
USDCHF–46.2% (n=2792; break-even 52.5%)––
USDJPY–49.5% (n=813; break-even 53.0%)––
WTI––––
XAGUSD–46.1% (n=536; break-even 54.6%)––
XAUUSD–49.3% (n=716; break-even 50.8%)––

No data: HK50, KOSPI

Also measured: 1:2 and 1:3 TP win rates
Also measured: 1:2 and 1:3 TP win rates
Sample · symbol · timeframe1:21:3
Out of sample: 2024-01-01 to 2026-11-16 · AUDUSD · H131.0%23.0%
Out of sample: 2024-01-01 to 2026-11-16 · AUS200 · H123.2%21.4%
Out of sample: 2024-01-01 to 2026-11-16 · EURUSD · H130.0%23.0%
Out of sample: 2024-01-01 to 2026-11-16 · GBPUSD · H130.2%24.6%
Out of sample: 2024-01-01 to 2026-11-16 · GER40 · H150.0%44.9%
Out of sample: 2024-01-01 to 2026-11-16 · JP225 · H141.7%25.0%
Out of sample: 2024-01-01 to 2026-11-16 · NAS100 · H139.2%29.2%
Out of sample: 2024-01-01 to 2026-11-16 · NZDUSD · H129.5%22.5%
Out of sample: 2024-01-01 to 2026-11-16 · UK100 · H144.2%34.6%
Out of sample: 2024-01-01 to 2026-11-16 · US30 · H137.1%29.3%
Out of sample: 2024-01-01 to 2026-11-16 · US500 · H139.0%33.1%
Out of sample: 2024-01-01 to 2026-11-16 · USDCAD · H130.4%22.0%
Out of sample: 2024-01-01 to 2026-11-16 · USDCHF · H130.4%23.0%
Out of sample: 2024-01-01 to 2026-11-16 · USDJPY · H135.0%26.6%
Out of sample: 2024-01-01 to 2026-11-16 · WTI · H135.7%21.4%
Out of sample: 2024-01-01 to 2026-11-16 · XAGUSD · H130.1%22.3%
Out of sample: 2024-01-01 to 2026-11-16 · XAUUSD · H130.5%19.5%
In sample: through 2023-12-31 · AUDUSD · H131.4%23.2%
In sample: through 2023-12-31 · AUS200 · H137.8%30.5%
In sample: through 2023-12-31 · EURUSD · H130.9%23.6%
In sample: through 2023-12-31 · GBPUSD · H132.6%23.8%
In sample: through 2023-12-31 · GER40 · H139.4%35.2%
In sample: through 2023-12-31 · JP225 · H126.3%21.1%
In sample: through 2023-12-31 · NAS100 · H128.0%23.4%
In sample: through 2023-12-31 · NZDUSD · H128.4%21.1%
In sample: through 2023-12-31 · UK100 · H140.6%28.1%
In sample: through 2023-12-31 · US30 · H138.7%30.0%
In sample: through 2023-12-31 · US500 · H131.2%26.1%
In sample: through 2023-12-31 · USDCAD · H129.0%20.2%
In sample: through 2023-12-31 · USDCHF · H130.5%22.3%
In sample: through 2023-12-31 · USDJPY · H133.8%26.8%
In sample: through 2023-12-31 · XAGUSD · H130.2%25.0%
In sample: through 2023-12-31 · XAUUSD · H133.9%26.4%

What counts as a win

  • W1: take profit before stop loss. Stop loss = 1.5 × ATR(14) Wilder of the signal bar; shown take profit = 1 × stop loss (1:1). Entry is at the signal bar close. Buy pays the spread at entry; sell pays it at exit. If stop loss and take profit occur in the same M15 bar, count a loss. No result within 200 bars is not counted.
  • W2 direction after 5, 10 and 20 bars is measured too.
  • Default inputs require confluence ≥ 4/7.
  • In sample: first bar to 2023-12-31; out of sample: 2024-01-01 to 2026-11-16.
  • Costs: Real spread of an ECN-type MT5 account, no commission.
  • Data source: MT5 tick data (BNB: Binance spot).
  • Cells with fewer than 30 signals show –.

TradingView H4/D1 bars may follow the exchange time zone of the TradingView symbol, not the MT5 server time (UTC) used for the measurement; sessions and the H4 trend may differ on the Pine version. Same signals on TradingView not checked yet.

Arrows show measured rates for each market.

What this version adds

  • Standard Correlation versions on MT5 or TradingView do not show a measured win rate for their signals.
  • Every arrow shows its measured win rate, e.g. "Buy 1:1 49% (n=354)" on XAUUSD H1 buys. Measured on 20 MT5 symbols + BNB, M15 to D1, in and out of sample.
  • Signals on closed bars only; 7-factor confluence score, by default only signals scoring 4/7 or more.
  • ATR-based SL/TP suggestions, per-bar odds, standard buffers for EAs, one alert per closed bar.
  • On gold: GII panel and an optional GII side filter (off by default: GII is not validated yet).

Past test statistics are not a promise of future results.

More in this category

All Risk Management indicators

ATR Stop Levels

Risk Management · Indicator

Plots reference stop-loss levels at ATR multiples above and below price. Use it to size stops by volatility instead of a fixed number of pips.

FreeMT5TradingViewMeasured

Drawdown Monitor

Risk Management · Indicator

Tracks drawdown from the peak: price drawdown on TradingView, account drawdown on MT5. Use it to know when to cut your position size.

FreeMT5TradingViewFilter tool

Lot Size Script

Risk Management · MT5 Script

An MT5 script that calculates lot size from your risk percentage and stop distance. Use it before every trade so you never risk more than you planned.

FreeMT5Uses SuperTrend

Risk-to-Lot Calculator

Risk Management · Indicator

Works out position size from the amount you are willing to lose and your stop-loss level. The MT5 version reads the symbol's real contract specifications and never places an order.

FreeMT5TradingViewUses SuperTrend