Correlational cycles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Kowalski_Trader

//@version=5
indicator("Correlation Coefficient", shorttitle = "CC", format = format.price, precision = 2)
symbolInput = input.symbol("FNGU", "Symbol", confirm = true)
second_symbolInput = input.symbol("QQQ", "Symbol", confirm = true)
sourceInput = input.source(close, "Source")
multiplierInput = input.int(-1,"Multiplier")
second_symbolMultiplier = input.int(-1,"Second Symbol Multiplier")
lengthInput = input.int(11, "Length")


adjustedSeries = ticker.modify(symbolInput)
second_adjustedSeries = ticker.modify(second_symbolInput)

requestedData = request.security(adjustedSeries, timeframe.period, (sourceInput*multiplierInput))
second_requestedData = request.security(second_adjustedSeries, timeframe.period, (sourceInput*second_symbolMultiplier))

correlation = ta.correlation(sourceInput, requestedData, lengthInput)
second_correlation = ta.correlation(sourceInput, second_requestedData, lengthInput)
plot(second_correlation, "Correlation Second Symbol", color = color.red)
plot(correlation, "Correlation", color = color.blue)
hline(1)
hline(0, color = color.new(color.gray, 50))
hline(-1)