OPEN-SOURCE SCRIPT

Adaptive MACD [LuxAlgo]

The Adaptive MACD indicator is an adaptive version of the popular Moving Average Convergence Divergence (MACD) oscillator, returning longer-term variations during trending markets and cyclic variations during ranging markets while filtering out noisy variations.

🔶 USAGE

ảnh chụp nhanh

The proposed oscillator contains all the elements within a regular MACD, such as a signal line and histogram. A MACD value above 0 would indicate up-trending variations, while a value under 0 would be indicating down-trending variations.

ảnh chụp nhanh

Just like most oscillators, our proposed Adaptive MACD is able to return divergences with the price.

ảnh chụp nhanh

As we can see in the image above ranging markets will make the Adaptive MACD more conservative toward more cyclical conservations, filtering out both noise and longer-term variations. However, when longer-term variations (such as in a trending market) are prominent the oscillator will conserve longer-term variations.

The R2 Period setting determines when trending/ranging markets are detected, with higher values returning indications for longer intervals.

The fast and slow settings will act similarly to the regular MACD, however, closer values will return more cyclical outputs.

ảnh chụp nhanh

The image above compares our proposed MACD (top) with a regular MACD (bottom), both using fast = 19 and slow = 20.

🔶 DETAILS

It is common to be solely interested in the trend component when the market is trending, however, during a ranging market it is more common to observe a more prominent cyclical/noise component. We want to be able to preserve one of the components at the appropriate market conditions, however, the regular MACD lack the ability to preserve cyclical component with high accuracy.

The MACD is an IIR bandpass filter. In order to obtain a lower passband bandwidth and a more symmetrical magnitude response (which would allow to conserve more precise cyclical variations) we can directly change the system calculation:



where:



Using division instead of multiplication on the second feedback weight allows further weighting the 2 samples lagged output, returning a more desirable magnitude response with a higher degree of filtering on both ends of the spectrum as shown in the image below:

ảnh chụp nhanh

We are interested in conserving cycles during ranging markets, and longer-term variations during trending markets, we can do this by interpolating between our two filter coefficients:



where 1 > α > 0. α is measuring if the market is trending or ranging, with values closer to 1 indicating a trending market. We see that for higher values of α the original coefficient of the MACD is used. The image below shows various magnitude responses given multiple values of α:

ảnh chụp nhanh

We use a rolling R-Squared as α, this measurement has the benefit of indicating if the market is trending or ranging, as well as being constrained within range (0, 1), and having a U-shaped distribution.

If you are interested to learn more about the MACD see:

A Deep Dive Into The MACD


🔶 SETTINGS

  • R2 Period: Calculation window of the R-Squared.
  • Fast: Fast period for the calculation of the Adaptive MACD, lower values will return more noisy results.
  • Slow: Slow period for the calculation of the Adaptive MACD, higher values will return result with longer-term conserved variations.
  • Signal: Period of the EMA applied to the Adaptive MACD.
adaptiveadaptivemacdDivergenceLUXluxalgoMoving Average Convergence / Divergence (MACD)macddivergenceTrend Analysis

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 đồ?


Get access to our exclusive tools: luxalgo.com

Join our 150k+ community: discord.gg/lux

All content provided by LuxAlgo is for informational & educational purposes only. Past performance does not guarantee future results.
Ngoài ra, trên:

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