SMI Ergodic Indicator + Oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © The_Estonian_

//@version=5
indicator(title="SMI Ergodic Indicator+Oscillator", shorttitle="SMIIO", format=format.price, precision=4, timeframe="", timeframe_gaps=true)
longlen = input.int(20, minval=1, title="Long Length")
shortlen = input.int(5, minval=1, title="Short Length")
siglen = input.int(5, minval=1, title="Signal Line Length")
erg = ta.tsi(close, shortlen, longlen)
sig = ta.ema(erg, siglen)
osc = erg - sig
plot(osc, color=#FF5252, style=plot.style_histogram, title="SMI Ergodic Oscillator")
plot(erg, color=#e700fc, title="SMI")
plot(sig, color=#ffd102, title="Signal")

plot(ta.cross(erg, sig) ? erg : na, color= #ffffff, style = plot.style_circles, linewidth = 3)

TopLine = hline(.70, "MAX", color.red)
OB = .40
OverboughtLine = hline(OB, "Overbought", color.red)
fill(TopLine, OverboughtLine, color.new(color.red, 80))

BottomLine = hline(-.70, "MAX", color.green)
OS = -.40
OverSoldLine = hline(OS, "OverSold", color=color.green)
fill(BottomLine, OverSoldLine, color.new(color.green, 80))

MiddleLine = hline(0.0, "Middle", color.white)