Finding the slope of MACD line

buffetsbabes

New member
VIP
Hello,

I have been trying to find a way to design of the following indicator but cannot find a way to make it.

I am trying to calculate the slope of a MACD line with a fast length of 12 and slow length of 26. Is this possible?
 

rad14733

Well-known member
VIP
Thinkscript has no Functions that can calculate slope... That feature is only manually available via Drawing Tools...

Edited to add: Argh...!!! I forgot to mention the Tan and ATan Functions... I forgot about them as I have no experience with them but should have remembered them anyway...
 

buffetsbabes

New member
VIP
Okay so I literally have no idea how to code at all, so any help would be appreciated. Instead of thinking about the slope, this could be a different way.

[12-day EMA(4hr) - 26-day EMA(4hr)) - (12-dayEMA(t=0) - 26-dayEMA(t=0)] / (t=4hr - t=0hr)

This would effectively give the slope of the MACD line but I have no idea if this is possible. Thoughts?
 

XeoNoX

Well-known member
VIP
Calculate the slope of a macd's slow and fast lengths? if you set the slope's length to 9, then the slopes length would be nine. What about the slope exactly are you tying to calculate? you have some pretty deep thought arithmetic going on there.
 

Prison Mike

Member
Calculate the slope of a macd's slow and fast lengths? if you set the slope's length to 9, then the slopes length would be nine. What about the slope exactly are you tying to calculate? you have some pretty deep thought arithmetic going on there.
I'm looking to find slope of a moving average in degrees so anything over 0 would be incline.
 

XeoNoX

Well-known member
VIP
I'm looking to find slope of a moving average in degrees so anything over 0 would be incline.

Keep in mind although zero (mid point of incline/decline a described by you) would be theoretically flat remember that price has to move up and down (so there is not such thing as "flat") so there is a threshold tolerance when it comes to the divergence or "squeezing" of the moving averages, and since macd compares 2 moving averages at different lengths the zeroline although theoretically would be flat (mid point of incline/decline a described by you) would not be the case do to price having to move a point in order to move and the difference of the MA lengths compared to. In plain English not everything over 0 would be incline and not everything below would be decline... you will have to find the threshold to your liking similar to how the RSI overbought/oversold threshold works.

The code calculates the angle of slope of the macd moving average with the given MACDlength.
The angle itself is calculated using the return of the arc tangent of an angle in the range of -pi/2 through pi/2.

Code:
declare lower;
#The code calculates the angle of slope of the macd moving average with the given MACD length.
#The angle itself is calculated using the return of the arc tangent of an angle in the range of -pi/2 through pi/2.
#By XeoNoX via usethinkscript.com
input fastLength = 12;
input slowLength = 26;
input MACDLength = 9;
input averageType = AverageType.EXPONENTIAL;
def Value = MovingAverage(averageType, close, fastLength) - MovingAverage(averageType, close, slowLength);
def Avg = MovingAverage(averageType, Value, MACDLength);
def height = avg - avg[MACDLength];
plot "Angle, deg" = ATan(height/MACDLength) * 180 / Double.Pi;
"Angle, deg".SetDefaultColor(Color.GREEN);
plot zeroline = 0;
zeroline.SetDefaultColor(Color.red);
 
Last edited:

Prison Mike

Member
@XeoNoX Thanks for the way you give back to the community. You are appreciated.

With a few modifications could I replace “Value” with any study’s moving average to find its slope? For instance, the slope of a 50 day relative volume.
 

XeoNoX

Well-known member
VIP
@XeoNoX Thanks for the way you give back to the community. You are appreciated.

With a few modifications could I replace “Value” with any study’s moving average to find its slope? For instance, the slope of a 50 day relative volume.
you would have to change a bit out of each line because not everything is going to have a fast and a slow and a separate length (3 lengths).

For instance the following code calculates the angle of slope of the simple moving average with the given length.

Code:
declare lower;
input length = 3;
def avg = Average(close, length);
def height = avg - avg[length];
plot "Angle, deg" = ATan(height/length) * 180 / Double.Pi;
 

tommy jake

New member
i have been looking into this as well. slope is rise/run. so just depends on how far back you want to look at slope data? five bars? ten?
(value - value[4])/5 would be the slope of five bars back to current
 

Similar threads

Top