// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © julzen2

//@version=5
indicator("Stochastic RSI [Ehlers]", overlay=false)

// === Input Parameters ===
rsiLength = input.int(5, title="RSI Length")
stocLength = input.int(5, title="Stochastic Length")
wmaLength = input.int(5, title="WMA Length")

// === Step 1: Calculate RSI ===
rsi = ta.rsi(close, rsiLength)

// === Step 2: Calculate Highest High and Lowest Low of RSI over Stochastic Length ===
hh = ta.highest(rsi, stocLength)
ll = ta.lowest(rsi, stocLength)

// === Step 3: Normalize RSI into Stochastic RSI ===
value1 = rsi - ll
value2 = hh - ll
value3 = value2 != 0 ? value1 / value2 : 0.0

// === Step 4: Smooth with WMA and scale ===
smoothed = ta.wma(value3, wmaLength)
stocRSI = 2.0 * (smoothed - 0.5)
trigger = stocRSI[1]

// === Plotting ===
plot(stocRSI, title="Stochastic RSI", color=color.red)
plot(trigger, title="Trigger", color=color.blue)
hline(0, color=color.gray, linestyle=hline.style_dotted)
hline(1, "Upper", color=color.gray, linestyle=hline.style_dashed)
hline(-1, "Lower", color=color.gray, linestyle=hline.style_dashed)
