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.
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: