Maz

Moving Average Slope

Category: Indicators By: Maz Created: May 25, 2017, 8:49 AM
May 25, 2017, 8:49 AM
Indicators
16 Comments
Moving Average Slope

The moving average slope function is an extremely simple indicator and indicates several useful things:

– Direction of the given moving average, thus trend
– Gradient or slope of the given moving average thus momentum or power of the recent price action
– Volatility
– probability of continuation of price action.

This is a simple function which can prove to be valuable for algorithmic or manual trading. Use in conjunction with other indicators to find entries; or use as a filter to prevent bad entries. It’s best used with slower moving exponential averages but can also be used with a combination of averages. This can be considered as a building block for more complex indicators and trading systems.

Advantages

The histogram will give you a easy representation of acceleration or deceleration of  a move. Oftentimes I see system code that checks whether a moving average is going up or going down in relation to its last few bars. This tool is more granular and will also allow you to test for when an average is curving off, or losing steam. That will allow you to enter a move sooner.

Interpretation:
A change in direction of the histogram back towards the zero line indicates the potential curving off of the underlining moving average and thus a reversal is more likely. In conjunction with other indicators, it may help to get into a move earlier than otherwise.

Zero crossings of the histogram suggest momentum is picking up in the direction of the crossing. Zero crossings become more significant if the previous wave was above a given threshold. It is up to you to set that threshold; low volatility crossings should be ignored.

Units are in points expressed as basis points per candle. If the chart was on a one-minute time frame and the histogram was showing +1, this would mean that the moving average was rising by one point per minute. A 30-minute time frame showing -3 would mean the moving average was falling by 6 basis points per hour.

Variables
– maPeriod :: the moving average period. This is normally set at 200 by defailt
– maType :: the moving average method. Expotential average is the default

// ------------------------------
// Moving Average Slope
// Author: Maz @ prorealcode.com
// ------------------------------

// maPeriod = 200 // Moving Average Period
// maType   = 1   // Moving Average function - 1: exponential

ma = average[maPeriod, maType](customClose)
slope = ma - ma[1]

// -- Colour management -----
if slope > 0 then
 if slope > slope[1] then
  g = 255
  r = 0
 elsif slope < slope[1] then
  g = 200
  r = 0
 endif
elsif slope < 0 then
 if slope < slope[1] then
  r = 255
  g = 0
 elsif slope > slope[1] then
  r = 200
  g = 0
 endif
endif

return slope coloured(r, g, 10) style(histogram, 1) as "Moving Average Slope"

Please reach out if there are any questions.

Download
Filename: Moving-Average-Slope.itf
Downloads: 640
Maz
Maz Veteran
Quant fund manager; Founder of institutional HFT engine. Background in market making, arbitrage, machine learning, indicator & algo design. Affection for PRC community - good discussions here. Welcome anyone to reach out, see posts :-)
Author’s Profile

Comments

sydney43025
5 years ago
#

Hello, I'm digging up this topic because I uploaded the code on a PRT v11.1 but the indicator loads on the price chart without displaying any histogram. I can't get it under the price chart. Something happens when I drag the indicator to the RSI panel for example but there is obviously a problem with scaling. Do we need to amend the code for the last PRT versions ? Thanks.

phanz
5 years ago
#

Hi community. May I know how you use this indicator please? Is it on the zero cross over? or the histogram above or below a certain level? My understanding is zero cross over points to the direction, where as histogram above certain level points to the strength of the strength? So for a buy signal, look for a zero cross over, positive histogram above a certain number? What number on the y-axis will point to a healthy trend?

Sumihiko Tachibana
8 years ago
#

I need help to write this script on TD Ameritrade thinkorswim (TOS). How to make it work on TOS? Thanks...

Nicolas
8 years ago
#

We do not offer free assistance for TOS. However, you can send demand for private paid coding at: https://www.prorealcode.com/trading-programming-services/

Marcot18
8 years ago
#

Save Nicolas, non ci riesco puoi postarmelo grazie.

Marcot18
8 years ago
#

Buongiorno, è possibile codificare lo stesso codice per regressione lineare? grazie in anticipo

Nicolas
8 years ago
#

Just change the indicator at line 9 with a linearregression instead of average

Leo
Leo
9 years ago
#

I just have a question about trading. What is better for use as a filter in trading (long): long term moving average slope upwards or price above it or both? Thanks in advance

juanj
9 years ago
#

I coded the above indicator into a strategy, seems to be profitable on the EURUSD 1Hr

juanj
9 years ago
#

I mean a moving average line

juanj
9 years ago
#

Having a moving average bar running above 0 for the green bars and below 0 for the red bars would be a nice addition.

MtraderWD40
9 years ago
#

Many thanks for sharing this, simple but a great indicator. Used it successfully for visual scanning of potential breakout and scalping.  i use it with maPeriod = 50

victormork
9 years ago
#

Thanks Man!!

Tedvin
9 years ago
#

Nice one, thanks a lot Maz :)

Robert
9 years ago
#

Great work! Could be useful :)

Nicolas
9 years ago
#

Hi Maz, it's always a pleasure to review your post, they are always perfectly well formatted with all the required files :) Perfect for a sunny holiday day like today! ;)

ProRealCode ProRealCode
Loading...