K's Reversal Indicator III
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Sofien-Kaabar

//@version=5
indicator("K's Reversal Indicator III", overlay = true)

// Defining the variables
price_return = close - close[1]
rsi = ta.rsi(close, 14)

// Calculating the correlation of price returns
correlation_measure = ta.correlation(price_return, price_return[14], 14)

// Generating signals
bullish_signal = correlation_measure > 0.60 and rsi < 40
bearish_signal = correlation_measure > 0.60 and rsi > 60

// Plotting signals
plotshape(bullish_signal,  style = shape.triangleup,   color = color.blue,   location =  location.belowbar, size = size.small)
plotshape(bearish_signal,  style = shape.triangledown, color = color.orange, location =  location.abovebar, size = size.small)