Dynamic Reactor [CHE]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © chervolino
// Dynamic Reactor [CHE] indicator displays dynamic support and resistance levels.
// Green lines represent resistance, red lines represent support, and gray lines represent areas of consolidation.
// The length of the indicator can be adjusted with the lengthMA input.
//@version=5
indicator("Dynamic Reactor [CHE]", shorttitle="DR [CHE]", overlay=true)

//Inputs
lengthMA = input(50, 'Length DR', inline='Inp', group='Input')
color green = input(#00e677f6, inline='Col', group='Color')
color red = input(#ff5252, inline='Col', group='Color')
color gray =input(#787b86, inline='Col', group='Color')

// Function
dyn_rea(src, len) =>
    var smma = 0.0
	h = ta.sma(src, len)
    smma := na(smma[1]) ? h : (smma[1] * (len - 1) + src) / len
    smma

// Calculation
hi=dyn_rea(high, lengthMA)
lo=dyn_rea(low, lengthMA)
mi=(hi-lo)/2+lo

// Plots
a=plot(hi,"", hlc3>hi?green:hlc3<lo?red:gray)
b=plot(lo,"", hlc3>hi?green:hlc3<lo?red:gray)
c=plot(mi,"", hlc3>hi?green:hlc3<lo?red:gray)
fill(a,b,hlc3>hi?color.new(green,60):hlc3<lo?color.new(red,60):color.gray)