October 19, 2007
MACD Histograms (v1)
Q1. How to plot an MACD histogram with bars above zero colored green and bars below zero colored red, in simple terms?
1 2 3 4 5 | //Substitue your code for x //Graham Kavanagh Mycolor = IIf( x > 0, colorGreen, colorRed); Plot( x, "", mycolor, styleHistogram) |
Q2. Is there a MACD histogram parameter in AmiBroker or do you have to calculate it yourself by subtracting the MACD from the SIGNAL?
The MACD short and long EMA difference is ‘built in’ to the AmiBroker MACD Indicator (it can be plotted as a Histogram if required).
AB Help Manual >> Technical Analysis Guide >> Indicators
“The Moving Average Convergence/Divergence indicator (MACD) is calculated by subtracting the value of 26-day exponential moving average from a 12-day exponential moving average. A 9-day exponential moving average (the “signal line”) is automatically displayed on top of the MACD indicator line”.
Q3. Is there a way to modify the width of the bars for the built-in MACD histogram? The bars are narrow lines which are difficult to read when near zero.
styleThick or you might even try styleArea, just be sure it’s the last Plot statement or it will cover up your other lines.
1 2 3 4 | //Terry Magic color = IIf(cond > 0, colorGreen, colorRed); Plot(cond,"cond",color,styleHistogram+styleThick); |
The following code has been adapted from the MACD Indicator built in to AmiBroker.
1 2 3 4 5 6 7 8 9 10 11 12 13 | //MACD - Moving Average Convergence Divergence v1 //adapted from code by Tomasz Janeczko //ideas by Graham Kavanagh and Terry Magic r1 = Param( "Fast avg", 12, 2, 200, 1 ); r2 = Param( "Slow avg", 26, 2, 200, 1 ); r3 = Param( "Signal avg", 9, 2, 200, 1 ); m1 = MACD(r1, r2); s1 = Signal(r1,r2,r3); difference = m1-s1; Plot( m1, StrFormat(_SECTION_NAME()+"(%g,%g)", r1, r2), ParamColor("MACD color", colorRed ), ParamStyle("MACD style") ); Plot( s1, "Signal" + _PARAM_VALUES(), ParamColor("Signal color", colorBlue ), ParamStyle("Signal style") ); Color=IIf(difference > 0,colorGreen,colorRed); Plot(difference, "MACD Histogram", Color, styleNoTitle | ParamStyle("Histogram style", styleHistogram | styleThick | styleNoLabel, maskHistogram ) ); |
The top MACD graph uses the AmiBroker ‘built in’ indicator and the lower uses the adapted version.
AmiBrokerYahooGroup message #76360 “MACD Histogram” http://finance.groups.yahoo.com/group/amibroker/message/76360
Thanks to Anthony, Don, Graham, Terry and others for their contributions.
ATTACHED FILE:
AB MACD Indicator adapted to plot as a thick colored histogram macd-moving-average-convergence-divergence-v1.afl
Filed by brian_z at 4:52 am under Indicators


(1 votes, average: 4 out of 5)
MACD Histograms v1 corrects errors - short and long MA’s in the price chart changed to EMA’s and answer to Q2 updated.