Price Exhaustion Indicator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © profitprotrading
//@version=5
indicator(title='Price Exhaustion Indicator', shorttitle='PE', overlay=false)

//Input parameters
fastLength = input.int(12, minval=1, title='Fast Length')
slowLength = input.int(26, minval=1, title='Slow Length')
signalSmoothing = input.int(9, minval=1, title='Signal Smoothing')
atrLength = input.int(14, minval=1, title='ATR Length')
stochLength = input.int(14, minval=1, title='Stochastic Length')
smoothK = input.int(3, minval=1, title='Stochastic %K Smoothing')

//MACD
[macdLine, signalLine, _] = ta.macd(close, fastLength, slowLength, signalSmoothing)

// ATR
atrValue = ta.atr(atrLength)

//Stochastic Oscillator
stochK = ta.sma(ta.stoch(close, high, low, stochLength), smoothK)

// Calculate price exhaustion
exhaustion = macdLine / atrValue * stochK


//Colors
color = color.from_gradient(exhaustion, -20, 40, color.purple, color.white)
color2 = color.from_gradient(exhaustion, 40, 100, color.white, color.purple)

//Plotting
ex1 = plot(exhaustion, title='Trend Exhaustion', color= exhaustion < 40? color: color2, linewidth=2)
plotchar(ta.crossunder(exhaustion, 100), char = "🞄", location = location.top, color = color.rgb(198, 0, 0), size = size.tiny)
plotchar(ta.crossunder(exhaustion, -20), char = "🞄", location = location.bottom, color = color.rgb(0, 186, 6), size = size.tiny)

top = plot(100, color = color.gray, display = display.none)
bottom = plot(-20, color = color.gray, display = display.none)
mid = plot(40, title='Exhaustion Threshold', color=color.red, display = display.none)
fill(mid,bottom, top_value = 40, bottom_value = -20, top_color = color.rgb(0, 0, 0, 100), bottom_color = color.rgb(0, 255, 8, 78))
fill(mid,top, top_value = 100, bottom_value = 40, top_color = color.rgb(255, 0, 0, 78), bottom_color = color.rgb(0, 0, 0, 100))
fill(ex1, top, 200, 100, top_color = color.new(#960091, 0), bottom_color = color.new(#960091, 100),  title = "Overbought Gradient Fill")
fill(ex1, bottom, -20,  -70,  top_color = color.new(#960091, 100), bottom_color = color.new(#960091, 0),      title = "Oversold Gradient Fill")