You are using an out of date browser. It may not display this or other websites correctly.

You should upgrade or use an alternative browser.

You should upgrade or use an alternative browser.

- Thread starter Pete
- Start date

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

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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
```

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

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

Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|

T | smi crosses avgsmi Watchlist | Questions | 1 | |

Plotting 2 SMI Periods aligned at the same zero-line | Questions | 1 | ||

M | the price the moment the smi crosses above the average smi. | Questions | 2 | |

F | Scan for Stochastic MACD, RSI, and SMI | Questions | 1 | |

T | William Blau SMI with EMA difference (aka histogram) | Questions | 6 |

Start a new thread and receive assistance from our community.

87k+
Posts

297
Online

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club

- Exclusive indicators
- Proven strategies & setups
- Private Discord community
- ‘Buy The Dip’ signal alerts
- Exclusive members-only content
- Add-ons and resources
- 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

- The most viewed thread:

https://usethinkscript.com/threads/repainting-trend-reversal-for-thinkorswim.183/ - Our most popular indicator:

https://usethinkscript.com/threads/buy-the-dip-indicator-for-thinkorswim.3553/ - Answers to frequently asked questions:

https://usethinkscript.com/threads/answers-to-commonly-asked-questions.6006/

What are the benefits of VIP Membership?

VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.

How can I access the premium indicators?

To access the premium indicators, which are plug and play ready, sign up for VIP membership here.