SMI_DSS_EUO Indicator for ThinkorSwim

HighBredCloud

Well-known member
VIP
@netarchitech I took a look at post #22 above for the OB/OS mods. Consider your code definitions :

def over_bought = 1;
plot overbought = over_bought;

def over_sold = -1;
plot oversold = over_sold;

AddCloud(if SMI >= 1 then SMI else Double.NaN, over_bought, Color.RED, Color.RED);
AddCloud(if SMI <= -1 then SMI else Double.NaN, over_sold, Color.GREEN, Color.GREEN);

Since this is already a bounder oscillator between -1 and 1, adding a cloud at those defined OB/OS levels will not yield a cloud. Probably best to do something like normalize the scale from 0 to 100 and then set the OB/OS to 70/30 or 80/20 or such like
@tomsk The OB/OS lines are for the SMI...which have a value of -40 and 40...not sure if doing the 70/30 or 80/20 would yield the same results for the OB/OS settings of the SMI...any ideas?
 

netarchitech

Well-known member
VIP
Three different indicators fully normalized!

smi.png


Code:
# filename: MR__EZ_SMI_DSS_EUO_

# original authors: TDAmeritrade and LazyBear
# enhancements: netarchitech as requested by @HighBredCloud
#               normalized code sample courtesy of @tomsk
# V1.01.2019.11.06
# V1.02.2019.11.16
# V1.03.2019.11.17

declare lower;

input PaintBars = no;
input showHistogram = yes;
input showBreakoutSignals = {default "No", "On SMI", "On AvgSMI", "On SMI & AvgSMI"};

input MinValue = -50; 
input MaxValue = 50; 

input percentDLength = 3;
input percentKLength = 5;

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;
#plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) else 0;
SMI.hide();

plot PlotToNormalize = SMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize.SetHiding(1);
plot NormalizedSMI =  (MaxValue - MinValue) * (PlotToNormalize - LowestAll(PlotToNormalize))/ (HighestAll(PlotToNormalize) - LowestAll(PlotToNormalize))+ MinValue;
NormalizedSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedSMI.SetDefaultColor(GetColor(6));
NormalizedSMI.SetLineWeight(2);

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.hide();

plot PlotToNormalize1 = AvgSMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize1.SetHiding(1);
plot NormalizedAvgSMI =  (MaxValue - MinValue) * (PlotToNormalize1 - LowestAll(PlotToNormalize1))/ (HighestAll(PlotToNormalize1) - LowestAll(PlotToNormalize1))+ MinValue;
NormalizedAvgSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedAvgSMI.SetDefaultColor(GetColor(5));
NormalizedAvgSMI.SetLineWeight(2);

# DSS
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 Y2 = ((close - Ln2) / (Hn2 - Ln2));
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 DSS = ((X2 - Lxn) / (Hxn - Lxn));
def DSSb = ExpAverage(DSS, R2_Period);
plot DSSsignal = DSSb[1];

plot PlotToNormalize2 = DSSsignal;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize2.SetHiding(1);
plot NormalizedDSS =  (MaxValue - MinValue) * (PlotToNormalize2 - LowestAll(PlotToNormalize2))/ (HighestAll(PlotToNormalize2) - LowestAll(PlotToNormalize2))+ MinValue;
NormalizedDSS.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
NormalizedDSS.AssignValueColor(if DSSb > NormalizedDSS then Color.GREEN else Color.RED);
NormalizedDSS.SetLineWeight(3);

#EUO
input bandedge = 20;
input lengthMA = 9;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);
def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;
def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];
def denom = if pk == 0 then -1 else pk;
def euo = if denom == -1 then euo[1] else filt1 / pk;
plot euoMA = ExpAverage(euo, lengthMA);
euoMA.hide();

plot PlotToNormalize3 = euo;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize3.SetHiding(1);
plot NormalizedEUO =  (MaxValue - MinValue) * (PlotToNormalize3 - LowestAll(PlotToNormalize3))/ (HighestAll(PlotToNormalize3) - LowestAll(PlotToNormalize3))+ MinValue;
#NormalizedPlot3.SetPaintingStrategy(PaintingStrategy.line);
NormalizedEUO.hide();

plot hist = if showHistogram then NormalizedEUO else Double.NaN;
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(5);
hist.DefineColor("Positive and Up", Color.GREEN);
hist.DefineColor("Positive and Down", Color.DARK_GREEN);
hist.DefineColor("Negative and Down", Color.RED);
hist.DefineColor("Negative and Up", Color.DARK_RED);
hist.AssignValueColor(if hist >= 0 then if hist > hist[1] then hist.Color("Positive and Up") else hist.Color("Positive and Down") else if hist < hist[1] then hist.Color("Negative and Down") else hist.Color("Negative and Up"));


plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(4));
ZeroLine.HideTitle();

def over_bought = 40;
def overbought = over_bought;

def over_sold = -40;
def oversold = over_sold;

plot OS = if !isNaN(close) then OverSold else Double.NaN;
OS.SetPaintingStrategy(PaintingStrategy.Line);
OS.SetLineWeight(2);
OS.SetDefaultColor(Color.ORANGE);

plot OB = if !IsNaN(close) then OverBought else Double.NaN;
OB.SetPaintingStrategy(PaintingStrategy.Line);
OB.SetLineWeight(2);
OB.SetDefaultColor(Color.ORANGE);

def upSMI = NormalizedSMI crosses above oversold;
def upAvgSMI = NormalizedAvgSMI crosses above oversold;
def downSMI = NormalizedSMI crosses below overbought;
def downAvgSMI = NormalizedAvgSMI 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");

AssignPriceColor(if PaintBars then (if euo >= 0 then Color.GREEN else Color.RED) else Color.CURRENT);

AddCloud(NormalizedSMI, NormalizedAvgSMI, Color.GREEN, Color.RED);
 

netarchitech

Well-known member
VIP
@12matthew09 Try this...

Code:
input MinValue = -50; 
input MaxValue = 50; 

#SMI
input percentDLength = 3;
input percentKLength = 5;

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);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
def PlotToNormalize = SMI;   
def NormalizedSMI =  (MaxValue - MinValue) * (PlotToNormalize - LowestAll(PlotToNormalize))/ (HighestAll(PlotToNormalize) - LowestAll(PlotToNormalize))+ MinValue;

def AvgSMI = ExpAverage(SMI, percentDLength);
def PlotToNormalize1 = AvgSMI;
def NormalizedAvgSMI =  (MaxValue - MinValue) * (PlotToNormalize1 - LowestAll(PlotToNormalize1))/ (HighestAll(PlotToNormalize1) - LowestAll(PlotToNormalize1))+ MinValue;

# DSS
def N2_Period = 21;
def R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
#def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def Y2 = ((close - Ln2) / (Hn2 - Ln2));
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 DSS = ((X2 - Lxn) / (Hxn - Lxn));
def DSSb = ExpAverage(DSS, R2_Period);
def DSSsignal = DSSb[1];

def PlotToNormalize2 = DSSsignal;
def NormalizedDSS =  (MaxValue - MinValue) * (PlotToNormalize2 - LowestAll(PlotToNormalize2))/ (HighestAll(PlotToNormalize2) - LowestAll(PlotToNormalize2))+ MinValue;

#EUO
def bandedge = 20;
def lengthMA = 9;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);
def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;
def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];
def denom = if pk == 0 then -1 else pk;
def euo = if denom == -1 then euo[1] else filt1 / pk;
def euoMA = ExpAverage(euo, lengthMA);

def PlotToNormalize3 = euo; 
def NormalizedEUO =  (MaxValue - MinValue) * (PlotToNormalize3 - LowestAll(PlotToNormalize3))/ (HighestAll(PlotToNormalize3) - LowestAll(PlotToNormalize3))+ MinValue;

def over_bought = 40;
def overbought = over_bought;

def over_sold = -40;
def oversold = over_sold;

def OS = if !isNaN(close) then OverSold else Double.NaN;

def OB = if !IsNaN(close) then OverBought else Double.NaN;

def upSMI = NormalizedSMI crosses above oversold;
def upAvgSMI = NormalizedAvgSMI crosses above oversold;
def downSMI = NormalizedSMI crosses below overbought;
def downAvgSMI = NormalizedAvgSMI crosses below overbought;

plot scan = if NormalizedSMI crosses below overbought and NormalizedEUO crosses below overbought then 1 else 0;
 

HighBredCloud

Well-known member
VIP
@netarchitech I don't want to be the one giving the bad news as I know you worked so hard on this but the new SMI DSS EUO code...the OB/OS lines still do not reflect the same settings as the original Stochastic Momentum Index...
 

HighBredCloud

Well-known member
VIP
@netarchitech The original Stochastic Momentum Index is in the TOS with the values of 40 OB -40 OS...same periods as you have 3, 5...I just noticed that you have 50 and -50...perhaps I can just change that in the code on my end to see if that works. Sometimes you just need a second set of eyes on it...With the all the lines of code it's easy to miss things.

EDIT: So I changed the -50/50 to -40/40 and still the same issue as compared to the original Stochastic Momentum Index...
 

netarchitech

Well-known member
VIP
Thanks @HighBredCloud The 50/50 setting was for the normalization...it doesn't have to do with the OB/OS...if you change it to 40/40, the plots will not go past 40 rendering the OB/OS obsolete...

Thanks for the second set of eyes :cool:
 

12matthew09

New member
@netarchitech Hey buddy, still no luck with the new code and trying to put in the old code doesnt work either. I dont know if you changed the old code but however I'll send a screen shot. I learned that yall like to see the codes but there are other messages popping up and I just want to be sure.


 

tomsk

Well-known member
VIP
@12matthew09 Since you're doing a scan, try the following:

1. Start a new scan...

2. Enter in the following code in a new custom study:

Code:
def percentDLength = 3;
def percentKLength = 5;

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);

SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) else 0;

def bandedge = 20;
def lengthMA = 9;
def price = close;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);

def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;

def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];

def denom = if pk == 0 then -1 else pk;

def euo = if denom == -1 then euo[1] else filt1 / pk;

plot scan = if SMI crosses below -0.7 and EUO crosses below -0.9 then 1 else 0;

Hope this helps :)

@netarchitech The problem faced by @12matthew09 in using this scan is that in your posted scan code, the variable SMI had a missing def
To fix this just insert the keyword "def" before the statement

SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) else 0;

Once this is done, the scan editor will no longer flag any syntax errors. Whether or not it returns any results would be a function of the code in the logic. Having said that I note that you had posted another scan based on your normalized code.

Hope this helps
 

netarchitech

Well-known member
VIP
@12matthew09 Thanks to @tomsk you can run the following code and should not receive an error...I tested where both the SMI and the EUO cross below "overbought"...it ran with no errors and returned the "no matching symbols" message...Since the code has been normalized, the -0.7 (SMI) and -0.9 (EUO) have to be adjusted...feel free to modify the last line of the code to meet your criteria...

Code:
input MinValue = -50;
input MaxValue = 50;

#SMI
input percentDLength = 3;
input percentKLength = 5;

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);

def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
def PlotToNormalize = SMI;   
def NormalizedSMI =  (MaxValue - MinValue) * (PlotToNormalize - LowestAll(PlotToNormalize))/ (HighestAll(PlotToNormalize) - LowestAll(PlotToNormalize))+ MinValue;

def AvgSMI = ExpAverage(SMI, percentDLength);
def PlotToNormalize1 = AvgSMI;
def NormalizedAvgSMI =  (MaxValue - MinValue) * (PlotToNormalize1 - LowestAll(PlotToNormalize1))/ (HighestAll(PlotToNormalize1) - LowestAll(PlotToNormalize1))+ MinValue;

# DSS
def N2_Period = 21;
def R2_Period = 5;

def Ln2 = Lowest(low, N2_Period);
def Hn2 = Highest(high, N2_Period);
#def Y2 = ((close - Ln2)/(Hn2 - Ln2)) * 100;
def Y2 = ((close - Ln2) / (Hn2 - Ln2));
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 DSS = ((X2 - Lxn) / (Hxn - Lxn));
def DSSb = ExpAverage(DSS, R2_Period);
def DSSsignal = DSSb[1];

def PlotToNormalize2 = DSSsignal;
def NormalizedDSS =  (MaxValue - MinValue) * (PlotToNormalize2 - LowestAll(PlotToNormalize2))/ (HighestAll(PlotToNormalize2) - LowestAll(PlotToNormalize2))+ MinValue;

#EUO
def bandedge = 20;
def lengthMA = 9;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);
def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;
def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];
def denom = if pk == 0 then -1 else pk;
def euo = if denom == -1 then euo[1] else filt1 / pk;
def euoMA = ExpAverage(euo, lengthMA);

def PlotToNormalize3 = euo;
def NormalizedEUO =  (MaxValue - MinValue) * (PlotToNormalize3 - LowestAll(PlotToNormalize3))/ (HighestAll(PlotToNormalize3) - LowestAll(PlotToNormalize3))+ MinValue;

def over_bought = 40;
def overbought = over_bought;

def over_sold = -40;
def oversold = over_sold;

def OS = if !isNaN(close) then OverSold else Double.NaN;

def OB = if !IsNaN(close) then OverBought else Double.NaN;

def upSMI = NormalizedSMI crosses above oversold;
def upAvgSMI = NormalizedAvgSMI crosses above oversold;
def downSMI = NormalizedSMI crosses below overbought;
def downAvgSMI = NormalizedAvgSMI crosses below overbought;

plot scan = if NormalizedSMI crosses below overbought and NormalizedEUO crosses below overbought then 1 else 0;
 

netarchitech

Well-known member
VIP
I will test it just let me know the final version.
@HighBredCloud Below please find the latest SMI_DSS_EUO for your review...Looking forward to your findings :) Thanks!

Code:
# filename: MR__EZ_SMI_DSS_EUO_

# original authors: TDAmeritrade and LazyBear
# enhancements: netarchitech as requested by @HighBredCloud
#               normalized code sample courtesy of @tomsk
# V1.01.2019.11.06
# V1.02.2019.11.16
# V1.03.2019.11.17

declare lower;

input PaintBars = no;
input showHistogram = yes;
input showBreakoutSignals = {default "No", "On SMI", "On AvgSMI", "On SMI & AvgSMI"};

input MinValue = -50;
input MaxValue = 50;

input percentDLength = 3;
input percentKLength = 5;

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;
#plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) else 0;
SMI.hide();

plot PlotToNormalize = SMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize.SetHiding(1);
plot NormalizedSMI =  (MaxValue - MinValue) * (PlotToNormalize - LowestAll(PlotToNormalize))/ (HighestAll(PlotToNormalize) - LowestAll(PlotToNormalize))+ MinValue;
NormalizedSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedSMI.SetDefaultColor(GetColor(6));
NormalizedSMI.SetLineWeight(2);

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.hide();

plot PlotToNormalize1 = AvgSMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize1.SetHiding(1);
plot NormalizedAvgSMI =  (MaxValue - MinValue) * (PlotToNormalize1 - LowestAll(PlotToNormalize1))/ (HighestAll(PlotToNormalize1) - LowestAll(PlotToNormalize1))+ MinValue;
NormalizedAvgSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedAvgSMI.SetDefaultColor(GetColor(5));
NormalizedAvgSMI.SetLineWeight(2);

# DSS
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 Y2 = ((close - Ln2) / (Hn2 - Ln2));
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 DSS = ((X2 - Lxn) / (Hxn - Lxn));
def DSSb = ExpAverage(DSS, R2_Period);
plot DSSsignal = DSSb[1];

plot PlotToNormalize2 = DSSsignal;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize2.SetHiding(1);
plot NormalizedDSS =  (MaxValue - MinValue) * (PlotToNormalize2 - LowestAll(PlotToNormalize2))/ (HighestAll(PlotToNormalize2) - LowestAll(PlotToNormalize2))+ MinValue;
NormalizedDSS.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
NormalizedDSS.AssignValueColor(if DSSb > NormalizedDSS then Color.GREEN else Color.RED);
NormalizedDSS.SetLineWeight(3);

#EUO
input bandedge = 20;
input lengthMA = 9;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);
def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;
def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];
def denom = if pk == 0 then -1 else pk;
def euo = if denom == -1 then euo[1] else filt1 / pk;
plot euoMA = ExpAverage(euo, lengthMA);
euoMA.hide();

plot PlotToNormalize3 = euo;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize3.SetHiding(1);
plot NormalizedEUO =  (MaxValue - MinValue) * (PlotToNormalize3 - LowestAll(PlotToNormalize3))/ (HighestAll(PlotToNormalize3) - LowestAll(PlotToNormalize3))+ MinValue;
#NormalizedPlot3.SetPaintingStrategy(PaintingStrategy.line);
NormalizedEUO.hide();

plot hist = if showHistogram then NormalizedEUO else Double.NaN;
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(5);
hist.DefineColor("Positive and Up", Color.GREEN);
hist.DefineColor("Positive and Down", Color.DARK_GREEN);
hist.DefineColor("Negative and Down", Color.RED);
hist.DefineColor("Negative and Up", Color.DARK_RED);
hist.AssignValueColor(if hist >= 0 then if hist > hist[1] then hist.Color("Positive and Up") else hist.Color("Positive and Down") else if hist < hist[1] then hist.Color("Negative and Down") else hist.Color("Negative and Up"));


plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(4));
ZeroLine.HideTitle();

def over_bought = 40;
def overbought = over_bought;

def over_sold = -40;
def oversold = over_sold;

plot OS = if !isNaN(close) then OverSold else Double.NaN;
OS.SetPaintingStrategy(PaintingStrategy.Line);
OS.SetLineWeight(2);
OS.SetDefaultColor(Color.ORANGE);

plot OB = if !IsNaN(close) then OverBought else Double.NaN;
OB.SetPaintingStrategy(PaintingStrategy.Line);
OB.SetLineWeight(2);
OB.SetDefaultColor(Color.ORANGE);

def upSMI = NormalizedSMI crosses above oversold;
def upAvgSMI = NormalizedAvgSMI crosses above oversold;
def downSMI = NormalizedSMI crosses below overbought;
def downAvgSMI = NormalizedAvgSMI 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");

AssignPriceColor(if PaintBars then (if euo >= 0 then Color.GREEN else Color.RED) else Color.CURRENT);

AddCloud(NormalizedSMI, NormalizedAvgSMI, Color.GREEN, Color.RED);
 

netarchitech

Well-known member
VIP
Glad to help and real good job on normalizing the SMI DSS EUO by the way
Thanks @tomsk Your compliment and support means a lot to me :)

what does the DSS stand for in the SMI DSS EUO
@tomsk The acronym stands for Double Smooth Stochastics...There was a time when it was called Double Full Stochastics...Ultimately, the name, like many around here lately, are just acronyms...The original conversion was done by rmejia over at futures.io...On that note, I hope to find some time to redo the headers of these scripts to properly reflect the original contributors...
 

netarchitech

Well-known member
VIP
I see what you are saying...I would have thought the normalization would have fixed things...what if we amped up the Min/Max settings to 100/-100...?
 

netarchitech

Well-known member
VIP
Try this @HighBredCloud

Code:
# filename: MR__EZ_SMI_DSS_EUO_

# original authors: TDAmeritrade and LazyBear
# enhancements: netarchitech as requested by @HighBredCloud
#               normalized code sample courtesy of @tomsk
# V1.01.2019.11.06
# V1.02.2019.11.16
# V1.03.2019.11.17

declare lower;

input PaintBars = no;
input showHistogram = yes;
input showBreakoutSignals = {default "No", "On SMI", "On AvgSMI", "On SMI & AvgSMI"};

input MinValue = -100;
input MaxValue = 100;

input percentDLength = 3;
input percentKLength = 5;

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;
#plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) else 0;
SMI.hide();

plot PlotToNormalize = SMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize.SetHiding(1);
plot NormalizedSMI =  (MaxValue - MinValue) * (PlotToNormalize - LowestAll(PlotToNormalize))/ (HighestAll(PlotToNormalize) - LowestAll(PlotToNormalize))+ MinValue;
NormalizedSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedSMI.SetDefaultColor(GetColor(6));
NormalizedSMI.SetLineWeight(2);

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.hide();

plot PlotToNormalize1 = AvgSMI;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize1.SetHiding(1);
plot NormalizedAvgSMI =  (MaxValue - MinValue) * (PlotToNormalize1 - LowestAll(PlotToNormalize1))/ (HighestAll(PlotToNormalize1) - LowestAll(PlotToNormalize1))+ MinValue;
NormalizedAvgSMI.SetPaintingStrategy(PaintingStrategy.LINE);
NormalizedAvgSMI.SetDefaultColor(GetColor(5));
NormalizedAvgSMI.SetLineWeight(2);

# DSS
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 Y2 = ((close - Ln2) / (Hn2 - Ln2));
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 DSS = ((X2 - Lxn) / (Hxn - Lxn));
def DSSb = ExpAverage(DSS, R2_Period);
plot DSSsignal = DSSb[1];

plot PlotToNormalize2 = DSSsignal;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize2.SetHiding(1);
plot NormalizedDSS =  (MaxValue - MinValue) * (PlotToNormalize2 - LowestAll(PlotToNormalize2))/ (HighestAll(PlotToNormalize2) - LowestAll(PlotToNormalize2))+ MinValue;
NormalizedDSS.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
NormalizedDSS.AssignValueColor(if DSSb > NormalizedDSS then Color.GREEN else Color.RED);
NormalizedDSS.SetLineWeight(3);

#EUO
input bandedge = 20;
input lengthMA = 9;

def whitenoise = (close - close[2]) / 2;
def a1 = ExpAverage(-1.414 * 3.14159 / bandedge);
def b1 = 2.0 * a1 * Cos(1.414 * 180 / bandedge);
def c2 = b1;
def c3 = -a1 * a1;
def c1 = 1 - c2 - c3;

def filt = c1 * (whitenoise + (whitenoise[1])) / 2 + c2 * (filt[1]) + c3 * (filt[2]);
def filt1 = if TotalSum(1) == 0 then 0 else if TotalSum(1) == 2 then c2 * filt1[1] else if TotalSum(1) == 3 then c2 * filt1[1] + c3 * (filt1[2]) else filt;
def pk = if TotalSum(1) == 2 then .0000001 else if AbsValue(filt1) > pk[1] then AbsValue(filt1) else 0.991 * pk[1];
def denom = if pk == 0 then -1 else pk;
def euo = if denom == -1 then euo[1] else filt1 / pk;
plot euoMA = ExpAverage(euo, lengthMA);
euoMA.hide();

plot PlotToNormalize3 = euo;  # replace close with the name of the plot you wish to normalize   
PlotToNormalize3.SetHiding(1);
plot NormalizedEUO =  (MaxValue - MinValue) * (PlotToNormalize3 - LowestAll(PlotToNormalize3))/ (HighestAll(PlotToNormalize3) - LowestAll(PlotToNormalize3))+ MinValue;
#NormalizedPlot3.SetPaintingStrategy(PaintingStrategy.line);
NormalizedEUO.hide();

plot hist = if showHistogram then NormalizedEUO else Double.NaN;
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(5);
hist.DefineColor("Positive and Up", Color.GREEN);
hist.DefineColor("Positive and Down", Color.DARK_GREEN);
hist.DefineColor("Negative and Down", Color.RED);
hist.DefineColor("Negative and Up", Color.DARK_RED);
hist.AssignValueColor(if hist >= 0 then if hist > hist[1] then hist.Color("Positive and Up") else hist.Color("Positive and Down") else if hist < hist[1] then hist.Color("Negative and Down") else hist.Color("Negative and Up"));


plot ZeroLine = 0;
ZeroLine.SetDefaultColor(GetColor(4));
ZeroLine.HideTitle();

def over_bought = 40;
def overbought = over_bought;

def over_sold = -40;
def oversold = over_sold;

plot OS = if !isNaN(close) then OverSold else Double.NaN;
OS.SetPaintingStrategy(PaintingStrategy.Line);
OS.SetLineWeight(2);
OS.SetDefaultColor(Color.ORANGE);

plot OB = if !IsNaN(close) then OverBought else Double.NaN;
OB.SetPaintingStrategy(PaintingStrategy.Line);
OB.SetLineWeight(2);
OB.SetDefaultColor(Color.ORANGE);

def upSMI = NormalizedSMI crosses above oversold;
def upAvgSMI = NormalizedAvgSMI crosses above oversold;
def downSMI = NormalizedSMI crosses below overbought;
def downAvgSMI = NormalizedAvgSMI 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");

AssignPriceColor(if PaintBars then (if euo >= 0 then Color.GREEN else Color.RED) else Color.CURRENT);

AddCloud(NormalizedSMI, NormalizedAvgSMI, Color.GREEN, Color.RED);
 

HighBredCloud

Well-known member
VIP
@horserider I think the SMI DSS EUO looks good for being 3 indicators in one but looks are subjective...there is only so much you can do to make it look functional and make it look good while having an indicator that is effective...I also like the fact that the user can literally uncheck the studies that they don't want...So if you don't want the DSS...no problem...unclick check plot...No SMI...No problem...The fact that this indicator is fully customizable is great IMO...

Here's a fourth option to how the SMI DSS EUO can look like in its full capacity...

 

Similar threads

Top