SMA Regime
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mslade50

//@version=5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © mslade50

//@version=5
indicator("SMA Regime", overlay=false)
iSMA = input(200,"Period SMA")
hline(0)
smasample = ta.sma(close,iSMA) 
smaslope = (smasample-ta.sma(close[1],iSMA))/smasample
iclose = close - smasample
plotcolor = (iclose<0 and smaslope<0) ? #880E4F:
 (iclose>=0 and smaslope>0) ? #4CAF50:
  (iclose<=0 and smaslope>0) ? #FFEB3B:
  (iclose>=0 and smaslope<0) ? #FFEB3B: #787B86	
plot(smaslope, title="Regime", color=plotcolor, linewidth=2, style=plot.style_area)