#### netarchitech

##### Well-known member

**VIP**

**SMI**=

**S**tochastic

**M**omentum

**I**ndex

**DSS**=

**D**ouble

**S**moothed

**S**tochastics

**EUO**=

**E**hlers

**U**niversal

**O**scillator

@HighBredCloud Please find the latest SMI/DSS below:

Code:

```
# filename: _SMI_DSS_
# Stochastic_Momentum_Index
# original author: TDAmeritrade
# enhancements: netarchitech as requested by @HighBredCloud
# V1.01.2019.10.20
# V1.02.2019.11.04
declare lower;
input percentDLength = 3;
input percentKLength = 5;
input showBreakoutSignals = {default "No", "On SMI", "On AvgSMI", "On SMI & AvgSMI"};
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(getColor(6));
smi.setLineWeight(2);
plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));
avgsmi.setLineWeight(2);
# Slow Line
input N2_Period = 21;
input R2_Period = 5;
def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def X2 = ExpAverage(Y2, R2_period);
def Lxn = Lowest(x2, n2_period);
def Hxn = Highest(x2, n2_period);
def DSS = ((X2 - Lxn)/(Hxn - Lxn)) * 100;
def DSSb = ExpAverage(Dss, R2_period);
#DSSb.setdefaultColor(Color.GREEN);
plot DSSsignal = DSSb[1];
DSSsignal.AssignValueColor(if DSSb>DSSsignal then Color.Green else Color.Red);
DSSsignal.SetLineWeight(3);
plot ZeroLine = 0;
Zeroline.SetDefaultColor(GetColor(4));
def over_bought = 40;
plot overbought = over_bought;
overbought.SetDefaultColor(GetColor(4));
overbought.HideTitle();
def over_sold = -40;
plot oversold = over_sold;
oversold.SetDefaultColor(GetColor(4));
oversold.HideTitle();
AddCloud(if SMI >= 40 then SMI else Double.NaN, over_bought, Color.RED, Color.RED);
AddCloud(if SMI <= -40 then SMI else Double.NaN, over_sold, Color.GREEN, Color.GREEN);
AddCloud(Zeroline, over_bought, Color.DARK_RED, Color.DARK_RED);
AddCloud(over_sold, Zeroline, Color.DARK_GREEN, Color.DARK_GREEN);
def upSMI = SMI crosses above OverSold;
def upAvgSMI = AvgSMI crosses above OverSold;
def downSMI = SMI crosses below OverBought;
def downAvgSMI = AvgSMI crosses below OverBought;
plot UpSignal;
UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
UpSignal.SetLineWeight(3);
plot DownSignal;
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
DownSignal.SetLineWeight(3);
switch (showBreakoutSignals) {
case "No":
UpSignal = Double.NaN;
DownSignal = Double.NaN;
case "On SMI":
UpSignal = if upSMI then OverSold else Double.NaN;
DownSignal = if downSMI then OverBought else Double.NaN;
case "On AvgSMI":
UpSignal = if upAvgSMI then OverSold else Double.NaN;
DownSignal = if downAvgSMI then OverBought else Double.NaN;
case "On SMI & AvgSMI":
UpSignal = if upSMI or upAvgSMI then OverSold else Double.NaN;
DownSignal = if downSMI or downAvgSMI then OverBought else Double.NaN;
}
UpSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
DownSignal.setHiding(showBreakoutSignals == showBreakoutSignals."No");
```

Please don't hesitate to let me know if there are any adjustments/changes needing to be made...

Last edited: