Wanting MTF Stochastic Momentum Index Labels

Newoldschool

New member
I know nothing about coding, but I've tried to write this myself using ChatGPT but with no luck, I found I'm only good with simple coding requests with GPT. Here's what I'm wanting, Multi time frame labels that show when the stochastic momentum index (SMI) is overbought (above 40) and oversold (below -40).

Using the 5-minute TF as an example. Using the built in SMI with default settings, I'd like an upper left hand corner label box that will change colors depending on OB or OS levels, for example:

If the 5min SMI and AvgSMI lines are both above 40 then the box will be dark red, if the SMI and AvgSMI lines both cross above 65 then it changes to bright red box.

If the 5min SMI and AvgSMI lines are below -40 then the box is dark green and if both line cross below -65 then the box is bright green.

Anytime both lines are in-between 40 and -40 then the box will be grey.

I would like this to be MTF for 1min, 2min, 3min, 5min, 10min, 15min, 30min, 1hr, 2hr, 4hr, D, W charts that will always be present regardless of timeframe on chart. Let me know if I'm missing any details or if there's anything to add to this indicator that I may not be thinking about, TIA!
 
Solution
I know nothing about coding, but I've tried to write this myself using ChatGPT but with no luck, I found I'm only good with simple coding requests with GPT. Here's what I'm wanting, Multi time frame labels that show when the stochastic momentum index (SMI) is overbought (above 40) and oversold (below -40).

Using the 5-minute TF as an example. Using the built in SMI with default settings, I'd like an upper left hand corner label box that will change colors depending on OB or OS levels, for example:

If the 5min SMI and AvgSMI lines are both above 40 then the box will be dark red, if the SMI and AvgSMI lines both cross above 65 then it changes to bright red box.

If the 5min SMI and AvgSMI lines are below -40 then the box is dark...
I know nothing about coding, but I've tried to write this myself using ChatGPT but with no luck, I found I'm only good with simple coding requests with GPT. Here's what I'm wanting, Multi time frame labels that show when the stochastic momentum index (SMI) is overbought (above 40) and oversold (below -40).

Using the 5-minute TF as an example. Using the built in SMI with default settings, I'd like an upper left hand corner label box that will change colors depending on OB or OS levels, for example:

If the 5min SMI and AvgSMI lines are both above 40 then the box will be dark red, if the SMI and AvgSMI lines both cross above 65 then it changes to bright red box.

If the 5min SMI and AvgSMI lines are below -40 then the box is dark green and if both line cross below -65 then the box is bright green.

Anytime both lines are in-between 40 and -40 then the box will be grey.

I would like this to be MTF for 1min, 2min, 3min, 5min, 10min, 15min, 30min, 1hr, 2hr, 4hr, D, W charts that will always be present regardless of timeframe on chart. Let me know if I'm missing any details or if there's anything to add to this indicator that I may not be thinking about, TIA! hal_agg


this has 13 labels for 13 different agg times
it compares the levels of SMI and AMIAVG and determines label color
it only works on 1 minute chart

dark_RED - SMI > 40 and AvgSMI > 40
red - SMI > 65 and avgsmi > 65
dark_green - SMI < -40 and AvgSMI < -40
green - SMI < -65 and avgsmi < -65
gray - both lines are in-between 40 and -40

set 2nd levels with, (plus and minus)
input L2 = 65;

i experimented with a way to make it not error, on other chart times, but wasn't working. (some variation of what used here, https://usethinkscript.com/threads/mtf-arrows-choose-1-of-3-sets-of-5-periods.8959/)


Code:
# mtf_smi_stoch_momen_in

#https://usethinkscript.com/threads/wanting-mtf-stochastic-momentum-index-labels.17609/
#Wanting MTF Stochastic Momentum Index Labels

# ref  agg labels
# https://usethinkscript.com/threads/the-multi-10x-mtf-labels-indicator-for-thinkorswim.1129/page-4#post-69106
# post71  pg 4


# StochasticMomentumIndex ,  put orig code in a script
# TD Ameritrade IP Company, Inc. (c) 2008-2023
declare lower;

script smi_mtf {
  input agg = AggregationPeriod.day;
  input perDLen = 3;
  input perKLen = 5;

  def min_low = Lowest(low(period = agg), perKLen);
  def max_high = Highest(high(period = agg), perKLen);
  def rel_diff = close(period = agg) - (max_high + min_low) / 2;
  def diff = max_high - min_low;
  def avgrel = ExpAverage(ExpAverage(rel_diff, perDLen), perDLen);
  def avgdiff = ExpAverage(ExpAverage(diff, perDLen), perDLen);

  plot SMI = if avgdiff != 0 then avgrel / (avgdiff / 2) * 100 else 0;
  plot AvgSMI = ExpAverage(SMI, perDLen);
}


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

def ob = over_bought;
def os = over_sold;
def d = percentDLength;
def k = percentKLength;

plot zob = ob;
zob.SetDefaultColor(GetColor(5));
plot zos = os;
zos.SetDefaultColor(GetColor(5));

def L1 = ob;
input L2 = 65;
def s = 60000;

# MTF for 1min, 2min, 3min, 5min, 10min, 15min, 30min, 1hr, 2hr, 4hr, D, W  charts
def chartagg = GetAggregationPeriod();

input agg1 = AggregationPeriod.MIN;
input agg2 = AggregationPeriod.TWO_MIN;
input agg3 = AggregationPeriod.THREE_MIN;
input agg4 = AggregationPeriod.FOUR_MIN;
input agg5 = AggregationPeriod.FIVE_MIN;
input agg6 = AggregationPeriod.TEN_MIN;
input agg7 = AggregationPeriod.FIFTEEN_MIN;
input agg8 = AggregationPeriod.THIRTY_MIN;
input agg9 = AggregationPeriod.HOUR;
input agg10 = AggregationPeriod.TWO_HOURS;
input agg11 = AggregationPeriod.FOUR_HOURS;
input agg12 = AggregationPeriod.day;
input agg13 = AggregationPeriod.week;


# try to work around charts of higher times.  didn't work
#def agg1b = if agg1 <= chartagg then chartagg else agg1;
#def agg2b = if agg2 <= chartagg then chartagg else agg2;
#def agg3b = if agg3 <= chartagg then chartagg else agg3;
#def agg4b = if agg4 <= chartagg then chartagg else agg4;
#def agg5b = if agg5 <= chartagg then chartagg else agg5;
#def agg6b = if agg6 <= chartagg then chartagg else agg6;
#def agg7b = if agg7 <= chartagg then chartagg else agg7;
#def agg8b = if agg8 <= chartagg then chartagg else agg8;
#def agg9b = if agg9 <= chartagg then chartagg else agg9;
#def agg10b = if agg10 <= chartagg then chartagg else agg10;
#def agg11b = if agg11 <= chartagg then chartagg else agg11;
#def agg12b = if agg12 <= chartagg then chartagg else agg12;
#def agg13b = if agg13 <= chartagg then chartagg else agg13;

def agg1b = if AggregationPeriod.MIN <= GetAggregationPeriod() then GetAggregationPeriod() else AggregationPeriod.MIN;
def agg2b = if agg2 <= GetAggregationPeriod() then GetAggregationPeriod() else agg2;
def agg3b = if agg3 <= GetAggregationPeriod() then GetAggregationPeriod() else agg3;
def agg4b = if agg4 <= GetAggregationPeriod() then GetAggregationPeriod() else agg4;
def agg5b = if agg5 <= GetAggregationPeriod() then GetAggregationPeriod() else agg5;
def agg6b = if agg6 <= GetAggregationPeriod() then GetAggregationPeriod() else agg6;
def agg7b = if agg7 <= chartagg then chartagg else agg7;
def agg8b = if agg8 <= chartagg then chartagg else agg8;
def agg9b = if agg9 <= chartagg then chartagg else agg9;
def agg10b = if agg10 <= chartagg then chartagg else agg10;
def agg11b = if agg11 <= chartagg then chartagg else agg11;
def agg12b = if agg12 <= chartagg then chartagg else agg12;
def agg13b = if agg13 <= chartagg then chartagg else agg13;


def a1min = if agg1 <= chartagg then chartagg/s else agg1/s;
def a2min = if agg2 <= chartagg then chartagg/s else agg2/s;
def a3min = if agg3 <= chartagg then chartagg/s else agg3/s;
def a4min = if agg4 <= chartagg then chartagg/s else agg4/s;
def a5min = if agg5 <= chartagg then chartagg/s else agg5/s;
def a6min = if agg6 <= chartagg then chartagg/s else agg6/s;
def a7min = if agg7 <= chartagg then chartagg/s else agg7/s;
def a8min = if agg8 <= chartagg then chartagg/s else agg8/s;
def a9min = if agg9 <= chartagg then chartagg/s else agg9/s;
def a10min = if agg10 <= chartagg then chartagg/s else agg10/s;
def a11min = if agg11 <= chartagg then chartagg/s else agg11/s;
def a12min = if agg12 <= chartagg then chartagg/s else agg12/s;
def a13min = if agg13 <= chartagg then chartagg/s else agg13/s;


def a1_smi = smi_mtf(agg1, d, k).SMI;
def a1_avg = smi_mtf(agg1, d, k).AvgSMI;
def a2_smi = smi_mtf(agg2, d, k).SMI;
def a2_avg = smi_mtf(agg2, d, k).AvgSMI;
def a3_smi = smi_mtf(agg3, d, k).SMI;
def a3_avg = smi_mtf(agg3, d, k).AvgSMI;
def a4_smi = smi_mtf(agg4, d, k).SMI;
def a4_avg = smi_mtf(agg4, d, k).AvgSMI;
def a5_smi = smi_mtf(agg5, d, k).SMI;
def a5_avg = smi_mtf(agg5, d, k).AvgSMI;
def a6_smi = smi_mtf(agg6, d, k).SMI;
def a6_avg = smi_mtf(agg6, d, k).AvgSMI;
def a7_smi = smi_mtf(agg7, d, k).SMI;
def a7_avg = smi_mtf(agg7, d, k).AvgSMI;
def a8_smi = smi_mtf(agg8, d, k).SMI;
def a8_avg = smi_mtf(agg8, d, k).AvgSMI;
def a9_smi = smi_mtf(agg9, d, k).SMI;
def a9_avg = smi_mtf(agg9, d, k).AvgSMI;
def a10_smi = smi_mtf(agg10, d, k).SMI;
def a10_avg = smi_mtf(agg10, d, k).AvgSMI;
def a11_smi = smi_mtf(agg11, d, k).SMI;
def a11_avg = smi_mtf(agg11, d, k).AvgSMI;
def a12_smi = smi_mtf(agg12, d, k).SMI;
def a12_avg = smi_mtf(agg12, d, k).AvgSMI;
def a13_smi = smi_mtf(agg13, d, k).SMI;
def a13_avg = smi_mtf(agg13, d, k).AvgSMI;


# dark_RED - SMI > 40 and AvgSMI > 40
#   red -  SMI > 65 and avgsmi > 65
# dark_green - SMI < -40 and AvgSMI < -40
#   green -  SMI < -65 and avgsmi < -65
#   gray -  both lines are in-between 40 and -40

input labels = yes;
addlabel(labels, 
(if a1min < 60 then (a1min + " Min")
 else if a1min < 1440 then ((a1min / 60) + " Hr")
 else if a1min < 10080 then (a1min / (60 * 24) + " D")
 else if agg1 == AggregationPeriod.WEEK then "W"
 else if agg1 == AggregationPeriod.MONTH then "M"
 else ""),
(if a1_smi >= l2 and a1_avg >= l2 then color.red
 else if a1_smi >= l1 and a1_avg >= l1 then color.dark_red
 else if a1_smi <= -l2 and a1_avg <= -l2 then color.green
 else if a1_smi <= -l1 and a1_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a2min < 60 then (a2min + " Min")
 else if a2min < 1440 then ((a2min / 60) + " Hr")
 else if a2min < 10080 then (a2min / (60 * 24) + " D")
 else if agg2 == AggregationPeriod.WEEK then "W"
 else if agg2 == AggregationPeriod.MONTH then "M"
 else ""),
(if a2_smi >= l2 and a2_avg >= l2 then color.red
 else if a2_smi >= l1 and a2_avg >= l1 then color.dark_red
 else if a2_smi <= -l2 and a2_avg <= -l2 then color.green
 else if a2_smi <= -l1 and a2_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a3min < 60 then (a3min + " Min")
 else if a3min < 1440 then ((a3min / 60) + " Hr")
 else if a3min < 10080 then (a3min / (60 * 24) + " D")
 else if agg3 == AggregationPeriod.WEEK then "W"
 else if agg3 == AggregationPeriod.MONTH then "M"
 else ""),
(if a3_smi >= l2 and a3_avg >= l2 then color.red
 else if a3_smi >= l1 and a3_avg >= l1 then color.dark_red
 else if a3_smi <= -l2 and a3_avg <= -l2 then color.green
 else if a3_smi <= -l1 and a3_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a4min < 60 then (a4min + " Min")
 else if a4min < 1440 then ((a4min / 60) + " Hr")
 else if a4min < 10080 then (a4min / (60 * 24) + " D")
 else if agg4 == AggregationPeriod.WEEK then "W"
 else if agg4 == AggregationPeriod.MONTH then "M"
 else ""),
(if a4_smi >= l2 and a4_avg >= l2 then color.red
 else if a4_smi >= l1 and a4_avg >= l1 then color.dark_red
 else if a4_smi <= -l2 and a4_avg <= -l2 then color.green
 else if a4_smi <= -l1 and a4_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a5min < 60 then (a5min + " Min")
 else if a5min < 1440 then ((a5min / 60) + " Hr")
 else if a5min < 10080 then (a5min / (60 * 24) + " D")
 else if agg5 == AggregationPeriod.WEEK then "W"
 else if agg5 == AggregationPeriod.MONTH then "M"
 else ""),
(if a5_smi >= l2 and a5_avg >= l2 then color.red
 else if a5_smi >= l1 and a5_avg >= l1 then color.dark_red
 else if a5_smi <= -l2 and a5_avg <= -l2 then color.green
 else if a5_smi <= -l1 and a5_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a6min < 60 then (a6min + " Min")
 else if a6min < 1440 then ((a6min / 60) + " Hr")
 else if a6min < 10080 then (a6min / (60 * 24) + " D")
 else if agg6 == AggregationPeriod.WEEK then "W"
 else if agg6 == AggregationPeriod.MONTH then "M"
 else ""),
(if a6_smi >= l2 and a6_avg >= l2 then color.red
 else if a6_smi >= l1 and a6_avg >= l1 then color.dark_red
 else if a6_smi <= -l2 and a6_avg <= -l2 then color.green
 else if a6_smi <= -l1 and a6_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a7min < 60 then (a7min + " Min")
 else if a7min < 1440 then ((a7min / 60) + " Hr")
 else if a7min < 10080 then (a7min / (60 * 24) + " D")
 else if agg7 == AggregationPeriod.WEEK then "W"
 else if agg7 == AggregationPeriod.MONTH then "M"
 else ""),
(if a7_smi >= l2 and a7_avg >= l2 then color.red
 else if a7_smi >= l1 and a7_avg >= l1 then color.dark_red
 else if a7_smi <= -l2 and a7_avg <= -l2 then color.green
 else if a7_smi <= -l1 and a7_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a8min < 60 then (a8min + " Min")
 else if a8min < 1440 then ((a8min / 60) + " Hr")
 else if a8min < 10080 then (a8min / (60 * 24) + " D")
 else if agg8 == AggregationPeriod.WEEK then "W"
 else if agg8 == AggregationPeriod.MONTH then "M"
 else ""),
(if a8_smi >= l2 and a8_avg >= l2 then color.red
 else if a8_smi >= l1 and a8_avg >= l1 then color.dark_red
 else if a8_smi <= -l2 and a8_avg <= -l2 then color.green
 else if a8_smi <= -l1 and a8_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a9min < 60 then (a9min + " Min")
 else if a9min < 1440 then ((a9min / 60) + " Hr")
 else if a9min < 10080 then (a9min / (60 * 24) + " D")
 else if agg9 == AggregationPeriod.WEEK then "W"
 else if agg9 == AggregationPeriod.MONTH then "M"
 else ""),
(if a9_smi >= l2 and a9_avg >= l2 then color.red
 else if a9_smi >= l1 and a9_avg >= l1 then color.dark_red
 else if a9_smi <= -l2 and a9_avg <= -l2 then color.green
 else if a9_smi <= -l1 and a9_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a10min < 60 then (a10min + " Min")
 else if a10min < 1440 then ((a10min / 60) + " Hr")
 else if a10min < 10080 then (a10min / (60 * 24) + " D")
 else if agg10 == AggregationPeriod.WEEK then "W"
 else if agg10 == AggregationPeriod.MONTH then "M"
 else ""),
(if a10_smi >= l2 and a10_avg >= l2 then color.red
 else if a10_smi >= l1 and a10_avg >= l1 then color.dark_red
 else if a10_smi <= -l2 and a10_avg <= -l2 then color.green
 else if a10_smi <= -l1 and a10_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a11min < 60 then (a11min + " Min")
 else if a11min < 1440 then ((a11min / 60) + " Hr")
 else if a11min < 10080 then (a11min / (60 * 24) + " D")
 else if agg11 == AggregationPeriod.WEEK then "W"
 else if agg11 == AggregationPeriod.MONTH then "M"
 else ""),
(if a11_smi >= l2 and a11_avg >= l2 then color.red
 else if a11_smi >= l1 and a11_avg >= l1 then color.dark_red
 else if a11_smi <= -l2 and a11_avg <= -l2 then color.green
 else if a11_smi <= -l1 and a11_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a12min < 60 then (a12min + " Min")
 else if a12min < 1440 then ((a12min / 60) + " Hr")
 else if a12min < 10080 then (a12min / (60 * 24) + " D")
 else if agg12 == AggregationPeriod.WEEK then "W"
 else if agg12 == AggregationPeriod.MONTH then "M"
 else ""),
(if a12_smi >= l2 and a12_avg >= l2 then color.red
 else if a12_smi >= l1 and a12_avg >= l1 then color.dark_red
 else if a12_smi <= -l2 and a12_avg <= -l2 then color.green
 else if a12_smi <= -l1 and a12_avg <= -l1 then color.dark_green
 else color.gray));

addlabel(labels, 
(if a13min < 60 then (a13min + " Min")
 else if a13min < 1440 then ((a13min / 60) + " Hr")
 else if a13min < 10080 then (a13min / (60 * 24) + " D")
 else if agg13 == AggregationPeriod.WEEK then "W"
 else if agg13 == AggregationPeriod.MONTH then "M"
 else ""),
(if a13_smi >= l2 and a13_avg >= l2 then color.red
 else if a13_smi >= l1 and a13_avg >= l1 then color.dark_red
 else if a13_smi <= -l2 and a13_avg <= -l2 then color.green
 else if a13_smi <= -l1 and a13_avg <= -l1 then color.dark_green
 else color.gray));

#

1 min chart
Y5jIfKa.jpg
 
Last edited:
Solution

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