Macro EMA Correlation
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © castonguayfrancois9



//@version=5
indicator("Macro EMA Correlation", overlay = false) 


// Time frame selection
tf = timeframe.period
 
// Pair selection

i_1 = input.bool(title = "BTC:USDT", defval = true, group = "Enablers")
i_2 = input.bool(title = "ETH:USDT", defval = true, group = "Enablers")
i_3 = input.bool(title = "TVC:GOLD", defval = true, group = "Enablers")
i_4 = input.bool(title = "TOTAL2", defval = true, group = "Enablers")
i_5 = input.bool(title = "TVC:US10Y", defval = true, group = "Enablers")
i_6 = input.bool(title = "USDT.D", defval = true, group = "Enablers")
i_7 = input.bool(title = "USD:JPY", defval = true, group = "Enablers")


// request.security fonction for each pair to get them on the same script and compare them with percentage variation

btcClose = request.security("BINANCE:BTCUSDT", tf, close)
btcEma50 = request.security("BINANCE:BTCUSDT", tf, ta.ema(btcClose, 100))
btcEmax = (btcClose/btcEma50)
colorA = color(na)
if i_1
    colorA := color.green
else
    colorA := color(na)
plot(ta.ema(btcEmax,100), color=colorA, linewidth =2)




ethClose = request.security("BINANCE:ETHUSDT", tf, close)
ethEma50 = request.security("BINANCE:ETHUSDT", tf, ta.ema(close, 100))
ethEmax = (ethClose/ethEma50)
colorB = color(na)
if i_2
    colorB := color.blue
else
    colorB := color(na)
plot(ta.ema(ethEmax,100), color=colorB)


paxClose = request.security("TVC:GOLD", tf, close)
paxEma50 = request.security("TVC:GOLD", tf, ta.ema(paxClose, 100))
paxEmax = (paxClose/paxEma50)
colorC = color(na)
if i_3
    colorC := color.yellow
else
    colorC := color(na)
plot(ta.ema(paxEmax,100), color=colorC, linewidth =2)


totalClose = request.security("CRYPTOCAP:TOTAL2", tf, close)
totalEma50 = request.security("CRYPTOCAP:TOTAL2", tf, ta.ema(totalClose, 100))
totalEmax = (totalClose/totalEma50)
colorD = color(na)
if i_4
    colorD := color.fuchsia
else
    colorD := color(na)
plot(ta.ema(totalEmax,100), color = colorD)


yieldClose = request.security("TVC:US10Y", tf, close)
yieldEma50 = request.security("TVC:US10Y", tf, ta.ema(close, 100))
yieldEmax = (yieldClose/yieldEma50)
colorE = color(na)
if i_5
    colorE := color.gray
else
    colorE := color(na)
plot(ta.ema(yieldEmax,100), color = colorE)


usdClose = request.security("CRYPTOCAP:USDT.D", tf, close)
usdDEma50 = request.security("CRYPTOCAP:USDT.D", tf, ta.ema(usdClose, 100))
usdDEmax = (usdClose/usdDEma50)
colorF = color(na)
if i_6
    colorF := color.lime
else
    colorF := color(na)
plot(ta.ema(usdDEmax,100), color = colorF)


yenClose = request.security("FX:USDJPY", tf, close)
yenEma50 = request.security("FX:USDJPY", tf, ta.ema(yenClose, 100))
yenEmax = (yenClose/yenEma50)
colorG = color(na)
if i_7
    colorG := color.red
else
    colorG := color(na)
plot(ta.ema(yenEmax,100), color = colorG, linewidth =2)


// Table indicating wich colored ema line correspond to wich asset

var table perfTable = table.new(position.bottom_right, 1, 7, border_width = 1)

if i_1
    table.cell(perfTable, 0, 0, "BTC:USDT", bgcolor = colorA, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_2
    table.cell(perfTable, 0, 1, "ETH:USDT", bgcolor = colorB, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_3
    table.cell(perfTable, 0, 2, "TVC:GOLD", bgcolor = colorC, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_4
    table.cell(perfTable, 0, 3, "TOTAL2", bgcolor = colorD, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_5
    table.cell(perfTable, 0, 4, "TVC:US10Y", bgcolor = colorE, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_6
    table.cell(perfTable, 0, 5, "USDT.D", bgcolor = colorF, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)
if i_7
    table.cell(perfTable, 0, 6, "USD:JPY", bgcolor = colorG, text_color = color.new(color.black, 0), width = 12, height = 9, text_size = size.large)