LuxAlgo

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


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.


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


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.


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:

y[t] = (price[t] - price[t-1]) × g + ((1 - a1) + (1 - a2)) × y[t-1] - (1 - a1) × (1 - a2) × y[t-2]

where:

a1 = 2/(fast + 1)
a2 = 2/(slow + 1)
g = a1 - a2

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:


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:

α × [(1 - a1) × (1 - a2)] + (1 - α) × [(1 - a1) / (1 - a2)]

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 α:


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:


🔶 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.

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.
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 a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?