Repaints Multi-TimeFrame Stochastic Momentum Index for ThinkorSwim



Here is a multiple timeframe modification of TOS' built in Stochastic Momentum Index.


#multiple timeframe stochastic momentum

declare lower;

input tf = {"MIN", "TWO_MIN", default "FIVE_MIN", "FIFTEEN_MIN", "HOUR", "TWO_HOURS", "FOUR_HOURS", "DAY", "WEEK", "MONTH"};

def timeframe;

switch (tf){
case "MIN":
    timeframe = AggregationPeriod.MIN;
case "TWO_MIN":
    timeframe = AggregationPeriod.TWO_MIN;
case "FIVE_MIN":
    timeframe = AggregationPeriod.FIVE_MIN;
    timeframe = AggregationPeriod.FIFTEEN_MIN;
case "HOUR":
    timeframe = AggregationPeriod.HOUR;
case "TWO_HOURS":
    timeframe = AggregationPeriod.TWO_HOURS;
case "FOUR_HOURS":
    timeframe = AggregationPeriod.FOUR_HOURS;
case "DAY":
    timeframe = AggregationPeriod.DAY;
case "WEEK":
    timeframe = AggregationPeriod.WEEK;
case "MONTH":
    timeframe = AggregationPeriod.MONTH;

input over_bought = 40.0;
input over_sold = -40.0;
input percentDLength = 4;
input percentKLength = 6;

def min_low = Lowest(low(period = timeframe), percentKLength);
def max_high = Highest(high(period = timeframe), percentKLength);
def rel_diff = close(period = timeframe) - (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;

plot AvgSMI = ExpAverage(SMI, percentDLength);

plot overbought = over_bought;

plot oversold = over_sold;
Last edited:



Add the standard TOS SMI, then add this (multiple times if you like) and set them for higher time frame(s). Note that the percent signs on the right are not part of the studies.

Possible use, when higher time frame crosses yellow above green and is above 0, possible buy could occur at next cross of shorter time frame blue above red. Possible sell when higher time frame crosses the other way. Or could hold longer and wait for shorter time frame to cross below -40. For example, right now, 8/15/20, would be looking for next 1 hour blue above red cross (and with yellow still above 0) for possible long entry.


New member
Hello, how does one add crossover arrows to display on the indicator whenever SMI crosses above the AvgSMI and vice versa. Thank you.
Last edited:


Staff member
@Lysergic This is a multi-time frame indicator. Arrows wouldn't be appropriate due to the repainting-effect.
Screenshot (113).png

In the example of a 4hr on a 15min chart, the arrow would only be right once in 16 candles
A 5min on a 2min chart would be right once in 10 bars, etc...

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
297 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.