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