SMI Ergodic Indicator for ThinkorSwim?

P

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

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

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

henry1224

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

Similar threads

Top