True Momentum Oscillator for ThinkorSwim

tenacity11

tenacity11

Active member
2019 Donor
@hCaostrader trying to add this in s = s * 100 / length; is giving error message
 
H

hCaostrader

New member
@hCaostrader trying to add this in s = s * 100 / length; is giving error message

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.
 
Last edited:
scott69

scott69

Member
@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.
 
tenacity11

tenacity11

Active member
2019 Donor
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.
 
H

hCaostrader

New member
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
 
tenacity11

tenacity11

Active member
2019 Donor
@hCaostrader Many thanks and I've added it to my chart and will test it against the other on Monday. Have a good weekend
 
markos

markos

Well-known member
VIP
Hey @Branch, if you should return, please put the original header back in an give it a new revision date w your name.
Thanks!
 
D

dmillz

Member
Anyone know how to scan the red to green move under the zero line and above the Oversold line? seems like these moves have the best runs!
 
S

ssaeed73

New member
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?
 
T

TraderKevin

Member
@hCaostrader 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!
 
H

hCaostrader

New member
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.
 

Similar threads

Top