about MACD Histogram divergence


I want to code MACD Histogram divergence like Dr. Alexander Elder in his book(Two Roads Diverged: Trading Divergences).

Here’s the definition of a bullish divergence: “It occurs when prices trace a bottom, rally, and then sink to a new low. At the same time, MACD-Histogram traces a different pattern. When it rallies from its first bottom, that rally lifts it above the zero line, ‘breaking the back of the bear.’ When prices sink to a new low, MACD-Histogram declines to a shallower bottom. At that point, prices are lower, but the bottom of MACD-Histogram is higher, showing that bears are weaker and the downtrend is ready for a reversal. MACD-Histogram gives a buy signal when it ticks up from its second bottom”.

and Bearish divergences: “It occur near market tops, where they identify dangerous cracks in seemingly happy uptrends. A bearish divergence occurs when prices rise to a new high, decline, then rise to a higher peak. MACD-Histogram gives the first sign of trouble when it breaks below its zero line during the decline from its first peak. When prices reach a higher high, MACD-Histogram rises to a much lower high. It shows that bulls are weaker, prices are rising simply out of inertia and are ready to reverse.”

Thank you!

Thanks Ho. See this post on divergences based on RSI:


You would need to change the RSI to MACD Histogram to calculate the pivot lows:

M1 = MACD(BAR1=12, BAR2=26, OSC=9).Histogram;
P1 = PIVOT(M1, MIN=7, TYPE=Low);
V1 = VALUEWHEN(M1, P1 <> 0);
Sig1 = V1 > V1[1];
V2 = VALUEWHEN(Close(),
P1 <> 0);
Sig2 = V2 < V2[1];
M1 < 0 and Sig1 and Sig2

Hi, just picking up on this past post. I wish to use filter looking when MACD-H drops to lowest low of past 100 bars. Would I set MIN=100 in the P1 Pivot?

Also, how can I add a filter on this script to omit stocks under certain volume (ie. 1,000,000 million shares traded in a day) and above a certain price (ie. price greater than $5)?