forexpirate

Correlation of chart symbol to different Index-ETF-currency

Script plots correlation of chart symbol to a variety of indexes, symbols, equities. ** Original idea was to find Bitcoin correlation, which I did not. Built in correlations are: Nikie, DAX , SPY , AAPL , US Dollar , Gold , EURUSD , USDCNY , EEM , QQQ , XLK , XLF , USDJPY , EURGBP
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
//@version=2
study(title="BITCOIN Index-ETF-currency Corr",  shorttitle="BITCOIN Index-ETF-currency Corr")
// Add the inputs
l = input(title="Length", type=integer,  defval=20, minval=5)

p0 = input(title="Other data series", type=symbol,defval="JPN")
p1 = input(title="Other data series", type=symbol,defval="DAX")
p2 = input(title="Other data series", type=symbol,defval="amex:SPY")
p3 = input(title="Other data series", type=symbol,defval="NASDAQ:aapl")
p4 = input(title="Other data series", type=symbol,defval="usdollar")
p5 = input(title="Other data series", type=symbol,defval="amex:gld") 
p6 = input(title="Other data series", type=symbol,defval="FX_IDC:EURUSD")
p7 = input(title="Other data series", type=symbol,defval="FX_IDC:usdcny")
p8 = input(title="Other data series", type=symbol,defval="amex:eem")
p9 = input(title="Other data series", type=symbol,defval="NASDAQ:qqq")
p10 = input(title="Other data series", type=symbol,defval="amex:xlk")
p11 = input(title="Other data series", type=symbol,defval="amex:xlf")
//p12 = input(title="Other data series", type=symbol,defval="FX_IDC:usdcnh")
p13 = input(title="Other data series", type=symbol,defval="FX_IDC:usdjpy")
p14 = input(title="Other data series", type=symbol,defval="FX_IDC:eurgbp")

s0= security(p0, period, close)
s1= security(p1, period, close)
s2= security(p2, period, close)
s3= security(p3, period, close)
s4= security(p4, period, close)
s5= security(p5, period, close)
s6= security(p6, period, close)
s7= security(p7, period, close)
s8= security(p8, period, close)
s9= security(p9, period, close)
s10= security(p10, period, close)
s11= security(p11, period, close)
//s12= security(p12, period, close)
s13= security(p13, period, close)
s14= security(p14, period, close)
// Calculate correlation and slopes
corr0 = correlation(close, s0, l)
corr1 = correlation(close, s1, l)
corr2 = correlation(close, s2, l)
corr3 = correlation(close, s3, l)
corr4 = correlation(close, s4, l)
corr5 = correlation(close, s5, l)
corr6 = correlation(close, s6, l)
corr7 = correlation(close, s7, l)
corr8 = correlation(close, s8, l)
corr9 = correlation(close, s9, l)
corr10 = correlation(close, s10, l)
corr11 = correlation(close, s11, l)
//corr12 = correlation(close, s12, l)
corr13 = correlation(close, s13, l)
corr14 = correlation(close, s14, l)
// SMA calc


plot(corr0,color=red,title="Japan")
plot(corr1,color=silver,title="Germany")
plot(corr2,color=white,title="SP500")
plot(corr3,color=maroon,title="Apple")
plot(corr4,color=purple,title="US Dollar")
plot(corr5,color=green,title="Gold")
plot(corr6,color=lime,title="EURUSD")
plot(corr7,color=olive,title="USDCNY")
plot(corr8,color=yellow,title="EEM")
plot(corr9,color=navy,title="Nasdaq")
plot(corr10,color=teal,title="Tech ETF")
plot(corr11,color=orange,title="Fin ETF")
//plot(corr12,color=aqua,title="")
plot(corr13,color=silver,title="USDJPY")
plot(corr14,color=white,title="EURGBP")