An 8 × 8 table on the chart where each cell is how much the row currency moved against the column currency over the last bars, in %: green when the row currency gained, red when it lost. The last column ranks the eight major currencies by their average move against the seven others.
This code is written in ProRealCode Script and runs with ProRealCode Studio on ProRealTime Web.
A row that is green across the board is a currency being bought against everything; a red one is being sold. The table is symmetric — USD against EUR is the opposite of EUR against USD — so the strongest and the weakest currency, and the pair between them, stand out at a glance.
Paste the code into a new Studio tab and press Ctrl + Enter. The lookback and the colour scale (± %) are fields of the Variables form; widen the scale on longer timeframes.
// ProRealCode Script example — forex matrix
// Seven forex pairs read with MarketData fill an 8 x 8 matrix on the chart:
// each cell is how much the ROW currency moved against the COLUMN currency
// over the lookback, in %, green when it gained and red when it lost.
// The last column ranks the eight by their average move.
DEFPARAM DRAWONLASTBARONLY = True
input(len, 20, "Lookback (bars)", int)
input(span, 0.2, "Colour scale (± %)", float)
// Seven pairs against the US dollar, on the chart's timeframe
eurusd = MarketData("EURUSD", default, close, default)
gbpusd = MarketData("GBPUSD", default, close, default)
audusd = MarketData("AUDUSD", default, close, default)
nzdusd = MarketData("NZDUSD", default, close, default)
usdjpy = MarketData("USDJPY", default, close, default)
usdchf = MarketData("USDCHF", default, close, default)
usdcad = MarketData("USDCAD", default, close, default)
// How many of the seven pairs already have their history (they load one by one)
ready = ISSET(eurusd[len]) + ISSET(gbpusd[len]) + ISSET(audusd[len]) + ISSET(nzdusd[len]) + ISSET(usdjpy[len]) + ISSET(usdchf[len]) + ISSET(usdcad[len])
// Each currency's move against the dollar, in the order USD EUR GBP JPY CHF AUD CAD NZD
$r[0] = 0
$r[1] = LOG(eurusd / eurusd[len]) * 100
$r[2] = LOG(gbpusd / gbpusd[len]) * 100
$r[3] = -LOG(usdjpy / usdjpy[len]) * 100
$r[4] = -LOG(usdchf / usdchf[len]) * 100
$r[5] = LOG(audusd / audusd[len]) * 100
$r[6] = -LOG(usdcad / usdcad[len]) * 100
$r[7] = LOG(nzdusd / nzdusd[len]) * 100
total = ARRAYSUM($r)
IF ready < 7 THEN
wait = DRAWTABLE(1, 1, topright) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
TABLECELL(wait, 0, 0, "Forex matrix · waiting for data (#ready#/7 pairs)", bold, center, 12) COLOURED(240, 190, 70)
ELSE
board = DRAWTABLE(10, 10, topright) FILLCOLOR(16, 20, 28, 235) BORDERCOLOR(48, 58, 76)
TABLEMERGE(board, 0, 0, 1, 10)
TABLECELL(board, 0, 0, "Forex matrix · row vs column · last #len# bars", bold, center, 12) COLOURED(214, 222, 235)
// Column and row headers
TABLECELL(board, 1, 1, "USD", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 2, "EUR", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 3, "GBP", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 4, "JPY", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 5, "CHF", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 6, "AUD", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 7, "CAD", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 8, "NZD", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 1, 9, "Strength", bold, center) COLOURED(170, 180, 195)
TABLECELL(board, 2, 0, "USD", bold) COLOURED(170, 180, 195)
TABLECELL(board, 3, 0, "EUR", bold) COLOURED(170, 180, 195)
TABLECELL(board, 4, 0, "GBP", bold) COLOURED(170, 180, 195)
TABLECELL(board, 5, 0, "JPY", bold) COLOURED(170, 180, 195)
TABLECELL(board, 6, 0, "CHF", bold) COLOURED(170, 180, 195)
TABLECELL(board, 7, 0, "AUD", bold) COLOURED(170, 180, 195)
TABLECELL(board, 8, 0, "CAD", bold) COLOURED(170, 180, 195)
TABLECELL(board, 9, 0, "NZD", bold) COLOURED(170, 180, 195)
// The 64 cells: row against column, then the row's average strength
FOR i = 0 TO 7 DO
FOR j = 0 TO 7 DO
IF i = j THEN
TABLECELL(board, i + 2, j + 1, "·", center) COLOURED(90, 100, 115)
ELSE
v = $r[i] - $r[j]
vTxt = ROUND(v * 100) / 100
TABLEHEAT(board, i + 2, j + 1, v, -span, span, "#vTxt#")
ENDIF
NEXT
s = (8 * $r[i] - total) / 7
sTxt = ROUND(s * 100) / 100
TABLEBAR(board, i + 2, 9, s, -span, span, "#sTxt#") GRADIENTCOLOR(s, -span, span, "#e05563", "#8fa4c0", "#3fbf7f")
NEXT
ENDIF
RETURN