Correlation Crypto Matrix
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © [VanHelsing 2023]

//@version=5
indicator("Correlation Crypto Matrix", 'CCM', overlay = false)

int cc_len = input.int(30, 'Correlation Length')

string sym1=	input("BTCUSD")
string sym2=	input("BNBUSD")
string sym3=	input("ETHUSD")
string sym4=	input("BCHUSD")
string sym5=	input("XRPUSD")
string sym6=	input("EOSUSD")
string sym7=	input("LTCUSD")
string sym8=	input("TRXUSD")
string sym9=	input("ETCUSD")
string sym10=	input("LINKUSD")

symbol1=	request.security(	sym1	,""	,close)
symbol2=    request.security(	sym2	,""	,close)
symbol3=	request.security(	sym3	,""	,close)
symbol4=	request.security(	sym4	,""	,close)
symbol5=	request.security(	sym5	,""	,close)
symbol6=	request.security(	sym6	,""	,close)
symbol7=	request.security(	sym7	,""	,close)
symbol8=	request.security(	sym8	,""	,close)
symbol9=	request.security(	sym9	,""	,close)
symbol10=	request.security(	sym10	,""	,close)

// ┄   ﹊   ﹎

corelation_col(sym, sym2, cc_len)=>
    cc    = math.round(ta.correlation(sym, sym2, cc_len),2)
    color = color.from_gradient(cc, -1, 1,color.red,color.green)
    [cc, color]
    
[cc1, color1] = corelation_col(symbol1, symbol2, cc_len)
[cc2, color2] = corelation_col(symbol1, symbol3, cc_len)
[cc3, color3] = corelation_col(symbol1, symbol4, cc_len)
[cc4, color4] = corelation_col(symbol1, symbol5, cc_len)
[cc5, color5] = corelation_col(symbol1, symbol6, cc_len)
[cc6, color6] = corelation_col(symbol1, symbol7, cc_len)
[cc7, color7] = corelation_col(symbol1, symbol8, cc_len)
[cc8, color8] = corelation_col(symbol1, symbol9, cc_len)
[cc9, color9] = corelation_col(symbol1, symbol10, cc_len)

[cc10, color10] = corelation_col(symbol2, symbol3, cc_len)
[cc11, color11] = corelation_col(symbol2, symbol4, cc_len)
[cc12, color12] = corelation_col(symbol2, symbol5, cc_len)
[cc13, color13] = corelation_col(symbol2, symbol6, cc_len)
[cc14, color14] = corelation_col(symbol2, symbol7, cc_len)
[cc15, color15] = corelation_col(symbol2, symbol8, cc_len)
[cc16, color16] = corelation_col(symbol2, symbol9, cc_len)
[cc17, color17] = corelation_col(symbol2, symbol10, cc_len)

[cc18, color18] = corelation_col(symbol3, symbol4, cc_len)
[cc19, color19] = corelation_col(symbol3, symbol5, cc_len)
[cc20, color20] = corelation_col(symbol3, symbol6, cc_len)
[cc21, color21] = corelation_col(symbol3, symbol7, cc_len)
[cc22, color22] = corelation_col(symbol3, symbol8, cc_len)
[cc23, color23] = corelation_col(symbol3, symbol9, cc_len)
[cc24, color24] = corelation_col(symbol3, symbol10, cc_len)

[cc25, color25] = corelation_col(symbol4, symbol5, cc_len)
[cc26, color26] = corelation_col(symbol4, symbol6, cc_len)
[cc27, color27] = corelation_col(symbol4, symbol7, cc_len)
[cc28, color28] = corelation_col(symbol4, symbol8, cc_len)
[cc29, color29] = corelation_col(symbol4, symbol9, cc_len)
[cc30, color30] = corelation_col(symbol4, symbol10, cc_len)

[cc31, color31] = corelation_col(symbol5, symbol6, cc_len)
[cc32, color32] = corelation_col(symbol5, symbol7, cc_len)
[cc33, color33] = corelation_col(symbol5, symbol8, cc_len)
[cc34, color34] = corelation_col(symbol5, symbol9, cc_len)
[cc35, color35] = corelation_col(symbol5, symbol10, cc_len)

[cc36, color36] = corelation_col(symbol6, symbol7, cc_len)
[cc37, color37] = corelation_col(symbol6, symbol8, cc_len)
[cc38, color38] = corelation_col(symbol6, symbol9, cc_len)
[cc39, color39] = corelation_col(symbol6, symbol10, cc_len)

[cc40, color40] = corelation_col(symbol7, symbol8, cc_len)
[cc41, color41] = corelation_col(symbol7, symbol9, cc_len)
[cc42, color42] = corelation_col(symbol7, symbol10, cc_len)

[cc43, color43] = corelation_col(symbol8, symbol9, cc_len)
[cc44, color44] = corelation_col(symbol8, symbol10, cc_len)

[cc45, color45] = corelation_col(symbol9, symbol10, cc_len)

var table = table.new(position.top_center, 40, 40, border_color = color.rgb(61, 62, 68), border_width = 2)
cell(sym, a, c, color, text_size = size.normal)=>
    table.cell(table, a, c, text = str.tostring(sym), text_color = color, text_size = text_size)

cell1(cc, a, c, color)=>
    table.cell(table, a, c, text = cc<0.2 and cc>-0.2?"┄":cc>0.2? "﹊":cc<-0.2 ? '﹎':na, text_color = color1, text_size = size.large)

cell(sym1, 0, 1, color.white)
cell(sym2, 0, 2, color.white)
cell(sym3, 0, 3, color.white)
cell(sym4, 0, 4, color.white)
cell(sym5, 0, 5, color.white)
cell(sym6, 0, 6, color.white)
cell(sym7, 0, 7, color.white)
cell(sym8, 0, 8, color.white)
cell(sym9, 0, 9, color.white)
cell(sym10, 0, 10, color.white)

cell(sym1, 1, 0, color.white)
cell(sym2, 2, 0, color.white)
cell(sym3, 3, 0, color.white)
cell(sym4, 4, 0, color.white)
cell(sym5, 5, 0, color.white)
cell(sym6, 6, 0, color.white)
cell(sym7, 7, 0, color.white)
cell(sym8, 8, 0, color.white)
cell(sym9, 9, 0, color.white)
cell(sym10, 10, 0, color.white)

cell("₿", 1, 1, color.gray)
cell(sym2, 2, 2, color.gray)
cell(sym3, 3, 3, color.gray)
cell(sym4, 4, 4, color.gray)
cell(sym5, 5, 5, color.gray)
cell(sym6, 6, 6, color.gray)
cell(sym7, 7, 7, color.gray)
cell(sym8, 8, 8, color.gray)
cell(sym9, 9, 9, color.gray)
cell(sym10, 10, 10, color.gray)


cell(str.tostring(cc1), 1, 2, color1)
cell1(cc1, 2, 1, color1)

cell(str.tostring(cc2), 1, 3, color2)
cell1(cc2, 3, 1, color2)

cell(str.tostring(cc3), 1, 4, color3)
cell1(cc3, 4, 1, color3)

cell(str.tostring(cc4), 1, 5, color4)
cell1(cc4, 5, 1, color4)

cell(str.tostring(cc5), 1, 6, color5)
cell1(cc5, 6, 1, color5)

cell(str.tostring(cc6), 1, 7, color6)
cell1(cc6, 7, 1, color6)

cell(str.tostring(cc7), 1, 8, color7)
cell1(cc7, 8, 1, color7)

cell(str.tostring(cc8), 1, 9, color8)
cell1(cc8, 9, 1, color8)

cell(str.tostring(cc9), 1, 10, color9)
cell1(cc9, 10, 1, color9)

cell(str.tostring(cc10), 2, 3, color10)
cell1(cc10, 3, 2, color10)

cell(str.tostring(cc11), 2, 4, color11)
cell1(cc11, 4, 2, color11)

cell(str.tostring(cc12), 2, 5, color12)
cell1(cc12, 5, 2, color12)

cell(str.tostring(cc13), 2, 6, color13)
cell1(cc13, 6, 2, color13)

cell(str.tostring(cc14), 2, 7, color14)
cell1(cc14, 7, 2, color14)

cell(str.tostring(cc15), 2, 8, color15)
cell1(cc15, 8, 2, color15)

cell(str.tostring(cc16), 2, 9, color16)
cell1(cc16, 9, 2, color16)

cell(str.tostring(cc17), 2, 10, color17)
cell1(cc17, 10, 2, color17)

cell(str.tostring(cc18), 3, 4, color18)
cell1(cc18, 4, 3, color18)

cell(str.tostring(cc19), 3, 5, color19)
cell1(cc19, 5, 3, color19)

cell(str.tostring(cc20), 3, 6, color20)
cell1(cc20, 6, 3, color20)

cell(str.tostring(cc21), 3, 7, color21)
cell1(cc21, 7, 3, color21)

cell(str.tostring(cc22), 3, 8, color22)
cell1(cc22, 8, 3, color22)

cell(str.tostring(cc23), 3, 9, color23)
cell1(cc23, 9, 3, color23)

cell(str.tostring(cc24), 3, 10, color24)
cell1(cc24, 10, 3, color24)

cell(str.tostring(cc25), 4, 5, color25)
cell1(cc25, 5, 4, color25)

cell(str.tostring(cc26), 4, 6, color26)
cell1(cc26, 6, 4, color26)

cell(str.tostring(cc27), 4, 7, color27)
cell1(cc27, 7, 4, color27)

cell(str.tostring(cc28), 4, 8, color28)
cell1(cc28, 8, 4, color28)

cell(str.tostring(cc29), 4, 9, color29)
cell1(cc29, 9, 4, color29)

cell(str.tostring(cc30), 4, 10, color30)
cell1(cc30, 10, 4, color30)

cell(str.tostring(cc31), 5, 6, color31)
cell1(cc31, 6, 5, color31)

cell(str.tostring(cc32), 5, 7, color32)
cell1(cc32, 7, 5, color32)

cell(str.tostring(cc33), 5, 8, color33)
cell1(cc33, 8, 5, color33)

cell(str.tostring(cc34), 5, 9, color34)
cell1(cc34, 9, 5, color34)

cell(str.tostring(cc35), 5, 10, color35)
cell1(cc35, 10, 5, color35)

cell(str.tostring(cc36), 6, 7, color36)
cell1(cc36, 7, 6, color36)

cell(str.tostring(cc37), 6, 8, color37)
cell1(cc37, 8, 6, color37)

cell(str.tostring(cc38), 6, 9, color38)
cell1(cc38, 9, 6, color38)

cell(str.tostring(cc39), 6, 10, color39)
cell1(cc39, 10, 6, color39)

cell(str.tostring(cc40), 7, 8, color40)
cell1(cc40, 8, 7, color40)

cell(str.tostring(cc41), 7, 9, color41)
cell1(cc41, 9, 7, color41)

cell(str.tostring(cc42), 7, 10, color42)
cell1(cc42, 10, 7, color42)

cell(str.tostring(cc43), 8, 9, color43)
cell1(cc43, 9, 8, color43)

cell(str.tostring(cc44), 8, 10, color44)
cell1(cc44, 10, 8, color44)

cell(str.tostring(cc45), 9, 10, color45)
cell1(cc45, 10, 9, color45)


alert('- ' + str.tostring(sym1) +" "+ str.tostring(sym2) +" "+ str.tostring(sym3) +" "+ str.tostring(sym4) +" "+ str.tostring(sym5) +" "+ str.tostring(sym6) +" "+ str.tostring(sym7)
 +" "+ str.tostring(sym8) +" "+ str.tostring(sym9)
 +","+str.tostring(sym1)+","+
 str.tostring(sym2) +" "+str.tostring(cc1)+","+
 str.tostring(sym3) +" "+str.tostring(cc2)+" "+str.tostring(cc10)+","+
 str.tostring(sym4) +" "+str.tostring(cc3)+" "+str.tostring(cc11)+" "+str.tostring(cc18)+","+
 str.tostring(sym5) +" "+str.tostring(cc4)+" "+str.tostring(cc12)+" "+str.tostring(cc19)+" "+str.tostring(cc25)+","+
 str.tostring(sym6) +" "+str.tostring(cc5)+" "+str.tostring(cc13)+" "+str.tostring(cc20)+" "+str.tostring(cc26)+" "+str.tostring(cc31)+","+
 str.tostring(sym7) +" "+str.tostring(cc6)+" "+str.tostring(cc14)+" "+str.tostring(cc21)+" "+str.tostring(cc27)+" "+str.tostring(cc32)+" "+str.tostring(cc36)+","+
 str.tostring(sym8) +" "+str.tostring(cc7)+" "+str.tostring(cc15)+" "+str.tostring(cc22)+" "+str.tostring(cc28)+" "+str.tostring(cc33)+" "+str.tostring(cc37)+" "+str.tostring(cc40)+","+
 str.tostring(sym9) +" "+str.tostring(cc8)+" "+str.tostring(cc16)+" "+str.tostring(cc23)+" "+str.tostring(cc29)+" "+str.tostring(cc34)+" "+str.tostring(cc38)+" "+str.tostring(cc41)+" "+str.tostring(cc43)+","+ 
 str.tostring(sym10)+" "+str.tostring(cc9)+" "+str.tostring(cc17)+" "+str.tostring(cc24)+" "+str.tostring(cc30)+" "+str.tostring(cc35)+" "+str.tostring(cc39)+" "+str.tostring(cc41)+" "+str.tostring(cc44)+" "+str.tostring(cc45)
 )