Skip to content

The Relationship Between the MACD and Z-Score: Creating the MAC-Z score

May 11, 2010

The MACD stands for moving average confluence/divergence and was introduced by Gerald Appel a long time ago as a means of tracking trends. Some background reading on the MACD can be found here: http://en.wikipedia.org/wiki/MACD
Effectively the MACD represents the difference between two moving averages–a short moving average and a longer moving average. As a consequence the MACD tracks the acceleration or rate of change in the trend. The Z-Score in contrast is related to Bollinger Bands and of course the normal distribution. It is designed to track the position within the price distribution normalized by volatility. Some background reading on the Z-score can be found here. Effectively the Z-score is the difference between the current price and a moving average divided by the standard deviation of price over the same time period.

So, many of you are already asking the question: “OK so what is the relationship here?” Well it comes down to how the math works–especially as it applies to financial data. The Z-score is effectively a normalized, rolling and de-trended measurement of deviation from an average. Most people for example use the z-score as a mean-reversion indicator especially in the short term. This is because the price of a stock or index rarely deviates much from its moving average and regardless of trend will tend to gravitate back to the middle value–which is zero. Values exceeding 1 or -1, and especially 2 or -2 are very likely to revert to the mean. The MACD works well at detecting the actual acceleration and direction of the trend, and this is because it looks at the difference between moving averages versus a price deviation from the moving average. Effectively the use of moving averages instead of price removes much of the noise inherent in the data, to more clearly reflect the trend. A positive MACD is bullish, while a negative MACD is either bearish or neutral. Refinements can be made to improve the MACD (see the DVMM at dvindicators.com). So to me the MACD and the Z-score are complementary and can be combined to create an improved indicator– especially if they are scaled to be the same length.

The general idea is that counter-trend component of the Z-score can be used to adjust/improve the trend component of the MACD. In this case my suggestion is to take the 12/25 MACD and the 25-day Z-score as an example of parameters that might be used. The key to combining the two indicators is to restore them to a similar scale. The weakness of the MACD is that it is an unscaled difference between two price moving averages. By taking the raw MACD (difference between the 12 sma and 25 sma) you can basically scale this indicator by dividing it by the 25-day standard deviation. This now gives us the difference expressed in standard deviation units, which is the same scale as the z-score. Now we can create an adaptive (or static) formula to properly combine the separate mean-reversion and trend components within a given time frame. We shall call this new formula the “MAC-Z Score” for reference:

MAC-Z= (Z-score, 25)*A+ (MACD,25)/(Stdeva,25)*B

where A and B are constants that can range between 2 and -2 in .2 increments to reduce computational time.

It is recommended that if you want to create a composite trend indicator the constant “A” should be negative. However this depends on the parameter length selected (in this case both use a 25 day as the long length) where the shorter the parameter length, the more likely “A” should be a negative value. In the case of “B” this should be a positive for a composite trend indicator, to reflect the trend impact of the MACD. Either way, as an optimization problem, the MAC-Z can be run with all iterations either way across a basket of securities, or to be customized to the security in question.

The advantage of the MAC-Z is that it is a more accurate and “assumption-free” indicator that can more accurately describe how a market or stock actually works in a given time frame. To more accurately understand where to best apply it, you can optimize the MAC-Z over multiple time frames find the best time frame to apply it or create a composite indicator. I will leave this for creative readers to have fun with—if anyone finds some interesting results I will be happy to post it.

Advertisements
13 Comments leave one →
  1. bootstrap permalink
    May 11, 2010 5:18 pm

    “The Z-Score in contrast is related to Bollinger Bands and of course the normal distribution.”
    -not true.
    Z-score and standard deviation do not assume a normal distribution. Assigning a probability to a z-score requires a distributional assumption. i.e. claiming “66.7% of the data fall is 1 zscore from the mean” asumes the normal distribution.

  2. david varadi permalink*
    May 12, 2010 2:55 am

    to be honest, your semantic argument here is largely irrelevant since most traders and financial institutions (unfortunately) assume that 2 standard deviations away from the mean is a rare occurence in the normal distribution sense. it is true that a z-score in the context of how it is used on financial data is going to be calculated on a rolling basis and will not be normally distributed—however, the actual values -1, +1 etc indicate the standard deviation units that the price is from the mean even if the actual frequency distribution indicates a higher/lower likelihood of occurence. in practice this is not adjusted for when used on inidcators etc (however DV Bands etc use a percentrank procedure to normalize these levels). in either case, the distribution has to be re-mapped to accomodate observed frequencies over a very long interval.

    best
    david

  3. bootstrap permalink
    May 12, 2010 1:10 pm

    It’s relevant b/c it highlight the limits/sloppiness of your analysis.

    • david varadi permalink*
      May 12, 2010 1:33 pm

      that is a pretty funny comment— im not sure how my analysis is limited because I did not fully define the z-score. if precisely defining terms was the pre-requisite for good research than institutions would only be hiring professors at trading firms and hedge funds. ultimately fuzzy problems call for less “deterministic” approaches and more abstract thinking. i have worked with several statistical methods and it has not been the magical solution I thought it would be. i believe you fail to truly understand how abstract things really are in financial markets and take comfort in the tangibility of being able to catch “spelling mistakes” and assuring yourself of your mental superiority.

      best
      dv

    • May 13, 2010 5:11 pm

      Actually, the Z-score is extremely related to the normal distribution, though you are correct that it does not HAVE to refer to normally distributed variables.

      Z-scores are measurements of how many standard deviations an observation lies from the mean value of the distribution. Since [almost] every distribution has a mean, and [almost] every distribution has a standard deviation, you *can* calculate a Z-score for observations from an arbitrary distribution. However, if you are dealing only with the first two moments of a distribution, then the canonical representation of your data is the normal distribution, and that is why Z-scores are intimately tied to normal distributions: they map data to a standardized space based only the first two moments.

      Moreover, that’s why we differentiate Z-scores (Z representing a normal distribution) from t-scores, f-scores, etc. corresponding to other distributions.

      If you want to be super-specific, then you can point out that what David is actually describing is a t-score, since the moment estimates are based on a sample and not a population. However, a) it doesn’t matter practically because we are using the raw score and not converting it to a probability (where it wouldn’t matter much anyway!) and b) since David isn’t even implementing the strategy, but providing an illustration for readers like ourselves to follow, I really don’t see how there’s any sloppiness here.

      David, thanks for taking the time to write. It’s much appreciated.

      J

      • david varadi permalink*
        May 14, 2010 12:39 am

        thanks J, this explanation will help readers more than criticism indeed. feel free to drop me an email if you like.

        best
        david

  4. jim branch permalink
    December 5, 2010 10:12 am

    i would love to have this Macd on my charts. I use Sierra charts but have no clue how to program on a step by step basis.

  5. February 9, 2011 3:42 pm

    Hi David,

    Nice articel. I see someone else published a similar idea after you – http://www.highbeam.com/doc/1P3-2073675511.html

    Keep up the great work
    Cheers
    Derry

  6. October 13, 2011 6:30 am

    Greetings,

    Are you saying A should be -2 and B 2?

    MAC-Z= (Z-score, 25)*-2+ (MACD,25)/(Stdeva,25)*2

    I want to code it on MT4 for Forex…thanks

  7. Steve permalink
    January 23, 2013 1:49 pm

    Assuming most data fell within 2, 3 or even 4 Standard deviations have caused untold financial disasters starting with Long Term Capital !

  8. April 25, 2013 9:30 pm

    Pretty nice post. I just stumbled upon your
    blog and wanted to say that I have truly enjoyed browsing your blog posts.
    After all I’ll be subscribing to your feed and I hope you write again very soon!

    • david varadi permalink*
      April 29, 2013 11:42 am

      thanks marvin, much appreciated.
      best
      david

  9. November 3, 2013 7:20 am

    Hi David, great post! I just came across this now, I tried putting it into excel and got to the last step, but calculate the MAC-Z score, do you have en example of this spreadsheet I can work off ? Keep up the good work

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: