Stochastic Momentum Index for ThinkorSwim

GGC

New member
Stochastic momentum index and I would like to have a down arrow is SMI crosses below AVGSMI (with the crossing happening above the overbought line), and an up arrow if SMI crosses above AVGSMI (with the crossing happening below the oversold line). Thanks :)
 
Last edited by a moderator:
Sure, here you go. Please verify that the crossing signals are plotting where you want.

Code:
# Stochastic Momentum Index
# Base code by TD Ameritrade IP Company, Inc. (c) 2008-2020
# Added arrows and alerts when SMI/AvgSMI cross above/below the oversold/overbought lines

declare lower;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;

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

plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));

plot overbought = over_bought;
overbought.setDefaultColor(getcolor(5));

plot oversold = over_sold;
oversold.setDefaultColor(getcolor(5));

def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;

plot arrowUp = if signalUp then AvgSMI else double.nan;
     arrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     arrowUp.SetDefaultColor(color.green);

plot arrowDn = if signalDn then AvgSMI else double.nan;
     arrowDn.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     arrowDn.SetDefaultColor(color.red);

Alert(alerts and signalUp, " Arrow Up! ", alert.bar, sound.ring);
Alert(alerts and signalDn, " Arrow Down! ", alert.bar, sound.ring);

#end code

Edit: Modified code to add alerts for the arrow signals.
 
Last edited:

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

Hey guys, I am on this board enough and I am only a beginner here with ThinkScript but here is my contribution to the group. For anyone who uses the Stochastic Momentum Index indicator. Here is a script that changes the candle colors when the SMI crosses the AvgSMI line. This can be used on any timeframe. Copy and paste the code. I call it SMICandles, make sure to drop the script in the volume section of your Studies and not in the price or chart area of Studies.

Code:
#Hint Violet candles = SMI 40 or greater
#Hint White candles = SMI -40 or less

plot SMI = StochasticMomentumIndex();
plot OverBought = 40;
plot OverSold = -40;

SMI.DefineColor("OverBought", Color.VIOLET);
SMI.DefineColor("OverSold", Color.yellow);

AssignPriceColor(if SMI >= OverBought then SMI.color("OverBought") else if SMI <= OverSold then SMI.color("OverSold") else Color.current);

def Condition1 = (StochasticMomentumIndex()."SMI" crosses below StochasticMomentumIndex()."AvgSMI");

def Condition2 = (StochasticMomentumIndex()."SMI" crosses above StochasticMomentumIndex()."AvgSMI");

               
AssignPriceColor
(if Condition1 then Color.plum
else Color.CURRENT);

AssignPriceColor
(if Condition2 then color.cyan
else Color.CURRENT);
 
Last edited by a moderator:
I am looking to get an audio alert when the SMI (stochasticmomentumindex) likes cross each other either up or down, but have no clue how to make that happen.........any help really appreciated.....TY.
 
@Duece This might work , not tested.

Code:
input sound = yes;
Alert(sound and SMI crosses above avgsmi, "SMI Long",  Alert.BAR, Sound.Ring);
Alert(sound and SMI crosses below avgsmi, "SMI Short",  Alert.BAR, Sound.Ring);
 
Hi Guys,

would appreciate it if you guys could make a simple customization to the code below.

Overbought and oversold are currently set to -50 and 50

I'm hoping you guys can insert a cloud within the following range -15 to 15.

I'd like to ignore any crosses inside of that range.

Thanks in advance
--------------------------------------------------------------------------------------------------------------

Code:
# Stochastic Momentum Index
# Base code by TD Ameritrade IP Company, Inc. (c) 2008-2020
# Added arrows and alerts when SMI/AvgSMI cross above/below the oversold/overbought lines

declare lower;

input over_bought = 50.0;
input over_sold = -50.0;
input percentDLength = 3;
input percentKLength = 5;
input alerts = yes;

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

plot AvgSMI = expaverage(smi, percentDLength);
avgsmi.setDefaultColor(getcolor(5));

plot overbought = over_bought;
overbought.setDefaultColor(getcolor(5));

plot oversold = over_sold;
oversold.setDefaultColor(getcolor(5));

def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;

plot arrowUp = if signalUp then AvgSMI else double.nan;
     arrowUp.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
     arrowUp.SetDefaultColor(color.green);

plot arrowDn = if signalDn then AvgSMI else double.nan;
     arrowDn.SetPaintingStrategy(PaintingStrategy.Arrow_Down);
     arrowDn.SetDefaultColor(color.red);

Alert(alerts and signalUp, " Arrow Up! ", alert.bar, sound.ring);
Alert(alerts and signalDn, " Arrow Down! ", alert.bar, sound.ring);

#end code
 
@rbark3r To add the cloud, insert the following code to the bottom of your script:

Code:
plot range1 = 15;
plot range2 = -15;
AddCloud(range1, range2, color.yellow, color.yellow);
 
Hi All,

I was wondering if anyone knew how to create a scan that would find stocks that have an Stochastic Momentum Index “SMI” and “AvgSMI” within a value of 1 of each other?

For instance, a SMI value of 10 and an AvgSMI value of 11.

Any help is greatly appreciated!
 
remember to thumbs up if you found this post useful @Optionsguy

“SMI” and “AvgSMI” Scan Within Value of 1​

Code:
#By XeoNoX Via Usethinkscript.com
#SMI and SMI Average within XYZ
input avg_length = 60;
def SMI = StochasticMomentumIndex()."SMI";
def SMIAverage = average(SMI,avg_length);
def diff = absValue(smi-SMIaverage);
plot scan = diff <1;
 
Thank you so much! What would be the average length for the default settings on TOS for the SMI? I can’t seem to find it, but I don’t think it is 60

I see:
  • D length=3
  • K length=5
 
you stated:
find stocks that have an Stochastic Momentum Index “SMI” and “AvgSMI”

60 is the average of SMI Length... or what you reffered to as AvgSMI... you can change 60 to whatever average you want..... your K&D Length is whatever the default is built into thinkorswim.
 
you stated:
find stocks that have an Stochastic Momentum Index “SMI” and “AvgSMI”

60 is the average of SMI Length... or what you reffered to as AvgSMI... you can change 60 to whatever average you want..... your K&D Length is whatever the default is built into thinkorswim.
Hmm..okay, when I scan with this code, it brings up stocks that aren’t within 1 when lined up with the default settings.

I was looking to scan by the default settings, but I’m not sure what to put in for the length to match it up with the default.
 
i tried it and it came up with 3 results on the daily. you appear to be confusing the average smi length with the averages that are part of the smi. study.

Think of it like this, what you requested was an average of 2 compared averages

personally i dont know what purpose it will serve, but maybe you might have stumbled upon something special 😆
 
I appreciate the detailed responses! Thank you for the help
@Optionsguy @XeoNoX I added this indicator with modifications like square points instead of arrows, cloud, and price bubble. It said to work much better on trending stocks, so I trend painter script with the stochasticmomoindex to have a better entry plot. To explains things short, the TrendReversal I found more accurate with Buy/Sell signals (screenshots below). It was worth a try. Good luck! @cabe1332

Unless @Optionsguy has better process or projections on how he uses the stochasticmomoindex.
 
Last edited by a moderator:
@Optionsguy @XeoNoX I added this indicator with modifications like square points instead of arrows, cloud, and price bubble. It said to work much better on trending stocks, so I trend painter script with the stochasticmomoindex to have a better entry plot. To explains things short, the TrendReversal I found more accurate with Buy/Sell signals (screenshots below). It was worth a try. Good luck! @cabe1332

Unless @Optionsguy has better process or projections on how he uses the stochasticmomoindex.


tF7Ls50.png


6iJw411.png
Can you please share the script/code for the Stochastic momentumidex_20210801 and the buy sell signal on chart. Thanks.
 
@analyst2345 Welcome to the Forum! The way the site works, is that someone will submit the script and any questions that they have and everybody then chimes in with their thoughts.

So the script/code being discussed is the basic built-in TOS StochasticMomentumIndex to which the original poster added things like arrows. When you are reading a thread, it is always safe to start w/ the study in post#1. You can add it to your charts, get to understand it, google both this forum and the internet for the pros and the caveats of using this indicator. Then you can adapt that code w/ what others have contributed if you want to.
@cabe1332 turned the arrows into squares. You can make them anything you want by going to settings. @cab1332 also made pretty with some cloud coloring and a price bubble. Just in case, you are not yet well-versed in this type of formatting, Below is a script of the TOS SMI w/ @cabe1332's pretty formatting features. Review the code and read up in the TOS library because you can use these formatting features on any TOS or Custom study.
a2.png

Ruby:
# ########################################################
declare lower;

plot SMI = StochasticMomentumIndex()."SMI";
plot AvgSMI = StochasticMomentumIndex()."AvgSMI";
plot OverBought = 40;
plot OverSold = -40;
plot zeroline = 0 ;
zeroline.SetPaintingStrategy(PaintingStrategy.DASHES);

def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;

plot Up = if signalUp then AvgSMI else double.NaN ;
Up.SetPaintingStrategy(PaintingStrategy.SQUARES);
Up.SetDefaultColor(color.green) ;
Up.SetLineWeight(5);
plot Down = if  signalDn then AvgSMI  else double.NaN ;
Down.SetPaintingStrategy(PaintingStrategy.SQUARES);
Down.SetDefaultColor(color.red) ;
Down.SetLineWeight(5);
AddCloud(SMI, AvgSMI, color.light_green, color.pink);
AddChartBubble(signalUp, 0, close, Color.light_orange, no);
# ########################################################
Shared Study Link: http://tos.mx/JY5P6yP Click here for --> Easiest way to load shared links
 
@analyst2345 Welcome to the Forum! The way the site works, is that someone will submit the script and any questions that they have and everybody then chimes in with their thoughts.

So the script/code being discussed is the basic built-in TOS StochasticMomentumIndex to which the original poster added things like arrows. When you are reading a thread, it is always safe to start w/ the study in post#1. You can add it to your charts, get to understand it, google both this forum and the internet for the pros and the caveats of using this indicator. Then you can adapt that code w/ what others have contributed if you want to.
@cabe1332 turned the arrows into squares. You can make them anything you want by going to settings. @cab1332 also made pretty with some cloud coloring and a price bubble. Just in case, you are not yet well-versed in this type of formatting, Below is a script of the TOS SMI w/ @cabe1332's pretty formatting features. Review the code and read up in the TOS library because you can use these formatting features on any TOS or Custom study.
View attachment 750
Ruby:
# ########################################################
declare lower;

plot SMI = StochasticMomentumIndex()."SMI";
plot AvgSMI = StochasticMomentumIndex()."AvgSMI";
plot OverBought = 40;
plot OverSold = -40;
plot zeroline = 0 ;
zeroline.SetPaintingStrategy(PaintingStrategy.DASHES);

def signalUp = AvgSMI[1] < oversold and SMI[1] < AvgSMI[1] and SMI > AvgSMI;
def signalDn = AvgSMI[1] > overbought and SMI[1] > AvgSMI[1] and SMI < AvgSMI;

plot Up = if signalUp then AvgSMI else double.NaN ;
Up.SetPaintingStrategy(PaintingStrategy.SQUARES);
Up.SetDefaultColor(color.green) ;
Up.SetLineWeight(5);
plot Down = if  signalDn then AvgSMI  else double.NaN ;
Down.SetPaintingStrategy(PaintingStrategy.SQUARES);
Down.SetDefaultColor(color.red) ;
Down.SetLineWeight(5);
AddCloud(SMI, AvgSMI, color.light_green, color.pink);
AddChartBubble(signalUp, 0, close, Color.light_orange, no);
# ########################################################
Shared Study Link: http://tos.mx/JY5P6yP Click here for --> Easiest way to load shared links
@MerryDay @analyst2345, I stopped using the Stochastic Momentum Index even the one I mod. It looked pretty and all, but I find it does not fit my strategy. The buy/sell signals were not accurate or too many. I revert back to what works best and profits and cut down on indicators I don't need. You can say "it gets better as you earn". Good luck! Thanks, @MerryDay for sharing the code. @cabe1332
 
@MerryDay @analyst2345, I stopped using the Stochastic Momentum Index even the one I mod. It looked pretty and all, but I find it does not fit my strategy. The buy/sell signals were not accurate or too many. I revert back to what works best and profits and cut down on indicators I don't need. You can say "it gets better as you earn". Good luck! Thanks, @MerryDay for sharing the code. @cabe1332
While I have just signed up and noticed your use of the SMI, I have found that when the fast crosses the slow in a very defined angle, it works best when getting in on a trade early.
 
@MerryDay @analyst2345, I stopped using the Stochastic Momentum Index even the one I mod. It looked pretty and all, but I find it does not fit my strategy. The buy/sell signals were not accurate or too many. I revert back to what works best and profits and cut down on indicators I don't need. You can say "it gets better as you earn". Good luck! Thanks, @MerryDay for sharing the code. @cabe1332
What do you use now/instead?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
510 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

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

Frequently Asked Questions

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.

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.
Back
Top