Bitcoin Correlation Map
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Milvetti

//@version=5
indicator("Bitcoin Correlation Map")

g1= "Settings"
g2="Reference Settings"
g3="Symbol Settings"

size = input.string("Normal","Size",options = ["Small","Normal","Large"],group = g1)
len= input.int(20,"Mov Lenght",group = g1)
cLen = input.int(200,"Correlation Lenght",minval = 1,maxval = 4999,group = g1)

base = input.symbol("BINANCE:BTCUSDT","Referenece Symbol",group = g2)
symbol1 = input.symbol("BINANCE:ETHUSDT",group = g3)
symbol2 = input.symbol("BINANCE:BNBUSDT",group = g3)
symbol3 = input.symbol("BINANCE:DOTUSDT",group = g3)
symbol4 = input.symbol("BINANCE:LTCUSDT",group = g3)
symbol5 = input.symbol("BINANCE:AVAXUSDT",group = g3)
symbol6 = input.symbol("BINANCE:SANDUSDT",group = g3)
symbol7 = input.symbol("BINANCE:ALGOUSDT",group = g3)
symbol8 = input.symbol("BINANCE:GALAUSDT",group = g3)
symbol9 = input.symbol("BINANCE:MANAUSDT",group = g3)
symbol10 = input.symbol("BINANCE:SOLUSDT",group = g3)
symbol11 = input.symbol("BINANCE:MATICUSDT",group = g3)
symbol12 = input.symbol("BINANCE:TRXUSDT",group = g3)
symbol13 = input.symbol("BINANCE:XMRUSDT",group = g3)
symbol14 = input.symbol("BINANCE:XRPUSDT",group = g3)
symbol15 = input.symbol("BINANCE:FTMUSDT",group = g3)
symbol16 = input.symbol("BINANCE:NEARUSDT",group = g3)
symbol17 = input.symbol("BINANCE:ENJUSDT",group = g3)
symbol18 = input.symbol("BINANCE:ATOMUSDT",group = g3)
symbol19 = input.symbol("BINANCE:ADAUSDT",group = g3)
symbol20 = input.symbol("BINANCE:COMPUSDT",group = g3)
symbol21 = input.symbol("BINANCE:ALICEUSDT",group = g3)
symbol22 = input.symbol("BINANCE:AAVEUSDT",group = g3)
symbol23 = input.symbol("BINANCE:CHZUSDT",group = g3)
symbol24 = input.symbol("BINANCE:CAKEUSDT",group = g3)
symbol25 = input.symbol("BINANCE:AXSUSDT",group = g3)
symbol26 = input.symbol("BINANCE:BATUSDT",group = g3)
symbol27 = input.symbol("BINANCE:MKRUSDT",group = g3)
symbol28 = input.symbol("BINANCE:BCHUSDT",group = g3)
symbol29 = input.symbol("BINANCE:ICPUSDT",group = g3)
symbol30 = input.symbol("BINANCE:SOLUSDT",group = g3)
symbol31 = input.symbol("BINANCE:CRVUSDT",group = g3)
symbol32 = input.symbol("BINANCE:LRCUSDT",group = g3)
symbol33 = input.symbol("BINANCE:DOGEUSDT",group = g3)
symbol34 = input.symbol("BINANCE:SHIBUSDT",group = g3)
symbol35 = input.symbol("BINANCE:LINKUSDT",group = g3)
symbol36 = input.symbol("TVC:DXY",group = g3)


tableSize= switch size
    "Small" => size.small
    "Normal" => size.normal
    "Large" => size.large



cor(x)=>
    if bar_index<x and bar_index>0
        bar_index
    else
        x




baseC = request.security(base,"",close)
c1 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol1,"",close), len),cor(cLen)),2)
c2 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol2,"",close), len),cor(cLen)),2)
c3 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol3,"",close), len),cor(cLen)),2)
c4 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol4,"",close), len),cor(cLen)),2)
c5 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol5,"",close), len),cor(cLen)),2)
c6 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol6,"",close), len),cor(cLen)),2)
c7 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol7,"",close), len),cor(cLen)),2)
c8 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol8,"",close), len),cor(cLen)),2)
c9 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol9,"",close), len),cor(cLen)),2)
c10 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol10,"",close), len),cor(cLen)),2)
c11 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol11,"",close), len),cor(cLen)),2)
c12 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol12,"",close), len),cor(cLen)),2)
c13 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol13,"",close), len),cor(cLen)),2)
c14 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol14,"",close), len),cor(cLen)),2)
c15 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol15,"",close), len),cor(cLen)),2)
c16 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol16,"",close), len),cor(cLen)),2)
c17 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol17,"",close), len),cor(cLen)),2)
c18 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol18,"",close), len),cor(cLen)),2)
c19 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol19,"",close), len),cor(cLen)),2)
c20 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol20,"",close), len),cor(cLen)),2)
c21=math.round(ta.wma(ta.correlation(baseC, request.security(symbol21,"",close), len),cor(cLen)),2)
c22 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol22,"",close), len),cor(cLen)),2)
c23 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol23,"",close), len),cor(cLen)),2)
c24 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol24,"",close), len),cor(cLen)),2)
c25 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol25,"",close), len),cor(cLen)),2)
c26 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol26,"",close), len),cor(cLen)),2)
c27 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol27,"",close), len),cor(cLen)),2)
c28 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol28,"",close), len),cor(cLen)),2)
c29 =math.round(ta.wma(ta.correlation(baseC, request.security(symbol29,"",close), len),cor(cLen)),2)
c30=math.round(ta.wma(ta.correlation(baseC, request.security(symbol30,"",close), len),cor(cLen)),2)
c31=math.round(ta.wma(ta.correlation(baseC, request.security(symbol31,"",close), len),cor(cLen)),2)
c32=math.round(ta.wma(ta.correlation(baseC, request.security(symbol32,"",close), len),cor(cLen)),2)
c33=math.round(ta.wma(ta.correlation(baseC, request.security(symbol33,"",close), len),cor(cLen)),2)
c34=math.round(ta.wma(ta.correlation(baseC, request.security(symbol34,"",close), len),cor(cLen)),2)
c35=math.round(ta.wma(ta.correlation(baseC, request.security(symbol35,"",close), len),cor(cLen)),2)
c36=math.round(ta.wma(ta.correlation(baseC, request.security(symbol36,"",close), len),cor(cLen)),2)

headerColor = #131722
corColor = #fefcee
headerTextColor = color.white
textColor = color.white

corColor(x) =>
    if x>0
        color.new(color.green,10)
    else
        color.new(color.red,10)


var tablo=table.new(position=position.middle_center,columns=12,rows=6,bgcolor=headerColor ,frame_color=#151715, frame_width=2, border_width=2, border_color=color.new(color.black, 100) )
table.cell(tablo,0,0,syminfo.ticker(symbol1) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,0,1,str.tostring(c1),text_color=textColor,bgcolor = corColor(c1),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,0,2,syminfo.ticker(symbol2) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,0,3,str.tostring(c2),text_color=textColor,bgcolor = corColor(c2),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,0,4,syminfo.ticker(symbol3) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,0,5,str.tostring(c3),text_color=textColor,bgcolor = corColor(c3),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,1,0,syminfo.ticker(symbol4) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,1,1,str.tostring(c4),text_color=textColor,bgcolor = corColor(c4),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,1,2,syminfo.ticker(symbol5) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,1,3,str.tostring(c5),text_color=textColor,bgcolor = corColor(c5),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,1,4,syminfo.ticker(symbol6) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,1,5,str.tostring(c6),text_color=textColor,bgcolor = corColor(c6),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,2,0,syminfo.ticker(symbol7) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,2,1,str.tostring(c7),text_color=textColor,bgcolor = corColor(c7),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,2,2,syminfo.ticker(symbol8) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,2,3,str.tostring(c8),text_color=textColor,bgcolor = corColor(c8),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,2,4,syminfo.ticker(symbol9) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,2,5,str.tostring(c9),text_color=textColor,bgcolor = corColor(c9),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,3,0,syminfo.ticker(symbol10) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,3,1,str.tostring(c10),text_color=textColor,bgcolor = corColor(c10),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,3,2,syminfo.ticker(symbol11) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,3,3,str.tostring(c11),text_color=textColor,bgcolor = corColor(c11),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,3,4,syminfo.ticker(symbol12) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,3,5,str.tostring(c12),text_color=textColor,bgcolor = corColor(c12),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,4,0,syminfo.ticker(symbol13) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,4,1,str.tostring(c13),text_color=textColor,bgcolor = corColor(c13),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,4,2,syminfo.ticker(symbol14) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,4,3,str.tostring(c14),text_color=textColor,bgcolor = corColor(c14),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,4,4,syminfo.ticker(symbol15) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,4,5,str.tostring(c15),text_color=textColor,bgcolor = corColor(c15),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,5,0,syminfo.ticker(symbol16) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,5,1,str.tostring(c16),text_color=textColor,bgcolor = corColor(c16),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,5,2,syminfo.ticker(symbol17) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,5,3,str.tostring(c17),text_color=textColor,bgcolor = corColor(c17),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,5,4,syminfo.ticker(symbol18) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,5,5,str.tostring(c18),text_color=textColor,bgcolor = corColor(c18),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,6,0,syminfo.ticker(symbol19) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,6,1,str.tostring(c19),text_color=textColor,bgcolor = corColor(c19),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,6,2,syminfo.ticker(symbol20) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,6,3,str.tostring(c20),text_color=textColor,bgcolor = corColor(c20),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,6,4,syminfo.ticker(symbol21) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,6,5,str.tostring(c21),text_color=textColor,bgcolor = corColor(c21),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,7,0,syminfo.ticker(symbol22) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,7,1,str.tostring(c22),text_color=textColor,bgcolor = corColor(c22),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,7,2,syminfo.ticker(symbol23) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,7,3,str.tostring(c23),text_color=textColor,bgcolor = corColor(c23),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,7,4,syminfo.ticker(symbol24) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,7,5,str.tostring(c24),text_color=textColor,bgcolor = corColor(c24),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,8,0,syminfo.ticker(symbol25) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,8,1,str.tostring(c25),text_color=textColor,bgcolor = corColor(c25),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,8,2,syminfo.ticker(symbol26) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,8,3,str.tostring(c26),text_color=textColor,bgcolor = corColor(c26),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,8,4,syminfo.ticker(symbol27) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,8,5,str.tostring(c27),text_color=textColor,bgcolor = corColor(c27),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,9,0,syminfo.ticker(symbol28) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,9,1,str.tostring(c28),text_color=textColor,bgcolor = corColor(c28),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,9,2,syminfo.ticker(symbol29) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,9,3,str.tostring(c29),text_color=textColor,bgcolor = corColor(c29),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,9,4,syminfo.ticker(symbol30) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,9,5,str.tostring(c30),text_color=textColor,bgcolor = corColor(c30),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,10,0,syminfo.ticker(symbol31) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,10,1,str.tostring(c31),text_color=textColor,bgcolor = corColor(c31),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,10,2,syminfo.ticker(symbol32) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,10,3,str.tostring(c32),text_color=textColor,bgcolor = corColor(c32),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,10,4,syminfo.ticker(symbol33) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,10,5,str.tostring(c33),text_color=textColor,bgcolor = corColor(c33),text_halign = text.align_center,text_size = tableSize)

table.cell(tablo,11,0,syminfo.ticker(symbol34) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,11,1,str.tostring(c34),text_color=textColor,bgcolor = corColor(c34),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,11,2,syminfo.ticker(symbol35) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,11,3,str.tostring(c35),text_color=textColor,bgcolor = corColor(c35),text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,11,4,syminfo.ticker(symbol36) ,text_color=headerTextColor,bgcolor = headerColor,text_halign = text.align_center,text_size = tableSize)
table.cell(tablo,11,5,str.tostring(c36),text_color=textColor,bgcolor = corColor(c36),text_halign = text.align_center,text_size = tableSize)

