Delta Agnostic Correlation Coefficient
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alexjvale

//@version=5
indicator("Delta-Agnostic Correlation Coefficient")

index = input.symbol("INDEX:BTCUSD", "Index")
sma_length = input.int(20, "SMA Length", minval=5, maxval=52, step=1)

index_current = request.security(index, "", close)
index_previous = request.security(index, "", close[1])

target_current = close
target_previous = close[1]

index_delta = index_current - index_previous
target_delta = target_current - target_previous

dcc = 0

if (math.sign(index_delta) == math.sign(target_delta))
    dcc := 1
else
    dcc := -1
    
dcc_sma = ta.sma(dcc, sma_length)

plot(dcc_sma, "DCC", color.blue, 1, plot.style_areabr)

hline(1)
hline(0)
hline(-1)
