SMI Ergodic Indicator for ThinkorSwim

Pete

New member
Has anyone seen the TOS code for the smi ergotic indicator? It seems similar to MACD, but is based on the True Strength Index (which TOS has included) with a signal line.
 

BenTen

Administrative
Staff
VIP
I looked up SMI in the thinkScript lounge and this is what I found. Is this what you're looking for?

Code:
#IronRod SMI histogram lower study ver4

declare lower;

input audioalarm=yes;

input Price = hlc3;

input RsqLength = 5;

input RsqLimit = .5;

input SmiLimit = 30;

input chopband2= 70;

input smibarbufr = 4;


def overbought = SmiLimit;

def oversold = -SmiLimit;

def percentDLength = 4;

def percentKLength = 5;


#Stochastic momentum index (SMI) 

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 chopband = if IsNaN(close) then Double.NaN else 0;


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

#SMI.SetDefaultColor(Color.BLUE);

smi.DefineColor("Up", CreateColor(0, 153, 51));

smi.definecolor("weak", color.light_gray);

smi.DefineColor("Down", Color.RED);

smi.AssignValueColor(if smi > smi[1] then smi.Color("Up") 

else if smi < smi[1]  then smi.color("down") 

else smi.Color("weak"));

smi.SetLineWeight(2);

SMI.SetStyle(Curve.SHORT_DASH);

SMI.SetLineWeight(3);


PLOT AvgSMI = ExpAverage(SMI, percentDLength);

AVGsmi.DefineColor("Up", CreateColor(0, 153, 51));

avgsmi.definecolor("weak", color.light_gray);

AVGsmi.DefineColor("Down", Color.RED);

avgsmi.AssignValueColor(if avgsmi > avgsmi[1] then avgsmi.Color("Up") 

else if avgsmi < avgsmi[1] then avgsmi.color("down") 

else avgsmi.Color("weak"));

AVGsmi.SetLineWeight(3);

#smi1.SetPaintingStrategy(PaintingStrategy.DASHES);


plot smiBAR = AvgSMI;

smiBAR.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

smiBAR.SetLineWeight(3);

smiBAR.DefineColor("upstrong", CreateColor (0, 255, 0));

smiBAR.DefineColor("weak", Color.LIGHT_GRAY);

smiBAR.DefineColor("downstrong", CreateColor(255, 51, 51));


smiBAR.AssignValueColor (if (smi + smibarbufr) >= smi[1] and smi > -SmiLimit then smiBAR.Color("upstrong")

       else if (smi - smibarbufr) <= smi[1] and smi < SmiLimit then smiBAR.Color("downstrong") 

    else  smiBAR.Color("weak"));


#r-Square centerline indicator

#def sma = Average(close, RsqLength);

#def RSq = Sqr(WMA(close, RsqLength) - sma) / (Average(Sqr(close), RsqLength) - Sqr(sma)) * 3 * (RsqLength + 1) / (RsqLength - 1);


chopband.HideBubble();

chopband.SetLineWeight(5);

chopband.DefineColor("Trade", createColor(0, 150,200));

chopband.DefineColor("Hold", Color.orange);

chopband.AssignValueColor(if smi > -smiLimit and smi < smilimit then chopband.Color("hold") else chopband.Color("trade"));


#Chop Cloud

plot upper= smilimit;

plot lower= -smilimit;

upper.setDefaultColor(color.GRAY);

lower.setDefaultColor(color.gRAY);

def choplimits = SmiLimit;

#input choplimits= 1;

AddCloud(choplimits, -choplimits,createColor(210,210,210));

#addcloud(-choplimits,-chopband2,createcolor(175,175,175));

#addcloud(chopband2,choplimits,createcolor(175,175,175));


#Labels

#AddLabel(yes, "SMI Legend: ", Color.BLACK);


#AddLabel(yes, "BULLISH", Color.UPTICK);

#AddLabel(yes, "BEARISH", Color.DOWNTICK);

#AddLabel(yes, "changing", Color.GRAY);

#AddLabel(yes, "MidLine: ", Color.BLACK);

#AddLabel(yes, "Trending", createColor(0,150,200));

#AddLabel(yes, "in ChopZone", Color.ORANGE);

#AddLabel(yes, "             SmiLimit= " + SmiLimit, Color.DARK_GRAY);


alert (audioalarm and smi crosses avgsmi and smi <= -smilimit or SMI CROSSes AVGSMI AND Smi >= smilimit,"SMI CROSS", alert.bar, sound.ring);
 

tradebyday

Active member
I am new to the community but not new to this page. I have been skulking the threads here the better part of 2 years now and have liked quite a few things you guys have both utilized and created. I am reaching out to this wonderful community in hopes to gain some assistance, some insight, and hopefully a fully automated alert system into my trading regimen to test out. I will post the links to the 2 indicators I am using at the bottom of this text. Now for the details. Trading off the 4000tick chart for /ES futures, I have developed a system I am rather proud of, but need help in trying to make it a more compact system. The way it works is rather simple, when z-score and Ergodic are both > 0, Its a long entry, when they are both < 0, its a short entry. I have settings that work very well for me, but I want to leave the system customizable as the indicators are right now. But what I would like to do is combine the indicators into a strategy that I can apply 3 ATR TPs, and leave the exit to being a reverse signal of the z-score. So say I enter a long, TP at 2*ATR, 4*ATR, and 7*ATR, then my stop loss or exit signal would just be when z-score is <0. The other thing I would like to accomplish with the strategy is to paint arrows for the 3 functions, green for bullish entry, red for bearish entry, and pink for exits. I am not too versed in the capabilities of coding so if this is not all doable I understand, but any help would be appreciated!

This is my current workspace (yes it is a bit of a mess as i have been playing around with some extra stuff on daily charts haha).

https://tos.mx/NzFimxi

It has come to my attention this link does not provide the z-score I am using. Such a shame. It can be found below

Code:
# Zscore
# Mobius
# Chat Room Request for mean reversion oscillator
#hint: Zscore measures distance from mean. Study allows the user to pick different aggregations than the chart aggregation and different lengths for the calculations.
# Discussion: Good use is as a reversion to mean oscillator. On lower aggregations (5min and less) Zscore can be so jumpy that it's near useless. But using it several aggregations higher than your trade time can make it useful. For 2 min charts setting Zscore to 15 min gives a nice confirmation to a pivot signal where Zscore is 3 or better for instance.

declare lower;

input length = 48;
input Agg = {default current, min5, min15, min30, daily};

def t;
switch (Agg){
case current:
    t = close;
case min5:
    t = close(period = AggregationPeriod.Five_min);
case min15:
    t = close(period = AggregationPeriod.Fifteen_Min);
case min30:
    t = close(period = AggregationPeriod.Thirty_Min);
case daily:
    t = close(period = AggregationPeriod.Day);
}
def c = close;
plot Zscore = (t - Average(t, length)) / StDev(t, length);
     Zscore.SetDefaultColor(Color.PLUM);
plot zero = if isNaN(c) then double.nan else 0;
     zero.SetDefaultColor(Color.Black);
     zero.SetLineWeight(1);
     zero.HideTitle();
plot PosOne = if isNaN(c) then double.nan else 1;
     PosOne.SetDefaultColor(Color.Green);
     PosOne.HideTitle();
plot NegOne = if isNaN(c) then double.nan else -1;
     NegOne.SetDefaultColor(Color.Light_Red);
     NegOne.HideTitle();
plot PosTwo = if isNaN(c) then double.nan else 2;
     PosTwo.SetDefaultColor(Color.Green);
     PosTwo.HideTitle();
plot NegTwo = if isNaN(c) then double.nan else -2;
     NegTwo.SetDefaultColor(Color.Red);
     NegTwo.HideTitle();
plot PosThree = if isNaN(c) then double.nan else 3;
     PosThree.SetDefaultColor(Color.Dark_Green);
     PosThree.HideTitle();
plot NegThree = if isNaN(c) then double.nan else -3;
     NegThree.SetDefaultColor(Color.Dark_Red);
     NegThree.HideTitle();
AddCloud(zero, PosOne, Color.Light_Green, Color.Light_Green);
AddCloud(PosOne, PosTwo, Color.Green, Color.Green);
AddCloud(PosTwo, PosThree, Color.Dark_Green, Color.Dark_Green);
AddCloud(NegOne, zero, Color.Light_Red, Color.Light_Red);
AddCloud(NegTwo, NegOne, Color.Red, Color.Red);
AddCloud(NegThree, NegTwo, Color.Dark_Red, Color.Dark_Red);
# End Code Zscore
 
Good setup! I just added RSI crossover (available in thinkorswim) signal and it is able point great entry point...

Look the signals are coming below the cloud and after sometime went above the cloud!

5-13 ema crossover at daily ES chart (downward) or price going below 20 or 50 sma may be considered as conditions against RSI bye signal . One can look at monthly or weekly VWAP for guidance.

l5ps09F.png
 

television

Member
hey, tested this out setup out and its looking promising! do you still utilize this system? also, in your workspace you have 2 ergodic oscillators one that is 100,50,10 and another that is 40,10,8... do you only require one of them to be green along with the zscore being over 0 or do you look for both oscilators to be above 0
 

wtf_dude

Active member
Just looked into this indicator after j007 mentioned it another thread. Here's the recode over from tradingview if anybody wants it

Code:
#////////////////////////////////////////////////////////////
#//  Copyright by HPotter v1.0 02/05/2017
#// The SMI Ergodic Indicator is the same as the True Strength Index (TSI) developed by
#// William Blau, except the SMI includes a signal line. The SMI uses double moving averages
#// of price minus previous price over 2 time frames. The signal line, which is an EMA of the
#// SMI, is plotted to help trigger trading signals. Adjustable guides are also given to fine
#// tune these signals. The user may change the input (close), method (EMA), period lengths
#// and guide values.
#// You can use in the xPrice any series: Open, High, Low, Close, HL2, HLC3, OHLC4 and ect...
#////////////////////////////////////////////////////////////

#Recoded for TOS by WTF_Dude


declare lower;

input price = close;
input fastlength = 4;
input slowlength = 8;
input smoothlength = 3;
input topband = .5;
input lowband = -.5;

def Price1 = Price - Price[1];
def Price2 = absvalue(Price - Price[1]);
def SMA_R = expaverage((expaverage(Price1,fastlength)),slowlength);
def SMA_aR = expaverage((expaverage(Price2, fastlength)),slowlength);

def SMI = SMA_R / SMA_aR;
def EMA_SMI = expaverage(SMI, Smoothlength);

plot ErgoticSMI = SMI;
ergoticsmi.setdefaultcolor(color.cyan);
plot SignalLine = EMA_SMI;
Signalline.setdefaultcolor(color.magenta);


plot topbandlevel = topband;
topbandlevel.setdefaultcolor(color.red);
addCloud(topbandlevel,.75, color.dark_red, color.dark_red);
plot lowbandlevel = lowband;
lowbandlevel.setdefaultcolor(color.green);
addCloud(lowband,-.75, color.dark_green, color.dark_green);

plot ZeroLine = 0;
zeroline.setdefaultcolor(color.dark_Gray);
 

henry1224

Active member
VIP
This indicator is for the SMI Histogram Indicator by IronRod. It adds labels for higher time frames. You have to add several of them onto the same chart area as the indicator{change the AGG period}

SMI Histogram Labels

Code:
############################################

declare lower;
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
DefineGlobalColor("Bullish", Color.Green);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("Changing", Color.Light_GRAY);
DefineGlobalColor("In ChopZone", Color.Orange);
DefineGlobalColor("Trending", CreateColor(0,150,200));
DefineGlobalColor("arrow Buy", Color.Cyan);
DefineGlobalColor("arrow Sell", Color.Dark_Orange);

Script SymbolSMIIron{
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def overbought = SmiLimit;
def oversold = -SmiLimit;
def percentDLength = 4;
def percentKLength = 5;
def min_low = Lowest(LP, percentKLength);
def max_high = Highest(HP, percentKLength);
def rel_diff = CP - (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 chopband = if IsNaN(CP) then Double.NaN else 0;
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
Plot Result = if SMI > SMI[1] then 1 else if SMI < SMI[1] then -1 else 0;}

Script SymbolASMI{
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def overbought = SmiLimit;
def oversold = -SmiLimit;
def percentDLength = 4;
def percentKLength = 5;
def min_low = Lowest(LP, percentKLength);
def max_high = Highest(HP, percentKLength);
def rel_diff = CP - (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 chopband = if IsNaN(CP) then Double.NaN else 0;
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
Def AvgSMI = ExpAverage(SMI, percentDLength);
Plot Result = if AvgSMI > AvgSMI[1] then 1 else if AvgSMI < AvgSMI[1] then -1 else 0;}

Script SymbolSMIBAR{
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def overbought = SmiLimit;
def oversold = -SmiLimit;
def percentDLength = 4;
def percentKLength = 5;
def min_low = Lowest(LP, percentKLength);
def max_high = Highest(HP, percentKLength);
def rel_diff = CP - (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 chopband = if IsNaN(CP) then Double.NaN else 0;
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
Def SMIBar = ExpAverage(SMI, percentDLength);
Plot Result = if (SMI + smibarbufr) >= SMI[1] and SMI > -SmiLimit then 1 else if (SMI - smibarbufr) <= SMI[1] and SMI < SmiLimit then -1 else 0;}

Script SymbolCLINE{
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def overbought = SmiLimit;
def oversold = -SmiLimit;
def percentDLength = 4;
def percentKLength = 5;
def min_low = Lowest(LP, percentKLength);
def max_high = Highest(HP, percentKLength);
def rel_diff = CP - (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 chopband = if IsNaN(CP) then Double.NaN else 0;
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
Def SMIBar = ExpAverage(SMI, percentDLength);
Plot Result = if SMI > -smiLimit and SMI < smilimit then 1 else 0;}

Script SymbolSignals{
input period = AggregationPeriod.DAY;
input RsqLength = 5;
input RsqLimit = .5;
input SmiLimit = 30;
input chopband2= 70;
input smibarbufr = 4;
def CP = Close(Period= period);
def HP = High(period= period);
def LP = Low(Period= period);
def overbought = SmiLimit;
def oversold = -SmiLimit;
def percentDLength = 4;
def percentKLength = 5;
def min_low = Lowest(LP, percentKLength);
def max_high = Highest(HP, percentKLength);
def rel_diff = CP - (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 chopband = if IsNaN(CP) then Double.NaN else 0;
def SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
Def SMIBar = ExpAverage(SMI, percentDLength);
Plot Result = If SMI crosses above SMIBar and SMI <= -smilimit then 1 else if  SMI crosses below SMIBar AND SMI >= smilimit then -1 else 0;}

def currentPeriod = GetAggregationPeriod();
def s1;
def h1;
def s2;
def h2;
def h3;
if period >= currentPeriod {
    s1 = SymbolSMIBAR(period = period ,RSQLength = RSQLength,RSQLimit = RSQLimit,SMILimit = SMILimit,ChopBand2 = ChopBand2,SMIBarBufr = SMIBarBufr);
    s2 = SymbolCLINE(period = period ,RSQLength = RSQLength,RSQLimit = RSQLimit,SMILimit = SMILimit,ChopBand2 = ChopBand2,SMIBarBufr = SMIBarBufr);

    h1 = SymbolSMIIRON(period = period ,RSQLength = RSQLength,RSQLimit = RSQLimit,SMILimit = SMILimit,ChopBand2 = ChopBand2,SMIBarBufr = SMIBarBufr);
    h2 = SymbolASMI(period = period ,RSQLength = RSQLength,RSQLimit = RSQLimit,SMILimit = SMILimit,ChopBand2 = ChopBand2,SMIBarBufr = SMIBarBufr);
    h3 = SymbolSignals(period = period ,RSQLength = RSQLength,RSQLimit = RSQLimit,SMILimit = SMILimit,ChopBand2 = ChopBand2,SMIBarBufr = SMIBarBufr);

} else {
    s1 = Double.NaN;
    s2 = Double.NaN;
    h1 = Double.Nan;
    h2 = Double.Nan;
    h3 = Double.Nan;

}
AddLabel(!IsNaN(s1), "SMI:" + (if period == AggregationPeriod.MONTH then "M"
else
if period == AggregationPeriod.WEEK then "W"
else
if period == AggregationPeriod.FOUR_DAYS then "4D"
else
if period == AggregationPeriod.THREE_DAYS then "3D"
else
if period == AggregationPeriod.TWO_DAYS then "2D"
else
if period  == AggregationPeriod.DAY then "D"
else
if period == AggregationPeriod.FOUR_HOURS then "4H"
else
if period == AggregationPeriod.TWO_HOURS then "2H"
else
if period == AggregationPeriod.HOUR then "60m"
else
if period == AggregationPeriod.THIRTY_MIN then "30m"
else
if period == AggregationPeriod.TWENTY_MIN then "20m"
else
if period  == AggregationPeriod.FIFTEEN_MIN then "15m"
else
if period == AggregationPeriod.TEN_MIN then "10m"
else
if period == AggregationPeriod.FIVE_MIN then "5m"
else
if period == AggregationPeriod.FOUR_MIN then "4m"
else
if period  == AggregationPeriod.THREE_MIN then "3m"
else
if period == AggregationPeriod.TWO_MIN then "2m"
else
if period  == AggregationPeriod.MIN then "1m"
else ""), if s1 == 1 then GlobalColor("Bullish") else if s1 == -1 then GlobalColor("Bearish") else GlobalColor("Changing"));

AddLabel(!IsNaN(h1) and h1 != 0, If h1 == 1 then "B1" else if h1 == -1 then "S1" else "-", if h1 == 1 then GlobalColor("arrow Buy") else if h1 == -1 then GlobalColor("arrow Sell") else color.gray);

AddLabel(!IsNaN(h2) and h2 != 0, If h2 == 1 then "B2" else if h2 == -1 then "S2" else "-", if h2 == 1 then GlobalColor("arrow Buy") else if h2 == -1 then GlobalColor("arrow Sell") else color.gray);

AddLabel(!IsNaN(h3) and h3 != 0, If h3 == 1 then "B3" else if h3 == -1 then "S3" else "-", if h3 == 1 then GlobalColor("arrow Buy") else if h3 == -1 then GlobalColor("arrow Sell") else color.gray);

AddLabel(!IsNaN(s2), "SMI CL:" + (if period == AggregationPeriod.MONTH then "M"
else
if period == AggregationPeriod.WEEK then "W"
else
if period == AggregationPeriod.FOUR_DAYS then "4D"
else
if period == AggregationPeriod.THREE_DAYS then "3D"
else
if period == AggregationPeriod.TWO_DAYS then "2D"
else
if period  == AggregationPeriod.DAY then "D"
else
if period == AggregationPeriod.FOUR_HOURS then "4H"
else
if period == AggregationPeriod.TWO_HOURS then "2H"
else
if period == AggregationPeriod.HOUR then "60m"
else
if period == AggregationPeriod.THIRTY_MIN then "30m"
else
if period == AggregationPeriod.TWENTY_MIN then "20m"
else
if period  == AggregationPeriod.FIFTEEN_MIN then "15m"
else
if period == AggregationPeriod.TEN_MIN then "10m"
else
if period == AggregationPeriod.FIVE_MIN then "5m"
else
if period == AggregationPeriod.FOUR_MIN then "4m"
else
if period  == AggregationPeriod.THREE_MIN then "3m"
else
if period == AggregationPeriod.TWO_MIN then "2m"
else
if period  == AggregationPeriod.MIN then "1m"
else ""), if s2 == 1 then GlobalColor("In ChopZone") else GlobalColor("Trending"));
 

Jonas99

Active member
VIP
Good setup! I just added RSI crossover (available in thinkorswim) signal and it is able point great entry point...

Look the signals are coming below the cloud and after sometime went above the cloud!

5-13 ema crossover at daily ES chart (downward) or price going below 20 or 50 sma may be considered as conditions against RSI bye signal . One can look at monthly or weekly VWAP for guidance.

l5ps09F.png
what is that cloud and MA that you are using? Thank you.
 

Similar threads

Top