Archived: TMO True Momentum Oscillator

Status
Not open for further replies.
@BenTen I am curious if you know how to build an alert for when TMO goes from green to red. I tried modifying the study at the end to get the signals I want so I can get alerts off of it but it isn't working. Any help would be appreciated. Thank you.

def uarrow = Main > Signal;

def darrow = Main < Signal;

plot alert = if uarrow then 1 else if darrow then -1 else 0;

I also added declare lower so it shows up on the bottom
 
Just a FYI, this was part of my chat with tech support on a "script execution time error" when scanning with the True Momentum Oscillator.

Sorry if this is a repeat.

Thank you for chatting into thinkorswim sorry for the wait. If the script requires extensive calculations such as recursions over a long period of time it will return this execution timeout. I can take a look at your scan with you to see if there may be a good way to modify it so that it works. You are welcome to share the scan query with us by clicking the three lines in the upper right and then "Share scan query" and then paste the hyperlink into our chat here to review, but I cannot promise that there will be a fix if the necessary calculations are extensive, the scan may need to be broken down into more than one scan or use a more narrow lookback period or something like that
t's the "Fold" iterations in the "data" variable that are breaking this down in the scan and making it timeout. The scan tab really just can't handle the "fold" reserved word. I have not found a good workaround to get this to work yet I'm sorry

There is not a good alternative to replace the "Fold" operator, but something that you could do is create a smaller watchlist instead of all symbols and run the same thinkscript scan over a smaller list of symbols. If you try to perform this calculation on all stocks or something like that it will likely time out, but if you have a smaller list of symbols that you want to run this calculation over in the scan that is the best workaround I can think of. Doing these many iterations on all symbols is just too much processing power
 
@subharmonic How did you set up your scanner for the TMO indicator? Can you post a screenshot?
Not sure exactly sure what you mean. I was a combo of the TMO and another indicator in one script. About 63 lines with half being hints. Filtered by "weekly" only.

Also I think this info should have stayed elsewhere as the point of my post was that the recursive data messes with their scans as it is just pounding them, needs to have a smaller pool of securities look at. It is not necessarily a TMO thing, it is a server resource issue. Just my opinion.
 
@subharmonic True momentum oscillator was the only indicator you mentioned in your post. That is why it was moved here. It looks like you were able to resolve this issue by scanning in a smaller watchlist.
 
@BenTen Yes. I have seen this before on larger scripts. It make sense that taking too many resources they are going to nerf you somewhat. I thought filtering by weekly was enough but I guess not.
 
@dmillz If you need more confirmation, consider that you may be using too many indicators already.
Multi-collinearity is dangerous to your trading account.

Do you also have the MTF TMO on your chart at 5x larger than your main chart?
In the end you'll have to find one that works for you and following someone else may not help you find it.

Please re-read all of the TMO material in the Reference thread. Use the search bar above. Best of luck.

Hey Thanks, Im using it on a 5 minute chart for day trading, Its a bit harder to manage than longer 1 hour charts etc. I found the SVE StochRSI and reversal trend indicator works pretty well. I guess i was just looking for the RSI so i could time my exits correctly because its hard to determine the top with the TMO indicator.
 
Hey Thanks, Im using it on a 5 minute chart for day trading, Its a bit harder to manage than longer 1 hour charts etc. I found the SVE StochRSI and reversal trend indicator works pretty well. I guess i was just looking for the RSI so i could time my exits correctly because its hard to determine the top with the TMO indicator.
In that case, look into RSI Laguerre in search & Tutorials. They "may" work better for exit timing... much more decisive.
 
How do you extend the time on the bullish -10 scan... I keep missing things because they pop up for like 10 min then go away on the 1 hour chart
 
Last edited:
Short and Buy Bubble Signals for momentum

Code:
declare lower;

input length = 7;
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.GREEN);
Signal.AssignValueColor(if Main > Signal then Color.RED else Color.RED);
Signal.HideBubble();
Signal.HideTitle();
AddCloud(Main, Signal, Color.GREEN, Color.BLACK);
plot zero = if IsNaN(c) then Double.NaN else 0;
zero.SetDefaultColor(Color.WHITE);
zero.HideBubble();
zero.HideTitle();
plot ob = if IsNaN(c) then Double.NaN else Round(length * .7);
ob.SetDefaultColor(Color.BLUE);
ob.HideBubble();
ob.HideTitle();
plot os = if IsNaN(c) then Double.NaN else -Round(length * .7);
os.SetDefaultColor(Color.BLUE);
os.HideBubble();
os.HideTitle();

#BUBBLE
def CrossBar = if Main crosses Signal then BarNumber() else Double.NaN;


#CLOUD__________________________________________________________________________________________________________________
AddCloud(ob, length, Color.gray, Color.gray, no);
AddCloud(-length, os, Color.gray, Color.gray);

#DOTSandBUBBLES______________________________________________________________________________________________________________________
plot DownSignal = if Main crosses below Signal then Signal else Double.NaN;
DownSignal.SetPaintingStrategy(PaintingStrategy.Arrow_DOWN);
AddChartBubble((DownSignal) and (DownSignal), DownSignal, "S" , Color.RED);

plot UpSignal = if Main crosses above Signal then Signal else Double.NaN;
UpSignal.SetPaintingStrategy(PaintingStrategy.Arrow_Up);
AddChartBubble((UpSignal) and (UpSignal), UpSignal, "B" , Color.GREEN);

AddLabel (yes, if Main > Signal then "(2) MOMENTUM: BUY" + "" else "", Color.GREEN);
AddLabel (yes, if Main < Signal then "(2) MOMENTUM: SELL" + "" else "", Color.RED);
 
Last edited:
I've started watching the TMO and think it's a pretty solid indicator, but would like to backtest some ideas with it using more accurate engines such as on Quantconnect. To do that, I need to convert the code to Python, but I don't really understand what the variable "data" is doing in the code (see below code snippet). Does anyone understand this, and what exactly it is calculating? I know it's the delta of price, but I obviously need to be able to mimic it's behavior exactly in Python and therefore need a more specific answer. Any help is GREATLY appreciated, and I'd be happy to share the results I come to when complete.

Code:
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);
 
@TraderKevin What you are experiencing is the result of coders not using English Language variable names which is what makes scripting languages so desirable... Old coding habits from other languages die hard but I wish at least the members here would start expanding their variable names... The benefit of doing so with scripting languages is that the code then becomes self-documenting and requires little to no comments...

All that being said, what the fold loop is doing is to calculate a value based on the closing price of the 7 previous candles/bars and providing an exponential average of those values...
 
Hi. I'm trying to build a scanner that captures stocks with
vol >500K, market cap >50M, price above 10 (all easy)
AND
currently in a TTM squeeze (for at least 2 days) (easy)
AND
(and this is the HARD part)
who, using the TMO, are below zero and where I can catch the first day where the TMO ribbon changes from red to green. I have built the following so far but i have to scroll through everything to try and find that red to green change still.
Any ideas on how to accomplish this?
thanks

https://tos.mx/fy2Gwcx
 
TMO WatchList
IEf8RM8.png

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);
# ########################################################
#charting and formatting
plot TMO = round(main,0);
AssignBackgroundColor(
if main < tmo_os      then CreateColor(50, 200, 255) else
if main > tmo_ob      then CreateColor(255, 139 ,61) else
if main crosses above tmo_os then CreateColor(0, 0, 255) else
if main crosses below tmo_ob then CreateColor(255, 204, 0) else
if main < signal  then CreateColor(225, 0, 0) else
if main > main[1] then CreateColor(0, 165, 0) else CreateColor(204, 204, 204)) ;
Shared Link: http://tos.mx/6HaRN1a
 
Last edited:
I've been spending a lot of time with this indicator and have implemented it for other platforms. While doing that I've noticed a few problems or shortcomings that could easily be alleviated and I want to propose them here, to make a more universal and streamlined version that is better suited for implementation in TA libraries.

Here is a snippet of the affected original code:
Code:
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);

The first issue is that the indicator uses two sources. It looks at the open and the close. This is very uncommon and in most cases doesn't even make a difference. If there are no gaps between the candles, the close of i+1 is exactly the same as the open of i. On almost all graphs with smaller timeframes, the values will even be exactly identical. Having only one input source makes the indicator a lot more flexible though, because it can be applied to a variety of sources.
For this reason, I propose the following code change:
Code:
def data = fold i = 0 to length
           with s
           do s + (if c > GetValue(c, i+1)
                   then 1
                   else if c < GetValue(c, i+1)
                        then - 1
                        else 0);

The second issue is that the indicator looks at length+1 candles. A TMO 14 for example looks at 15 candles. I sincerely believe that this was not intended by the original author and is a bug in the math. I therefore propose that the code is instead changed to
Code:
def data = fold i = 1 to length
           with s
           do s + (if c > GetValue(c, i)
                   then 1
                   else if c < GetValue(c, i)
                        then - 1
                        else 0);
With this change, a TMO 14 would look at 14 candles and be bound between -14 and 14. It would also look back at the closing prices of length candles, like any other indicator (moving averages, RSI, MACD).

Last but not least, I propose to normalize the result to a range between -100 and 100. It makes it straightforward to work with different values for length, because on an oscillator this has no effect on the result.
Code:
s = s * 100 / length;

These changes wouldn't affect the essence of TMO. The new TMO 15 would be the same as the old TMO 14, if there are no gaps. With gaps, the results would only differ ever so slightly. The normalization would bring the entry signals at a fixed e.g. +70 and -70, similar to RSI, regardless of length.

What are your thoughts? Should TMO be changed with these "fixes"? Or should the fixes go into a spin-off version that's called something like "TMO - Universal Edition"?
 
Last edited:
I've been spending a lot of time with this indicator and have implemented it for other platforms. While doing that I've noticed a few problems or shortcomings that could easily be alleviated and I want to propose them here, to make a more universal and streamlined version that is better suited for implementation in TA libraries.

Here is a snippet of the affected original code:
Code:
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);

The first issue is that the indicator uses two sources. It looks at the open and the close. This is very uncommon and in most cases doesn't even make a difference. If there are no gaps between the candles, the close of i+1 is exactly the same as the open of i. On almost all graphs with smaller timeframes, the values will even be exactly identical. Having only one input source makes the indicator a lot more flexible though, because it can be applied to a variety of sources.
For this reason, I propose the following code change:
Code:
def data = fold i = 0 to length
           with s
           do s + (if c > GetValue(c, i+1)
                   then 1
                   else if c < GetValue(c, i+1)
                        then - 1
                        else 0);

The second issue is that the indicator looks at length+1 candles. A TMO 14 for example looks at 15 candles. I sincerely believe that this was not intended by the original author and is a bug in the math. I therefore propose that the code is instead changed to
Code:
def data = fold i = 1 to length
           with s
           do s + (if c > GetValue(c, i)
                   then 1
                   else if c < GetValue(c, i)
                        then - 1
                        else 0);
With this change, a TMO 14 would look at 14 candles and be bound between -14 and 14. It would also look back at the closing prices of length candles, like any other indicator (moving averages, RSI, MACD).

Last but not least, I propose to normalize the result to a range between -100 and 100. It makes it straightforward to work with different values for length, because on an oscillator this has no effect on the result.
Code:
s = s * 100 / length

These changes wouldn't affect the essence of TMO. The new TMO 15 would be the same as the old TMO 14, if there are no gaps. With gaps, the results would only differ ever so slightly. The normalization would bring the entry signals at a fixed e.g. +70 and -70, similar to RSI, regardless of length.

What are your thoughts? Should TMO be changed with these "fixes"? Or should the fixes go into a spin-off version that's called something like "TMO - Universal Edition"?
I use the TMO and would be curious as to what your new code would look like and I would be happy to put it up against the current version on my 3m chart.
 
Status
Not open for further replies.

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