SMI_DSS_EUO Indicator for ThinkorSwim

netarchitech

netarchitech

Well-known member
VIP
SMI = Stochastic Momentum Index
DSS = Double Smoothed Stochastics
EUO = Ehlers Universal Oscillator

@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:
netarchitech

netarchitech

Well-known member
VIP
Hey there @HighBredCloud Thanks for the excellent and comprehensive analysis :) I will start to investigate and see if I can incorporate the modifications you suggest...

Below please find a prototype screenshot of the SMI DSS and the EUO merged together...looks great BUT there is the scaling issue again :( While they are both zero bound, the SMI DSS ranges from 40 to -40, whereas the EUO ranges from 1 to -1...

Will require further investigation to see if this ultimately be feasible...

 
Last edited:
netarchitech

netarchitech

Well-known member
VIP
@HighBredCloud I figured out the resolution to the scaling issue...The SMI_DSS_EUO should be ready for testing and analysis when you have a chance...

Needless to say, but I am looking forward to your thoughts and findings :)




Code:
# filename: _SMI_DSS_EUO_

# original authors: TDAmeritrade and LazyBear
# enhancements: netarchitech as requested by @HighBredCloud
# V1.01.2019.11.06

declare lower;

#SMI DSS

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

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));
AvgSMI.SetLineWeight(2);

AddCloud(SMI, AvgSMI, Color.GREEN, Color.RED);

# 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 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);
#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));
ZeroLine.HideTitle();

def over_bought = 1;
def overbought = over_bought;

def over_sold = -1;
def oversold = over_sold;

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


# EUO
# source: https://www.tradingview.com/script/ieFYbVdC-Ehlers-Universal-Oscillator-LazyBear/

input bandedge = 20;
input showHistogram = yes;
input showMA = no;
input lengthMA = 9;
input PaintBars = yes;
input 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;

def euoMA = ExpAverage(euo, lengthMA);

#plot zeroLine = 0;

plot hist = if showHistogram then euo else Double.NaN;
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(5);
hist.DefineColor("Positive and Up", Color.GREEN);
hist.DefineColor("Positive and Down", Color.GREEN);
hist.DefineColor("Negative and Down", Color.RED);
hist.DefineColor("Negative and Up", Color.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 ehlers_universal_oscillator = euo;
ehlers_universal_oscillator.Hide();

plot showMovAvg = if showMA then euoMA else Double.NaN;
showMovAvg.Hide();

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

HighBredCloud

Well-known member
VIP
@netarchitech Holy Cow! Just in time for the opening bell...This is going to be huge! The volatility in at the bell was unreal with basically almost everything. And guess what? The PercentR_MAC was key to look at IF the 5 EMA was above or below the 8 EMA...

Anyways...will let you know what I find with the SMI/DSS/EUO...I am so excited about this indicator!
 
H

HighBredCloud

Well-known member
VIP
@HighBredCloud Go get 'em... :cool:

OK...finally got everything set up with the indicator how I like...I really like the little touches you put in there...like the cloud in between the SMI lines...And I like the fact that the end user can select IF they want to keep the DSS line or not...For added confirmation its nice to have an option IMO...For some reason the BreakOut Signals on the SMI are not working when you select them...Also anyway to add the OB/OS lines on the SMI without having the HistoGram all crunched up? I don't know IF they would be necessary to have or not...They do show OB/OS condition on the SMI and one could reference the PercetR_MAC but I am sure they could be unselected by the "show plot" feature...will keep you updated but this thing is already rockin!
 
netarchitech

netarchitech

Well-known member
VIP
OK...finally got everything set up with the indicator how I like...I really like the little touches you put in there...like the cloud in between the SMI lines...And I like the fact that the end user can select IF they want to keep the DSS line or not...
@HighBredCloud Thanks for the compliments...I really appreciate it! To be honest, I don't remember putting in the DSS option, as I am deep in code at the moment, but I'm glad you find it useful... :cool:

The Breakout Signals...argh...as a result of merging the SMI DSS and the EUO, in order to renormalize the two indicators, both the OB/OS aspects and Breakout Signals of the SMI DSS were unfortunately sacrificed...

With that said, if there is a member of the uTS community out there who thinks they might have a fix or a way around this, I certainly would appreciate the input... :)
 
H

HighBredCloud

Well-known member
VIP
@HighBredCloud Thanks for the compliments...I really appreciate it! To be honest, I don't remember putting in the DSS option, as I am deep in code at the moment, but I'm glad you find it useful... :cool:

The Breakout Signals...argh...as a result of merging the SMI DSS and the EUO, in order to renormalize the two indicators, both the OB/OS aspects and Breakout Signals of the SMI DSS were unfortunately sacrificed...

With that said, if there is a member of the uTS community out there who thinks they might have a fix or a way around this, I certainly would appreciate the input... :)
@netarchitech Its all there with the DSS...makes a nice addition and if for whatever reason someone does not find it useful than tis simple to take off the chart. So good thing you didn't take it out. Too bad OB/OS lines as the study does move rather quickly...Was the issue because of the DSS line or was it mostly because of the OB/OS lines? I did notice that once you uncheck the DSS line...the indicator shifted a bit to the center...Not sure if that helps or not. And on some indicators you need the OB/OS line to show the breakout signals and on some you don't...

I can check on my end if I merge the SMI DSS with the SMI/DSS/EUO and uncheck everything except for the breakout signals to see how they will appear. But like you said hopefully someone can lend a hand with that one...

From what I have tested the indicator it works really well as an exit indicator...One could enter on it as well but it just moves fast...However, by utilizing the MACD/FREMA portion when it turns GREEN...and then entering when the EUO bars turn GREEN and the SMI lines are heading for a crossover.

I couldn't get much more testing done as I have spent 3 hours on the with TOS support because it seems like when I added AutoTrendLine indicator found below along with the SMI/DSS/EUO and the rest of my indicators...it slowed down my TOS candle stick reaction to a point where on a 3 min chart there would be approx 1 min to 2 min delay when the candle would close and another was suppose to appear.

I didn't know what what causing the issue...My internet...my computer or what...So process of elimination had to happen during live market to see IF it was an indicator that was giving such issues...

And I think I found the indicator that was giving such issues code is below @BenTen to hopefully warn others using this particular AutoTrendLine indicator...Too bad tho because this was the best auto trend line indicator I have tested thus far...but not worth the delay...

Code:

Code:
#Chris' Auto Trendline

declare upper;

#################################################
# Defining High, Low and Pivot Points
#################################################
def Hi = high;
def Lo = low;
def P1H = (Hi > Hi[1] or (Hi > Hi[2] and Hi == Hi[1])) and Hi > Hi[-1];
def P1L = (Lo < Lo[1] or (Lo < Lo[2] and Lo == Lo[1])) and Lo < Lo[-1];
def lastBar = HighestAll(if !IsNaN(close) then BarNumber() else 0);
def Piv1h = if P1H[1] then 1 else Piv1h[1] + 1;
def Piv1l = if P1L[1] then 1 else Piv1l[1] + 1;
def PivN1h = fold m = 1 to lastBar with a = Double.NaN while IsNaN(a) do if GetValue(P1H, -m) then -m else Double.NaN;
def PivN1l = fold n = 1 to lastBar with b = Double.NaN while IsNaN(b) do if GetValue(P1L, -n) then -n else Double.NaN;

def prevPivhigh = GetValue(Hi, Piv1h);
def prevPivlow = GetValue(Lo, Piv1l);
def nextPivhigh = GetValue(Hi, PivN1h);
def nextPivlow = GetValue(Lo, PivN1l);
def P2H = Hi > prevPivhigh and Hi > nextPivhigh;
def P2L = Lo < prevPivlow and Lo < nextPivlow;
def p2x2 = P2H and P2L;
def Piv2h = if P2H[1] then 1 else Piv2h[1] + 1;
def Piv2l = if P2L[1] then 1 else Piv2l[1] + 1;
def PivN2h = fold o = 1 to lastBar with c = Double.NaN while IsNaN(c) do if GetValue(P2H, -o) then -o else Double.NaN;
def PivN2l = fold p = 1 to lastBar with d = Double.NaN while IsNaN(d) do if GetValue(P2L, -p) then -p else Double.NaN;
def NextP2H = if PivN2h > PivN2l then 1 else Double.NaN;
def NextP2L = if PivN2l > PivN2h then 1 else Double.NaN;
def NextP2Both = if PivN2h == PivN2l then 1 else Double.NaN;
def PrevP2H = Piv2h < Piv2l;
def PrevP2L = Piv2l < Piv2h;
def PrevP2Both = Piv2h == Piv2l;
def nearLow = if P2L and PrevP2H then Lo else nearLow[1];
def AL0 = if P2L and PrevP2L and Lo > nearLow then 1 else Double.NaN;
def AL1 = if P2L and NextP2L and GetValue(Lo, PivN2l) <= Lo then 1 else Double.NaN;
def AL2 = if p2x2 and PrevP2L and Lo > GetValue(Lo, Piv2l) then 1 else Double.NaN;
def AL3 = if P2L and PrevP2Both and !NextP2H and Lo > GetValue(Lo, Piv2l) then 1 else Double.NaN;
def AL4 = if P2L and PrevP2L and Lo > GetValue(Lo, Piv2l) then 1 else Double.NaN;
def AL5 = if P2L and PrevP2H and NextP2Both and Lo > GetValue(Lo, PivN2l) and GetValue(Hi, PivN2h) < GetValue(Hi, Piv2h) then 1 else Double.NaN;
def A2L = P2L and IsNaN(AL0) and IsNaN(AL1) and IsNaN(AL2) and IsNaN(AL3) and IsNaN(AL4) and IsNaN(AL5);
def recentHigh = if P2H and PrevP2L then Hi else recentHigh[1];
def AH0 = if P2H and PrevP2H and Hi < recentHigh then 1 else Double.NaN;
def AH1 = if P2H and NextP2H and GetValue(Hi, PivN2h) >= Hi then 1 else Double.NaN;
def AH2 = if p2x2 and PrevP2H and Hi < GetValue(Hi, Piv2h) then 1 else Double.NaN;
def AH3 = if P2H and PrevP2Both and !NextP2L and Hi < GetValue(Hi, Piv2h) then 1 else Double.NaN;
def AH4 = if P2H and PrevP2H and Hi < GetValue(Hi, Piv2h) then 1 else Double.NaN;
def AH5 = if P2H and PrevP2L and NextP2Both and Hi < GetValue(Hi, PivN2h) and GetValue(Lo, PivN2l) > GetValue(Lo, Piv2l) then 1 else Double.NaN;
def A2H = P2H and IsNaN(AH0) and IsNaN(AH1) and IsNaN(AH2) and IsNaN(AH3) and IsNaN(AH4) and IsNaN(AH5);

def PPH = if A2H[1] then 1 else PPH[1] + 1;
def PPL = if A2L[1] then 1 else PPL[1] + 1;
def HighLow = if A2L and Lo > GetValue(Lo, PPL) then 1 else Double.NaN;
def LowHigh = if A2H and Hi < GetValue(Hi, PPH) then 1 else Double.NaN;
def PivTime = if !IsNaN(HighLow) or !IsNaN(LowHigh) then PivTime[1] + 1 else PivTime[1];

#################################################
# Trend Line End Numbers
#################################################
def end1 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) then BarNumber() else 0;
def end2 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 1 then BarNumber() else 0;
def end3 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 2 then BarNumber() else 0;
def end4 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 3 then BarNumber() else 0;
def end5 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 4 then BarNumber() else 0;
def end6 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 5 then BarNumber() else 0;
def end7 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 6 then BarNumber() else 0;
def end8 = if (!IsNaN(HighLow) or !IsNaN(LowHigh)) and PivTime == HighestAll(PivTime) - 7 then BarNumber() else 0;

#################################################
# Trend Line Start Numbers
#################################################
def start1 = if end1 and !IsNaN(HighLow) then end1 - PPL else if end1 and !IsNaN(LowHigh) then end1 - PPH else 0;
def start2 = if end2 and !IsNaN(HighLow) then end2 - PPL else if end2 and !IsNaN(LowHigh) then end2 - PPH else 0;
def start3 = if end3 and !IsNaN(HighLow) then end3 - PPL else if end3 and !IsNaN(LowHigh) then end3 - PPH else 0;
def start4 = if end4 and !IsNaN(HighLow) then end4 - PPL else if end4 and !IsNaN(LowHigh) then end4 - PPH else 0;
def start5 = if end5 and !IsNaN(HighLow) then end5 - PPL else if end5 and !IsNaN(LowHigh) then end5 - PPH else 0;
def start6 = if end6 and !IsNaN(HighLow) then end6 - PPL else if end6 and !IsNaN(LowHigh) then end6 - PPH else 0;
def start7 = if end7 and !IsNaN(HighLow) then end7 - PPL else if end7 and !IsNaN(LowHigh) then end7 - PPH else 0;
def start8 = if end8 and !IsNaN(HighLow) then end8 - PPL else if end8 and !IsNaN(LowHigh) then end8 - PPH else 0;

#################################################
# Price Data
#################################################
def price1 = HighestAll(if end1 and A2L then GetValue(Lo, end1 - start1) else if end1 and A2H then GetValue(Hi, end1 - start1) else 0);
def price2 = HighestAll(if end2 and A2L then GetValue(Lo, end2 - start2) else if end2 and A2H then GetValue(Hi, end2 - start2) else 0);
def price3 = HighestAll(if end3 and A2L then GetValue(Lo, end3 - start3) else if end3 and A2H then GetValue(Hi, end3 - start3) else 0);
def price4 = HighestAll(if end4 and A2L then GetValue(Lo, end4 - start4) else if end4 and A2H then GetValue(Hi, end4 - start4) else 0);
def price5 = HighestAll(if end5 and A2L then GetValue(Lo, end5 - start5) else if end5 and A2H then GetValue(Hi, end5 - start5) else 0);
def price6 = HighestAll(if end6 and A2L then GetValue(Lo, end6 - start6) else if end6 and A2H then GetValue(Hi, end6 - start6) else 0);
def price7 = HighestAll(if end7 and A2L then GetValue(Lo, end7 - start7) else if end7 and A2H then GetValue(Hi, end7 - start7) else 0);
def price8 = HighestAll(if end8 and A2L then GetValue(Lo, end8 - start8) else if end8 and A2H then GetValue(Hi, end8 - start8) else 0);

def price01 = HighestAll(if end1 and A2L then Lo else if end1 and A2H then Hi else 0);
def price02 = HighestAll(if end2 and A2L then Lo else if end2 and A2H then Hi else 0);
def price03 = HighestAll(if end3 and A2L then Lo else if end3 and A2H then Hi else 0);
def price04 = HighestAll(if end4 and A2L then Lo else if end4 and A2H then Hi else 0);
def price05 = HighestAll(if end5 and A2L then Lo else if end5 and A2H then Hi else 0);
def price06 = HighestAll(if end6 and A2L then Lo else if end6 and A2H then Hi else 0);
def price07 = HighestAll(if end7 and A2L then Lo else if end7 and A2H then Hi else 0);
def price08 = HighestAll(if end8 and A2L then Lo else if end8 and A2H then Hi else 0);

#################################################
# Defining Trend Line
#################################################
script trendLine
{
input startBar = 0;
input startPrice = 0;
input endBar = 0;
input endPrice = 0;
input leftExt = 0;
input rightExt = 0;
input limitRight = no;

def TrendV = (endPrice - startPrice) / (endBar - startBar);
def NewBar = BarNumber() - endBar;
plot TheTrend; if !limitRight then {TheTrend = if BarNumber() >= startBar - leftExt then endPrice + NewBar * TrendV else Double.NaN;} else {TheTrend = if BarNumber() > endBar + rightExt or BarNumber() < startBar - leftExt then Double.NaN else endPrice + NewBar * TrendV;}
}

#################################################
# Trend Lines
#################################################
input howManyTrendLinesMax_8 = 4;

plot Trend1 = trendline(HighestAll(start1), price1, HighestAll(end1), price01, 5, no);
Trend1.SetDefaultColor(Color.WHITE);
Trend1.SetStyle(Curve.FIRM);
plot Trend2 = trendline(HighestAll(start2), price2, HighestAll(end2), price02, 5, no);
Trend2.setDefaultColor(color.WHITE);
Trend2.SetStyle(Curve.SHORT_DASH);
Trend2.SetHiding(howManyTrendLinesMax_8 < 2);
plot Trend3 = trendline(HighestAll(start3), price3, HighestAll(end3), price03, 5, no);
Trend3.SetDefaultColor(color.WHITE);
Trend3.SetStyle(Curve.SHORT_DASH);
Trend3.SetHiding(howManyTrendLinesMax_8 < 3);
plot Trend4 = trendline(HighestAll(start4), price4, HighestAll(end4), price04, 5, no);
Trend4.SetDefaultColor(color.WHITE);
Trend4.SetStyle(Curve.SHORT_DASH);
Trend4.SetHiding(howManyTrendLinesMax_8 < 4);
plot Trend5 = trendline(HighestAll(start5), price5, HighestAll(end5), price05, 5, no);
Trend5.SetDefaultColor(color.WHITE);
Trend5.SetStyle(Curve.SHORT_DASH);
Trend5.SetHiding(howManyTrendLinesMax_8 < 5);
plot Trend6 = trendline(HighestAll(start6), price6, HighestAll(end6), price06, 5, no);
Trend6.SetDefaultColor(color.WHITE);
Trend6.SetStyle(Curve.SHORT_DASH);
Trend6.SetHiding(howManyTrendLinesMax_8 < 6);
plot Trend7 = trendline(HighestAll(start7), price7, HighestAll(end7), price07, 5, no);
Trend7.SetDefaultColor(color.WHITE);
Trend7.SetStyle(Curve.SHORT_DASH);
Trend7.SetHiding(howManyTrendLinesMax_8 < 7);
plot Trend8 = trendline(HighestAll(start8), price8, HighestAll(end8), price08, 5, no);
Trend8.SetDefaultColor(color.WHITE);
Trend8.SetStyle(Curve.SHORT_DASH);
Trend8.SetHiding(howManyTrendLinesMax_8 < 8);

#################################################
# Arrows
#################################################
input showArrows = yes;

#Up Arrows
plot DownArrow1 = Trend1 > Trend1[1] and close crosses below Trend1;
DownArrow1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DownArrow1.SetDefaultColor(color.CYAN);
DownArrow1.SetLineWeight(5);
DownArrow1.SetHiding(!showArrows);

#Down Arrows
plot UpArrow1 = Trend1 < Trend1[1] and close crosses above Trend1;
UpArrow1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UpArrow1.SetDefaultColor(color.CYAN);
UpArrow1.SetLineWeight(5);
UpArrow1.SetHiding(!showArrows);

#################################################
# Display Box
#################################################
input ShowDisplayBox = yes;
AddLabel(ShowDisplayBox, " ->", color.DARK_GRAY);
AddLabel(ShowDisplayBox, if close > Trend1 then "Above Current Trend" else "Below Current Trend", if close > Trend1 then color.GREEN else color.RED);
AddLabel(ShowDisplayBox, "<- ", color.DARK_GRAY);

#################################################
# Alerts
#################################################
input AudibleAlerts = yes;
Alert(AudibleAlerts and UpArrow1, GetSymbol() + " Possible Breakout.", Alert.BAR, Sound.Bell);
Alert(AudibleAlerts and DownArrow1, GetSymbol() + " Possible Breakdown.", Alert.BAR, Sound.Bell);
 
H

HighBredCloud

Well-known member
VIP
@HighBredCloud Sorry to hear about your troubles today...I'm glad you've pinpointed the likely suspect :)

I've had some of my own with a particular indicator I've used for many a year until recently...It starts and stops all day long...No reason, just off and on...TOS support had me tear down my installation to bare "metal" and yet it still persists...They want to re-install the video drivers, but I'm dealing with Nvidia...meaning if you're lucky enough to find drivers that work (I have), DON'T mess with them...Needless to say, I'm not going there for a particular indicator...

In other news...I'm wrapping up another LazyBear TradingView port...this is the one that incorporates the EhlersSuperSmootherFilter...After that I'm looking to revisit PercentR_MAC and see if I can smooth out PercentR...As always, I'll keep you apprised of any/all developments...
@netarchitech Exactly not worth all this headache for just one indicator. TOS actually informed me that I may need an external video card and more memory...I was kinda shocked as I only run TOS on MacBook and it should be sufficient with 4 GB video card and 16 GB memory...I am running 4 32 in monitors tho...so who knows for sure...

I really hope that that is the only indicator that caused such a problem...could have been a disaster IF I was in an actual position. Will do more testing tonight on higher time frame after I clean up my TOS and get rid of studies I don't need to see IF that will also help with the speed...BUT I really do like the SMI/DSS/EUO thus far...I already replaced the SMI/DSS with this for sure as its perfect for exits IMO...

I would be really curious to see when you implement the EhlersSuperSmootherFilter into PercentR_MAC...that would be really something...I've been using that indicator as well. Did you see the Larry Williams ProGo indicator code that I posted? It does have a variety of moving averages...just not sure if those too could be implement into the PercentR_MAC or if it would give you an idea of how that was done as I saw it was also using Triangular Moving Averages...and those are even smoother than the EhlersSuperSmootherFilter. I can tell you that the indicators you've made thus far will work VERY WELL together...
 
1

12matthew09

New member
Hey all!

Big fan of the SMI_DDS_EUO, I actually use it for a scanner. Works very well! Thank you very much! This website is great. Anywho the only thing that I do not like about it are the colors that comes to the chart with the candles, theyre very cartoonish to me and they shrink the candles from the full view. Is there a way to undo the cartoonish look and get the candles back to the correct size?
 
H

HighBredCloud

Well-known member
VIP
@12matthew09 This indicator is bad ass...I have this on my charts as well...Serves very well on higher time frames such as 15 min+ and can be used as an early entry but works very well as an exit indicator.

@netarchitech I know we spoke about this before but do you think you could give it a second shot at this indicator and see if there is a way to add the OB/OS lines on the SMI? This is the only thing this indicator needs to be perfect!
 
netarchitech

netarchitech

Well-known member
VIP
@HighBredCloud Per your request, I've added in the OB/OS lines for your review:



Code:
# filename: MR__EZ_SMI_DSS_EUO_

# original authors: TDAmeritrade and LazyBear
# enhancements: netarchitech as requested by @HighBredCloud
# V1.01.2019.11.06
# V1.01.2019.11.16


declare lower;

#SMI DSS

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

plot AvgSMI = ExpAverage(SMI, percentDLength);
AvgSMI.SetDefaultColor(GetColor(5));
AvgSMI.SetLineWeight(2);

AddCloud(SMI, AvgSMI, Color.GREEN, Color.RED);

# 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 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);
#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));
ZeroLine.HideTitle();

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

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


# EUO
# source: https://www.tradingview.com/script/ieFYbVdC-Ehlers-Universal-Oscillator-LazyBear/

input bandedge = 20;
input showHistogram = yes;
input showMA = no;
input lengthMA = 9;
input PaintBars = yes;
input 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;

def euoMA = ExpAverage(euo, lengthMA);

#plot zeroLine = 0;

plot hist = if showHistogram then euo else Double.NaN;
hist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
hist.SetLineWeight(5);
hist.DefineColor("Positive and Up", Color.GREEN);
hist.DefineColor("Positive and Down", Color.GREEN);
hist.DefineColor("Negative and Down", Color.RED);
hist.DefineColor("Negative and Up", Color.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 ehlers_universal_oscillator = euo;
ehlers_universal_oscillator.Hide();

#plot showMovAvg = if showMA then euoMA else Double.NaN;
#showMovAvg.Hide();

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

Let me know what you think when you have a chance... :)
 
H

HighBredCloud

Well-known member
VIP
@netarchitech and no scaling issues like before? Oh wow...let me check this out now...BUT this would be great! do you know if the breakout signals will work now since the OB/OS is added? Also just lookin at it...do the OB/OS lines follow SMI?
 
H

HighBredCloud

Well-known member
VIP
@netarchitech OK...so I plugged the new script in and no dice on the OB/OS lines as they do not follow SMI...On a side note...Combining these two indicators...SMI and EUO was a great idea...look how well they work together...


This indicator really amazes me...That and the PercentR_MAC...with the SuperSmootherFilter on...its great!
 
1

12matthew09

New member
So, whenever I try to make a scanner from the EUO and put crosses below -0.9 nothing appears but when I do it for the SMI -0.7 it works great. How do I get the scanner for the EUO?
 
netarchitech

netarchitech

Well-known member
VIP
@HighBredCloud I went and took another look...While I "resolved" the "scaling" issues from a display viewpoint, apparently it affected the breakout signals, as I believe it is preventing the proper functioning of the OB/OS lines :(
 
netarchitech

netarchitech

Well-known member
VIP
So, whenever I try to make a scanner from the EUO and put crosses below -0.9 nothing appears but when I do it for the SMI -0.7 it works great. How do I get the scanner for the EUO?
@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 :)
 
Last edited:
H

HighBredCloud

Well-known member
VIP
@netarchitech yeah I saw that...The indicator is good as it is...don't get me wrong...BUT if you ever figure out how to incorporate the OB/OS lines to it then DO IT...because it will only make it better. I can tell you right now that using SMI in place of the other moving average lines that come with the EUO is a much better option IMO...
 
T

tomsk

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
 

Similar threads

Top