Finding the slope of MACD line

buffetsbabes

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

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

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?
 
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.
 
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.
 
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:
@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 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;
 
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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
510 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