OPEN-SOURCE SCRIPT

RedK K-MACD : a MACD with some more muscles

Updated
Moving Averages are probably the most commonly used analysis tools, and MACD is possibly the first charting indicator a trader gets to learn about.

MACD Basic concept
----------------------------
Without repeating all the tons of documentation about what MACD does, let's quickly re-visit the MACD concept from a 10-mile altitude (note we're keen on simplifying here rather than being technically accurate - so please forgive the use of any "common lingos")
- MACD goal is to represent the distance between 2 Moving Averages (MAs) - one fast and one slow, relatively - as an unrestricted zero-based oscillator.
- The value of the main MACD line is the distance, or the displacement between the 2 MA's
- usually a signal line is used (which is another MA of that distance value) to enable better visualization of the change (and rate of change, since this is all depicted on a time axis) of that displacement - this represents price momentum (price movement in the recent period versus movements for a relatively longer period).
- the difference between the main MACD line and its signal is then represented as a histogram above and below the zero line. in this case, that histogram is really redundant, since it shows a value that is already represented visually by the main line and its signal line.

How K-MACD is different
---------------------------------

K-MACD takes that simple concept of the classic MACD and expands around it - the idea is to use the same simple approach to representing price momentum while bringing in more insight to price moves in the short, medium and long terms, ability to represent more than 2 MA's and to enable better identification of tradeable patterns (like Volatility Contraction and others) - while still keeping things simple and visually clean.

K-MACD is an indicator that allows us to view how price moves against 3 moving averages: a fast / slow pair, and a "market" Filter or Baseline (very long) that will be used as a flag for Bear/Bull market mode. Many traders and trading literature use the 200 day (40 week) SMA as that key filter

so in total, there are 4 MA lines in K-MACD (excluding the "orange" signal line):
* Price Proxy: Which is a very fast moving average that will represent the price itself - let's use a WMA(3) or something close to that here - there will be a signal line to enable better visualization of this similar to a classic MACD - that's the orange line

* Fast & Slow MA's : Use whatever represents the "medium term" momentum for your trading - Some traders use 20 and 50, others use 10 and 20 .. if on your price chart, you keep using a pair of MA's for this, use the same settings in K-MACD - these will be represented by the 3-color Momentum Bars that fluctuate above and below the baseline

* Filter/Baseline MA: Should be your long (Bullish/Bearish Mode) MA. so 100 or 200 or any other value you consider your market to be bearish below and bullish above. on K-MACD this is actually the blue zero line - everything else is "relative" to it

Review the sample chart which explains various elements and the "price chart" setup that K-MACD represents. With K-MACD you can clean up your chart from those various Moving Averages - or use a different set than the ones you already have K-MACD represent - or other indicators (like ATR channels..etc)

Other "muscles" in the K-MACD
---------------------------------------------
- Relative vs Classic Calculation Mode
A key issue with the classic MACD is that the displacement between the 2 moving averages is represented as "absolute or direct" values - as the price of the underlying increases with time, you can't really use these values to make useful comparison between the past and now (see below example) - also you can't use them to compare 2 different instruments.
- The "Relative" calculation option in K-MACD addresses that issue by relating all "distances" to the Baseline MA as percentage (above or below) - you can see this clear when you look at the above chart the far left versus the far right and compare K-MACD with the classic MACD - the Classic option is still available

snapshot

- More MA "type" options for all MA lines: choose between SMA, EMA, WMA, and RSS_WMA (which i use a lot in my trading and is my default for the Price Proxy)

snapshot


- More Alerts: a total or 9 alerts (in 3 groups) are available with K-MACD (Momentum above or below baseline, Price Proxy crossing signal line, and Price Proxy crossing baseline)

- New 52 week High / Low markers: These will show as Green/red circles on the zero line in K-MACD. this will only work for 1D timeframe and above, i'm just using a simple approach and would like to keep it that way.

- i know i added some more features not covered above :) -- if you have questions about any of the settings, feel free to ask below

Closing thoughts
-------------------------
K-MACD is a combination of couple of indicators i published in the past (xMACD and Mo_Bars) - so you can go back and read about them if needed - I then added improvements to accommodate ideas from swing trading literature and common practices that i plan to focus on in future. So K-MACD is really part of my own trading setup.

I assume here that most traders are familiar with what a MACD is - so kept this post short - if you thing we should expand more about the concepts covered here let me know in the comments - i can make some separate posts with examples and more details.

I hope many fellow traders find this work useful - and feel free let me know in comments below if you do.
Release Notes
Update K-MACD V1.1
----------------------------------

Made few updates based on initial feedback and my to-do list
- Improved the "New 52Wk Hi/Lo" approach to support symbols with less than 53 Weeks from IPO (like MBLY). Starting week #2, new all-time Hi/Lo's will be flagged - doesn't affect symbols that are already > 52 weeks since IPOs

- Added value for "Price % within 52Wk Hi/Lo range" - will print on the indicator status line and in the data window (see below chart) - and although this will not work for timeframe less than 1D (cause the calculation is based on the daily bar close) - i decided to leave it on lower TF's cause i believe it's still valuable (in lower TFs, may show values above 100% or below 0 - that's not a bug)

- The Price Proxy line is now dual-color similar to the xMACD -- changed default color of the signal line from orange to aqua which works (visually) better against a green/red main line.

- added Moving Average Type option for the Proxy Signal line, with default as EMA .. which can work better as a signal line compared to WMA -- but can be changed back in the settings

- couple other minor code tweaks and clean-ups

snapshot
Release Notes
Version 1.2
- Quick code fix for calculating all-time Hi/Lo instead of "new 52-wk Hi/Lo" for periods before 52 weeks since IPO
Release Notes
RedK K-MACD Version 1.3 with a quick fix to how the momentum bars are colored - couple minor code clean-ups
k-macdMoving Average Convergence / Divergence (MACD)mobarsmoving_averageMoving AveragesmovingaveragecrossoverosciladoresredkVolatility

Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in publication is governed by House rules. You can favorite it to use it on a chart.

Want to use this script on a chart?

Disclaimer