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

스냅샷

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:



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:

스냅샷

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

스냅샷

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

오픈 소스 스크립트

진정한 TradingView 정신에 따라, 이 스크립트의 저자는 트레이더들이 이해하고 검증할 수 있도록 오픈 소스로 공개했습니다. 저자에게 박수를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 출판물에서 이 코드를 재사용하는 것은 하우스 룰에 의해 관리됩니다. 님은 즐겨찾기로 이 스크립트를 차트에서 쓸 수 있습니다.

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


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.
또한 다음에서도:

면책사항