Archived: TMO True Momentum Oscillator

Status
Not open for further replies.
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.

If you just change the code snippet for data 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);
then the old TMO 14 would be the same as the new TMO 15. At least as long as there are no gaps. On the 3m there most likely aren't any, since trading doesn't stop.

The normalization step is just additionally to have the same range across any chosen length. Adding the line
Code:
s = s * 100 / length;
just behind the data definition should be all that's needed. Unfortunately I cannot test the code, since I don't have ToS. But it would be great if you could tell me, whether the code runs without an error.

Like I said, I've been implementing TMO for other platforms and after noticing these problems thought that I should bring it up in the original thread, before I go and just make changes on my own.
 
@hCaostrader It would also be a little clearer when using multiple characters in a mathematical expression to use parentheses, although it wouldn't make a difference in your "data = " line of code.
 
Oh, yes. Of course. Wrong variable. Try
Code:
data = data * 100 / length

That happens when you just eyeball something. If you confirm that works, I'm gonna change it in the previous posts too.
still getting an error message so maybe post the code def data and add the data = data * 100 / length in the code where you want it.
 
still getting an error message so maybe post the code def data and add the data = data * 100 / length in the code where you want it.
Thanks for checking it out. I got in touch with a friend who has ToS and we quickly debugged the code over the phone. Here is the complete code with the changes incorporated and also with the plots adjusted for the new scale.

Should have done that before I proposed code changes to a platform I can't test.

I also published these changes on TradingView: True Momentum Oscillator - Universal Edition

Code:
# TMO ((T)rue (M)omentum (O)scilator) - Universal Edition
# Mobius & hCaostrader
# V20.11.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.

declare Lower;

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

def c = close;
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);

def normData = data * 100 / length;

def EMA5 = ExpAverage(normData, 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(70);
     ob.SetDefaultColor(Color.gray);
     ob.HideBubble();
     ob.HideTitle();
plot os = if isNaN(c) then double.nan else -round(70);
     os.SetDefaultColor(Color.gray);
     os.HideBubble();
     os.HideTitle();
addCloud(ob, 100, color.light_red, color.light_red, no);
addCloud(-100, os, color.light_green, color.light_green);
# End Code TMO
 
Hey @Branch, if you should return, please put the original header back in an give it a new revision date w your name.
Thanks!
 
For those who use this intraday, five to fifteen minute timeframe, what's the best setting to use in your experience, 21, 14 or 7? I'm assuming the larger numbers are smoother curves but give slower entries?
 
Have you converted this code to Python, by chance? Or do you know how? I'm not fluent enough in Python to know how to convert the "data" variable. Any help is appreciated!
No, but look at the Pinescript implementation on TradingView. It's much easier to understand than thinkScript. The formula isn't that complicated. You only need to understand the ternary operator.
 
@allanumana1986 By placing "#" in front of the code. That will deactivate it.

For example, here is an active condition:

Code:
def buy = if this then that;

By placing the "#" in front of it, the condition is no longer active.

Code:
#def buy = if this then that;
 
Hey @Branch, if you should return, please put the original header back in an give it a new revision date w your name.
Thanks!
@markos: I came up with this code.

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.black, Color.black, no);
AddCloud(-length, os, Color.black, Color.black);

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

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

AddLabel (yes, if Main > Signal then "BUY" + "" else "", Color.GREEN);
AddLabel (yes, if Main < Signal then "SELL" + "" else "", Color.RED);

plot MainMomentum = ExpAverage(EMA5, smoothLength);

def CrossBar2 = if MainMomentum crosses MainMomentum then BarNumber() else Double.NaN;
 
@markos: I came up with this code.

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.black, Color.black, no);
AddCloud(-length, os, Color.black, Color.black);

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

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

AddLabel (yes, if Main > Signal then "BUY" + "" else "", Color.GREEN);
AddLabel (yes, if Main < Signal then "SELL" + "" else "", Color.RED);

plot MainMomentum = ExpAverage(EMA5, smoothLength);

def CrossBar2 = if MainMomentum crosses MainMomentum then BarNumber() else Double.NaN;
Here it is in action using renko trading TSLA
 
Is there a scan in this forum that can check for True Momentum Oscillator turning from Red/Green and vice versa?
 
@kmg526 You can set it up by creating a condition like this:

4u29dDv.png
 
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
289 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