Modified Stochastic Momentum Index for ThinkorSwim

rwfarrell

New member
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:

Duece

New member
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.
 

horserider

Well-known member
VIP
@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);
 

rbark3r

New member
VIP
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
 

BenTen

Administrative
Staff
VIP
@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);
 

Optionsguy

New member
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!
 

XeoNoX

Well-known member
VIP
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;
 

Optionsguy

New member
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
 

XeoNoX

Well-known member
VIP
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.
 

Optionsguy

New member
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.
 

XeoNoX

Well-known member
VIP
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 😆
 

Optionsguy

New member
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
I appreciate the detailed responses! Thank you for the help
 

Similar threads

Top