#
# TD Ameritrade IP Company, Inc. (c) 2008-2020
#
declare lower;
input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 13;
input percentKLength = 25;
def min_low = Lowest(low, percentKLength);
def max_high = Highest(high, percentKLength);
def rel_diff = close - (max_high + min_low) / 2;
def diff = max_high - min_low;
def avgrel = ExpAverage(ExpAverage(rel_diff, percentDLength), percentDLength);
def avgdiff = ExpAverage(ExpAverage(diff, percentDLength), percentDLength);
plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
SMI.SetDefaultColor(Color.ORANGE);
plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(Color.LIGHT_GREEN);
plot overbought = over_bought;
overbought.SetDefaultColor(Color.GRAY);
plot oversold = over_sold;
oversold.SetDefaultColor(Color.GRAY);
# Add a histogram -- mfsteve 12/10/20
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.WHITE);
plot wave = SMI - AvgSMI;
wave.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
wave.SetLineWeight(5);
wave.SetDefaultColor(Color.RED);