OPEN-SOURCE SCRIPT

MACDh with divergences & impulse system

-----------------------------------------------------------------
General Description:

This indicator (the one on the low panel) is a classic MACD that also shows regular divergences between its histogram and the prices. This script is special because it can be adjusted to fit several criteria when trading divergences filtering them according to the "height" and "width" of the patterns. The script also includes the "extra feature" Impulse System, which you will hardly find anywhere else in similar classic MACD histogram divergence indicators.

The indicator helps to find trend reversals, and it works on any market, any instrument, any timeframe, and any market condition (except against really strong trends that do not show any other sign of reversion yet).

Please take on consideration that divergences should be taken with caution.


-----------------------------------------------------------------
Definition of classic Bullish and Bearish divergences:

*Bearish divergences occur in uptrends identifying market tops. A classical or regular bearish divergence occurs when prices reach a new high and then pull back, with an oscillator (MACD histogram in this case) dropping below its zero line. Prices stabilize and rally to a higher high, but the oscillator reaches a lower peak than it did on a previous rally.

In the chart above (weekly charts of NKE, Nike, Inc.), in area X (around August 2021), NKE rallied to a new bull market high and MACD-Histogram rallied with it, rising above its previous peak and showing that bulls were extremely strong. In area Y, MACD-H fell below its centerline and at the same time prices punched below the zone between the two moving averages. In area Z, NKE rallied to a new bull market high, but the rally of MACD-H was feeble, reflecting the bulls’ weakness. Its downtick from peak Z completed a bearish divergence, giving a strong sell signal and auguring a nasty bear market.

*Bullish divergences, in the other hand, occur towards the ends of downtrends identifying market bottoms. A classical (also called regular) bullish divergence occurs when prices and an oscillator (MACD histogram in this case) both fall to a new low, rally, with the oscillator rising above its zero line, then both fall again. This time, prices drop to a lower low, but the oscillator traces a higher bottom than during its previous decline.

In the example in the chart above (weekly charts of NKE, Nike, Inc.), you see a bearish divergence that signaled the October 2022 bear market bottom, giving a strong buy signal right near the lows. In area A, NKE (weekly charts) appeared in a free fall. The record low A of MACD-H indicated that bears were extremely strong. In area B, MACD-H rallied above its centerline. Notice the brief rally of prices at that moment. In area C, NKE slid to a new bear market low, but MACD-H traced a much more shallow low. Its uptick completed a bullish divergence, giving a strong buy signal.


-----------------------------------------------------------------
Extra feature: Impulse System

This indicator also includes the “Impulse System”. The Impulse System is based on two indicators, a 13-day exponential moving average and the MACD-Histogram, and identifies inflection points where a trend speeds up or slows down. The moving average identifies the trend, while the MACD-Histogram measures momentum. This unique indicator combination is color coded into the price bars or macd histogram bars for easy reference.

Calculation:
Green Price Bar: (13-period EMA > previous 13-period EMA) and
(MACD-Histogram > previous period's MACD-Histogram)

Red Price Bar: (13-period EMA < previous 13-period EMA) and
(MACD-Histogram < previous period's MACD-Histogram)

Histogram bars are colored blue when conditions for a Red Histogram Bar or Green Histogram Bar are not met. The MACD-Histogram is based on MACD(12,26,9).

The Impulse System works more like a censorship system. Green histogram bars show that the bulls are in control of both trend and momentum as both the 13-day EMA and MACD-Histogram are rising (you don't have permission to sell). A red histogram bar indicates that the bears have taken control because the 13-day EMA and MACD Histogram are falling (you don't have permission to buy). A blue histogram bar indicates mixed technical signals, with neither buying nor selling pressure predominating (either both buying or selling are permitted).

The impulse system can be removed from the chart any time.


-----------------------------------------------------------------
Options/adjustments for this indicator:

*Horizontal Distance (width) between two tops/bottoms criteria.
Refers to the horizontal distance between the MACH histogram peaks involved in the divergence

*Height of tops/bottoms criteria (for Histogram).
Refers to the difference/relation/vertical distance between the MACH HISTOGRAM peaks involved in the divergence: 1st Histogram Peak is X times the 2nd.

*Height/Vertical deviation of tops/bottoms criteria (for Price).
Deviation refers to the difference/relation/vertical distance between the PRICE peaks involved in the divergence.

*Plot Regular Bullish Divergences?.

*Plot Regular Bearish Divergences?.

*Delete Previous Cancelled Divergences?.

*This indicator also has the option to show the Impulse System over the MACD histogram bars


educationalMoving Average Convergence / Divergence (MACD)Oscillators

Mã nguồn mở

Theo tinh thần TradingView thực sự, tác giả của tập lệnh này đã xuất bản dưới dạng nguồn mở để các nhà giao dịch có thể hiểu và xác minh. Chúc mừng tác giả! Bạn có thể sử dụng miễn phí. Tuy nhiên, bạn cần sử dụng lại mã này theo Quy tắc nội bộ. Bạn có thể yêu thích nó để sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?


Ngoài ra, trên:

Thông báo miễn trừ trách nhiệm