kinetix360

BB % Correlation

209
BB% of Correlation, is the indication frequently used by Quant Traders to define the momentum for their Arbitrage Trading Strategy. If anyone here is a Quant Trading and find this is not a correct script, please feel free to fix it, because I am not a programer. Thank you.

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?
study(title = "BB % Correlation", shorttitle = "BB % Correl")

source = hlc3
//length = input(14, minval=1, title="RSI Period") 
//corlength = input(30, minval=1, title="Correlation Period)
bblength = input(20, minval=1, title="BB Period")
mult = input(2.0, minval=0.001, maxval=50, title="StdDev")
HighlightBreaches=input(false, title="Highlight Oversold/Overbought?", type=bool)

//Define RSI
//rsi_s = rsi(source, length)


//Define Correlation
sym = input(title="Symbol", type=symbol, defval="XAUUSD", confirm=true)
src = input(close, title="Source")
//corlength = input(20, minval=1)
corlength = input(30, minval=1, title="Correlation Period")

res=period

ovr = security(sym, res, src)
correl = correlation(src, ovr, corlength)


// BB of RSI

basis = sma(correl, bblength)
dev = mult * stdev(correl, bblength)
upper = basis + dev
lower = basis - dev

bbr = (correl - lower)/(upper - lower)
plot(bbr, color=teal)
band1 = hline(1, color=gray, linestyle=dashed)
band0 = hline(0, color=gray, linestyle=dashed)
fill(band1, band0, color=teal)

//p1 = plot(upper, color=blue)
//p2 = plot(lower, color=blue)
//fill(p1,p2, blue)

b_color = (correl > upper) ? red : (correl < lower) ? green : na
//b_color = (bbr > band1) ? red : (bbr < band0) ? green : na
bgcolor(HighlightBreaches ? b_color : na)