Calculate TMO angle at directional change

jonvon33

New member
I am wanting to calculate the angle of the TMO line. Just focusing on the "main". I have figured out how to calculate the angle, but it does the angle on a bar by bar basis. I am wanting to calculate the angle starting when it changes from Red to Green and restart when it changes from green to red. Maybe start at 0 when the color changes and calculate the angle until it changes again. But I don't know how to start measuring angle at a certain point. I am not very good at writing code but I have been pretty successful at moving other peoples code around to get what I need. I just can't find any code where you pick a bar ( i.e. -- TMO changing from red to green) and start measuring at that point.

Here is what I start with. Thank you guys for any help. I am sure it is a pretty simple solution.

Code:
###########################################################################
# filename: MR__EZ_TMO_MTF_
# source: [URL]https://usethinkscript.com/d/91-tmo-with-higher-agg-mobius-tsl[/URL]

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

declare lower;

input length = 10; # default -> 14;
input calcLength = 5;
input smoothLength = 3;
input agg = AggregationPeriod.FIVE_MIN;

def o = open(period = agg);
def c = close(period = agg);
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 EMA = ExpAverage(data, calcLength);
plot Main = ExpAverage(EMA, smoothLength);
def Signal = ExpAverage(Main, smoothLength);

Main.AssignValueColor(if Main > Signal
                                then CreateColor(0, 191, 0)
                                else CreateColor(191, 0, 0)); #Red;
                                 Main.SetLineWeight(3);

def heighttmo = Main - Main[1];
input tmo_pos_limit = 10;
input tmo_neg_limit = -10;
plot “Angle, deg1” = ATan(heighttmo / length) * 180 / Double.Pi;


               
plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.white);
ZeroLine.HideBubble();
ZeroLine.HideTitle();
 
Last edited by a moderator:
Solution
this line:
Code:
Main.AssignValueColor(if Main > Signal ...
gives you the condition for the colors.
You can do something like this to determine the point at which it changed:
Code:
def ChangeDirection = if Main crosses Signal then 1 else 0;
then you have a point where you can specify the start of a series:
Code:
def heighttmo_on_change = if ChangeDirection == 1 then Main else heighttmo_on_change[1];

which you can use in your "angle" calculation. remember though that "angles" aren't really angles in the sense of geometry where you are on a coordinate plane with x and y working in equal increments. on your 'y' you have dollars and on the 'x' you have time -- each of which can vary widely in scale.

-mashume
this line:
Code:
Main.AssignValueColor(if Main > Signal ...
gives you the condition for the colors.
You can do something like this to determine the point at which it changed:
Code:
def ChangeDirection = if Main crosses Signal then 1 else 0;
then you have a point where you can specify the start of a series:
Code:
def heighttmo_on_change = if ChangeDirection == 1 then Main else heighttmo_on_change[1];

which you can use in your "angle" calculation. remember though that "angles" aren't really angles in the sense of geometry where you are on a coordinate plane with x and y working in equal increments. on your 'y' you have dollars and on the 'x' you have time -- each of which can vary widely in scale.

-mashume
 
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
340 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