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.


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.


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]


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:


  • 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 LuxAlgo indicators:

Join our 100k+ community:

All scripts & content provided by LuxAlgo are for informational & educational purposes only. Past performance does not guarantee future results.
오픈 소스 스크립트

이 스크립트의 오써는 참된 트레이딩뷰의 스피릿으로 이 스크립트를 오픈소스로 퍼블리쉬하여 트레이더들로 하여금 이해 및 검증할 수 있도록 하였습니다. 오써를 응원합니다! 스크립트를 무료로 쓸 수 있지만, 다른 퍼블리케이션에서 이 코드를 재사용하는 것은 하우스룰을 따릅니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.


이 정보와 게시물은 TradingView에서 제공하거나 보증하는 금융, 투자, 거래 또는 기타 유형의 조언이나 권고 사항을 의미하거나 구성하지 않습니다. 자세한 내용은 이용 약관을 참고하세요.

차트에 이 스크립트를 사용하시겠습니까?