RSI Fractal Energy with Signal Line
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Cookie1245

//@version=5
indicator("RSI Fractal Energy with Signal Line", overlay=false)

// RSI Inputs
rsiLength = input(14, title="RSI Length")
rsiSource = close

// Fractal Inputs
fractalLength = input(5, title="Fractal Length")

// Signal Line Inputs
signalPeriod = input(9, title="Signal Line Period")

// Calculate RSI
rsiValue = ta.rsi(rsiSource, rsiLength)

// Calculate Fractals
higherHigh = ta.highest(high, fractalLength)
lowerLow = ta.lowest(low, fractalLength)

// Calculate Fractal Energy
energy = math.abs(rsiValue - 50) * 2

// Calculate Signal Line
signalLine = ta.sma(energy, signalPeriod)

// Plotting
plot(energy, title="RSI Fractal Energy", color=color.blue, linewidth=2)
plot(signalLine, title="Signal Line", color=color.red, linewidth=1)

// Plot Overbought/Oversold Levels
hline(70, title="Overbought", color=color.red, linestyle=hline.style_dashed)
hline(30, title="Oversold", color=color.green, linestyle=hline.style_dashed)
