TMO True Momentum Oscillator For ThinkOrSwim

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

Could we add order on this in order to generate a P &L report


#True (M)omentum (O)scilator)
# Mobius
# V01.05.2018
# hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

#declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input AlertDisplace = 0;

def o = open;
def c = close;
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then color.green
else color.light_red);
Signal.AssignValueColor(if Main > Signal
then color.green
else color.light_red);
Signal.HideBubble();
Signal.HideTitle();
#addCloud(Main, Signal, color.green, color.light_red);
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
zero.hideBubble();
zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
ob.SetDefaultColor(Color.gray);
ob.HideBubble();
ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
os.SetDefaultColor(Color.gray);
os.HideBubble();
os.HideTitle();
#addCloud(ob, length, color.light_red, color.light_red, no);
#addCloud(-length, os, color.light_green, color.light_green);

def BUYsignal =Main < OS and Main crosses above Signal;
def SELLsignal = Main > OB and Main crosses below Signal;
addverticalline(BUYsignal,"Buy",color.green,curve.short_dash);
addverticalline(SELLsignal,"Sell",color.red,curve.short_dash);

# Alerts
Alert(BuySignal[AlertDisplace], " ", Alert.Bar, Sound.ding);
Alert(SellSignal[AlertDisplace], " ", Alert.Bar, Sound.chimes);
 
For anyone who understands machine learning and classification analysis, Mobius TMO has said to classify pivots because it is a momentum indicator. Can anyone get a better Precision and recall playing with parameters than this? According to precision and recall (I added to TMO) it performs really bad.

Tmo has an extreme amount of false positives.

# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

declare lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;
input train_n = 60;
input p_length = 10;
input signal_thresh = 10;


def o = open;
def c = close;
def v = volume;
def v1 = v[1];
def hi_p = high;
def lo_p = low;
def tp_;
def fp_;
def fn_;
def tp;
def fp;
def fn;


def p_score_hi = p_length == ((fold x11 = 1 to p_length
with y1 = 0
do y1 + if getvalue(hi_p, x11) < hi_p and getvalue(hi_p, -x11) < hi_p then 1 else 0) + 1);

def p_score_lo = p_length == ((fold x21 = 1 to p_length
with y2 = 0
do y2 + if getvalue(lo_p,x21) > lo_p and getvalue(lo_p, -x21) > lo_p then 1 else 0) + 1);



def trunc = if p_score_hi == 1 or p_score_lo == 1 then 1 else 0;
def truth = if !IsNaN(trunc) then trunc else trunc[1];

def data = fold i = 0 to length
with s
do s + (if c > GetValue(o, i)
then 1
else if c < GetValue(o, i)
then - 1
else 0);

def data2 = fold i2 = 0 to length
with s2
do s2 + (if v > GetValue(v1, i2)
then 1
else if v < GetValue(v1, i2)
then - 1
else 0);

def EMA5 = ExpAverage(data, calcLength);
def EMA52 = ExpAverage(data2, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
#plot Main2 = ExpAverage(EMA52, smoothLength);

#performance
def bull_sig = IF(Main[1] <= -signal_thresh and Main > -signal_thresh,1,0);
def bear_sig = IF(Main[1] >= signal_thresh and Main > signal_thresh ,1,0);
def class = if (bull_sig + bear_sig) != 0 then 1 else 0;



plot out = class;
plot low = -Signal_thresh;
plot High = signal_thresh;
plot sig_out_p = if class == 1 then signal_thresh else 0;

if BarNumber() >= train_n
{
tp_ = if class == 1 and truth == 1 then tp_[1] + 1 else tp_[1];
fp_ = if truth == 0 and class == 1 then fp_[1] + 1 else fp_[1];
fn_ = if class == 0 and truth == 1 then fn_[1] + 1 else fn_[1];
} else {
tp_ = 0;
fp_ = 0;
fn_ = 0;
}

tp = if !IsNaN(tp_) then tp_ else tp[1];
fp = if !IsNaN(fp_) then fp_ else fp[1];
fn = if !IsNaN(fn_) then fn_ else fn[1];

def prec = if !IsNaN(tp / (tp + fp)) then tp / (tp + fp) else prec[1] ;
def recall = if !IsNaN(tp / (tp + fn)) then tp / (tp + fn) else recall[1];


AddLabel(1, " Precision = " + prec + " Recall = " + recall + " TP : " + tp + " FP : " + fp + " FN : " + fn + " Sample Size : " + (barnumber() - train_n) , Color.GREEN );
 
Last edited by a moderator:
For anyone who understands machine learning and classification analysis, Mobius TMO has said to classify pivots because it is a momentum indicator. Can anyone get a better Precision and recall playing with parameters than this? According to precision and recall (I added to TMO) it performs really bad.
https://www.thebalancemoney.com/how...r sell.2-,Trading Use,-The momentum indicator

That’s great. Tmo has an extreme amount of false positives.
Oscillators oscillate.
Read more:
https://usethinkscript.com/threads/...7/#:~:text=are rife with-,false,-signals. The
 
Last edited:
# TMO ((T)rue (M)omentum (O)scilator) Scan
# Mobius, with modifications by tomsk, 1.1.2020
# V01.05.2018
What if I want to just scan the stocks on my watchlist? I have a watchlist with big boys on it (e.g. SPY, NFLX, QQQ, MSFT, NVDA, etc.) and these are the only stocks I like to trade because of contract volume. Is there a way I can utilize a scanner for just these stocks?
 
Last edited by a moderator:
Hey @bigworm
You still in Oregon? Big, I haven't looked in the Archive here for quite a while but JQ's archive should be in the tutorials section.
If not mistaken, Nube did a few studies mixing TMO with Supertrend and/or RSI Laguerre. I personally would suggest that you look in the Archive for Doc's (of Theotrade) that Mobius made for them and start there. Did you ask Mobius?

there are several folks that might be able to load it up and try to trouble shoot it.
I looked at the code but it's way above my head. Regarding TMO picking up pivots, no idea. Depends on your time frame possibly?...

Please tell everyone what instruments you are trading, what time frame your pivots would be used at, etc. That would be helpful.
What have you tried so far?, etc.


Are you working on your Doctorate or Masters?
@BenTen & @MerryDay, is there anyone you know here who understands machine learning and classification analysis?
 
Last edited by a moderator:
No the lounge doesn’t like that I point out things that are wrong. I’d try super trend with tmo but did you load my code?

I completed my masters. I'm not really looking for help to make it better because I don't think it can be improved. Mobius has said it approximates pivots well because it is a momentum indicator but as you can see below the precision is 14% and recall is 30%. That means 14 percent of the time when it signals a pivot its actually a pivot which is really bad. even used with other indicators this is not good.
tmo

try loading and looking at precision
 
Last edited by a moderator:
How would you use TMO in a scan?

I want to scan for stocks that have been under -8 on the TMO for the last 3 -30 minutes bars.

Here's the script for TMO

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.HideBubble();
Signal.HideTitle();
addCloud(Main, Signal, color.green, color.red);
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
zero.hideBubble();
zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
ob.SetDefaultColor(Color.gray);
ob.HideBubble();
ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
os.SetDefaultColor(Color.gray);
os.HideBubble();
os.HideTitle();
addCloud(ob, length, color.light_red, color.light_red, no);
addCloud(-length, os, color.light_green, color.light_green);
# End Code TMO
 
How would you use TMO in a scan?

I want to scan for stocks that have been under -8 on the TMO for the last 3 -30 minutes bars.

Here's the script for TMO

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA5, smoothLength);
plot Signal = ExpAverage(Main, smoothLength);
Main.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.AssignValueColor(if Main > Signal
then color.green
else color.red);
Signal.HideBubble();
Signal.HideTitle();
addCloud(Main, Signal, color.green, color.red);
plot zero = if isNaN(c) then double.nan else 0;
zero.SetDefaultColor(Color.gray);
zero.hideBubble();
zero.hideTitle();
plot ob = if isNaN(c) then double.nan else round(length * .7);
ob.SetDefaultColor(Color.gray);
ob.HideBubble();
ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(length * .7);
os.SetDefaultColor(Color.gray);
os.HideBubble();
os.HideTitle();
addCloud(ob, length, color.light_red, color.light_red, no);
addCloud(-length, os, color.light_green, color.light_green);
# End Code TMO

add a condition that checks for that condition for 3 bars
i disabled the plots and added 1 formula , that will be 1 or 0


Code:
# tmo_scan_00b

#https://usethinkscript.com/threads/how-to-use-tmo-in-a-scan.13914/
#How to use TMO in a scan

declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length
 with s
 do s + (if c > getValue(o, i) then 1
   else if c < getValue(o, i) then - 1
   else 0);
def EMA5 = ExpAverage(data, calcLength);

#----------------------------
input max_value = -8.0;
input bars = 3;

def Main2 = ExpAverage(EMA5, smoothLength);
def Signal2 = ExpAverage(Main2, smoothLength);

def cond1 = (main2 < max_value);
plot z = sum(cond1, bars) == bars;


#------------------------------
# remove these lines if used in a scan

#plot Main = ExpAverage(EMA5, smoothLength);
#plot Signal = ExpAverage(Main, smoothLength);
#Main.AssignValueColor(if Main > Signal then color.green else color.red);
#Signal.AssignValueColor(if Main > Signal then color.green else color.red);
#Signal.HideBubble();
#Signal.HideTitle();

#addCloud(Main, Signal, color.green, color.red);

#plot zero = if isNaN(c) then double.nan else 0;
#zero.SetDefaultColor(Color.gray);
#zero.hideBubble();
#zero.hideTitle();

#plot ob = if isNaN(c) then double.nan else round(length * .7);
#ob.SetDefaultColor(Color.gray);
#ob.HideBubble();
#ob.HideTitle();

#plot os = if isNaN(c) then double.nan else -round(length * .7);
#os.SetDefaultColor(Color.gray);
#os.HideBubble();
#os.HideTitle();

#addCloud(ob, length, color.light_red, color.light_red, no);
#addCloud(-length, os, color.light_green, color.light_green);
# End Code TMO
#
 
Hi guys/gals,

I'm trying to modify the TMO into a watchlist badge. For some reason, it doesn't seem to be lining up properly. I'd like to know whether a buy or sell has fired in the last 5 bars, as I'm combining it with another indicator for confirmation (Triple Exhaustion). Anyone see where I'm going wrong here?

Code:
# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
# hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

declare Upper;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

def o = open;
def c = close;
def data = fold i = 0 to length
with s
do s + (if c > getValue(o, i)
then 1
else if c < getValue(o, i)
then - 1
else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

def zero = if isNaN(c) then double.nan else 0;

def ob = if isNaN(c) then double.nan else round(length * .7);

def os = if isNaN(c) then double.nan else -round(length * .7);
#___________________________________________________________________add_on
def BUYsignal =Main < OS and Main crosses above Signal;
def SELLsignal = Main > OB and Main crosses below Signal;

def buyplot = buysignal or buysignal[1] or buysignal[2] or buysignal[3] or buysignal[4] or buysignal [5];
def sellplot = sellsignal or sellsignal[1] or sellsignal[2] or sellsignal[3] or sellsignal[4] or sellsignal [5];


addlabel(yes,if sellplot then "Sell" else if buyplot then "Buy" else " ",
if sellplot then color.red else if buyplot then color.green else color.current);

# End Code TMO
 
Hi guys/gals,

I'm trying to modify the TMO into a watchlist badge. For some reason, it doesn't seem to be lining up properly. I'd like to know whether a buy or sell has fired in the last 5 bars, as I'm combining it with another indicator for confirmation (Triple Exhaustion). Anyone see where I'm going wrong here?
CqRnUQ6.png

Watchlist Column Script:
Ruby:
# ########################################################
# TMO ((T)rue (M)omentum (O)scilator) WatchList Column Only
# Mobius, with modifications by tomsk, 1.1.2020
#with WatchList added by @MerryDay 12/2020
#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
input showlabels = yes ;
input length = 14;
input calcLength = 5;
input smoothLength = 3;
input tmo_ob =  10;
input tmo_os = -10;

def data = fold i = 0 to length
           with s
           do s + (if close > getValue(open, i)
                   then 1
                   else if close < getValue(open, i)
                        then - 1
                        else 0);
def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
def BUYsignal =Main < tmo_OS and Main crosses above Signal;
def SELLsignal = Main > tmo_OB and Main crosses below Signal;
# ########################################################
#charting and formatting
AddLabel(yes,
if BUYsignal within 5 bars then "BUY" else
if SELLsignal within 5 bars then "SELL" else " ") ;

AssignBackgroundColor(
if BUYsignal within 5 bars then color.green else
if SELLsignal within 5 bars then color.red else color.light_gray) ;
 
I am using the TMO
https://usethinkscript.com/threads/tmo-true-momentum-oscillator-for-thinkorswim.9413/#post-24

Is there a way to make horizonal lines at the price (like the example) when TMO is over 10 and under -10?

https://www.dropbox.com/s/8zbztgjkj9joar1/2023-01-25 - Tos Charts.png?dl=0


this is an upper study, that draws horizontal lines from the close, when the signal crosses a level.

the level 10 comes from ,
the length(14) * 0.7 = 9.8 (10)

i added an input to choose the length factor, instead of using a constant, 0.7.
input length_factor = 0.7;


Code:
# tmo_plusminus10_upper_00

#https://usethinkscript.com/threads/horizontal-line-when-price-is-over-under-tmo-10-10.14195/
#horizontal Line when price is over/under TMO -10 & +10

#----------------------------
#https://usethinkscript.com/threads/tmo-true-momentum-oscillator-for-thinkorswim.9413/#post-24
#TMO True Momentum Oscillator For ThinkOrSwim
# BenTen  Start dateDec 18, 2018  Tagsunanswered
#https://usethinkscript.com/threads/tmo-true-momentum-oscillator-archived-posts.15/ 
#The following thinkScript of the true momentum oscillator was created by Mobius.
#It calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

# TMO ((T)rue (M)omentum (O)scilator)
# Mobius
# V01.05.2018
# hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.

#declare Lower;

input length = 14;
input calcLength = 5;
input smoothLength = 3;

input length_factor = 0.7;

def o = open;
def c = close;
def data = fold i = 0 to length
           with s
           do s + (if c > getValue(o, i)
                   then 1
                   else if c < getValue(o, i)
                        then - 1
                        else 0);

def EMA5 = ExpAverage(data, calcLength);
def Main = ExpAverage(EMA5, smoothLength);
def Signal = ExpAverage(Main, smoothLength);
#     Main.AssignValueColor(if Main > Signal
#                           then color.green
#                           else color.red);
#     Signal.AssignValueColor(if Main > Signal
#                             then color.green
#                             else color.red);
#     Signal.HideBubble();
#     Signal.HideTitle();
#addCloud(Main, Signal, color.green, color.red);

#plot zero = if isNaN(c) then double.nan else 0;
#     zero.SetDefaultColor(Color.gray);
#     zero.hideBubble();
#     zero.hideTitle();
#def ob = if isNaN(c) then double.nan else round(length * .7);
def ob = if isNaN(c) then double.nan else round(length * length_factor);
#     ob.SetDefaultColor(Color.gray);
#     ob.HideBubble();
#     ob.HideTitle();
#def os = if isNaN(c) then double.nan else -round(length * .7);
def os = if isNaN(c) then double.nan else -round(length * length_factor);
#     os.SetDefaultColor(Color.gray);
#     os.HideBubble();
#     os.HideTitle();
#addCloud(ob, length, color.light_red, color.light_red, no);
#addCloud(-length, os, color.light_green, color.light_green);


def bn = barnumber();
def na = double.nan;

def level = round(length * length_factor);

def shi = if bn == 1 then na
 else if signal crosses above level then close
 else shi[1];
plot zshi = shi;
zshi.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zshi.SetDefaultColor(Color.red);
zshi.hidebubble();

def slo = if bn == 1 then na
 else if signal crosses below -level then close
 else slo[1];
plot zslo = slo;
zslo.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
zslo.SetDefaultColor(Color.green);
zslo.hidebubble();

# End Code TMO
#

dX7OKrH.jpg
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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