Stock Portfolio Organizer

The ultimate porfolio management solution.

Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

MACD - Adaptive V.1.0 for Amibroker (AFL)
PPP
over 5 years ago
Amibroker (AFL)

Rating:
5 / 5 (Votes 3)
Tags:
MACD - Adaptive V.1.0

This indicator was created by Karthik Marar. It is based on classic macd but with an exceptional smoothing.

This smoothing eliminates the noise of the classic macd as you see in the image.

So he calculated the adaptive MACD with two adaptive moving averages, one adaptive to the dominant cycle and the other adaptive to twice the dominant cycle. As the basic behind the MACD is the difference of two moving averages we cannot find much difference between the conventional MACD (12, 26) and the adaptive MACD. However the adaptive MACD is less prone for less whipsaws and the catch the trends very well at the same time the catches the turning points in time. The Adaptive MACD is definite one notch better than the conventional MACD.

Screenshots

Indicator / Formula

Copy & Paste Friendly
//||===================================================================================||
//|| MACD - Adaptive V.1.0 - Adaptive MACD by Karthimarar                               ||
//|| www.karthikmarar.blogspot.com                                                     ||
//|| Public release for personal use only.                                             ||
//|| Please do not commercialize this indicator in its original or modified form       ||
//||===================================================================================||
_SECTION_BEGIN("Dominant Period");
   
    SetBarsRequired( 1000, 1000);
    prc = ( High + Low ) / 2;
    Cyclepart = 0.7 ;
    pi=4*atan(1);
    RTD=180/pi;
    DTR=pi/180;
    
    Smooth[0] = Detrender[0] = I1[0] = Q1[0] = jI[0] = jQ[0] = I2[0] = I3[0] = Q3[0] = Q2[0] = Re[0] = Re1[0] =Im[0] = Im1[0] = 0;
    Period[0] = Period1[0] = alpha = cycle = SmoothPeriod[0] = imagpart[0] = realpart[0] = DCPhase[0] = 0;
    for ( i = 6; i < BarCount; i++ )
    {
    Smooth[i] = ( 4 * prc[i] + 3 * prc[i-1] + 2 * prc[i-2] + prc[i-3] ) / 10;
    Cycle[i] = ((1-0.5*alpha[i])^2)*(Smooth[i] - 2*Smooth[i-1] + Smooth[i-2]) + 2*(1-alpha[i])*Cycle[i-1] - ((1-alpha[i])^2)*Cycle[i-2];
    AmpCorr[i] = 0.075 * Period[i-1] + 0.54;
    Detrender[i] = ( 0.0962 * Smooth[i] + 0.5769 * Smooth[i-2] - 0.5769 * Smooth[i-4] - 0.0962 * Smooth[i-6] ) * AmpCorr[i];
    Q1[i] = ( 0.0962 * Detrender[i] + 0.5769 * Detrender[i-2] - 0.5769 * Detrender[i-4] - 0.0962 * Detrender[i-6] ) * AmpCorr[i];
    I1[i] = Detrender[i-3];
    jI[i] = ( 0.0962 * I1[i] + 0.5769 * I1[i-2] - 0.5769 * I1[i-4] - 0.0962 * I1[i-6] ) * AmpCorr[i];
    jQ[i] = ( 0.0962 * Q1[i] + 0.5769 * Q1[i-2] - 0.5769 * Q1[i-4] - 0.0962 * Q1[i-6] ) * AmpCorr[i];
    I2[i] = I1[i] - jQ[i];
    Q2[i] = Q1[i] + jI[i];
    I3[i] = 0.2 * I2[i] + 0.8 * I3[i-1];
    Q3[i] = 0.2 * Q2[i] + 0.8 * Q3[i-1];
    Re[i] = I3[i] * I3[i-1] + Q3[i] * Q3[i-1];
    Im[i] = I3[i] * Q3[i-1] - Q3[i] * I3[i-1];
    Re1[i] = 0.2 * Re[i] + 0.8 * Re1[i-1];
    Im1[i] = 0.2 * Im[i] + 0.8 * Im1[i-1];
    {
    if ( Im1[i] != 0 AND Re1[i] != 0 )    Period1[i] = 360*DTR / atan( Im1[i] / Re1[i] );
    else
    Period1[i] = Period1[i-1];
    }
    {
    if ( Period1[i] > 1.5 * Period1[i-1] )  Period2[i] = 1.5 * Period1[i-1];
    else
    {
    if ( Period1[i] < 0.67 * Period1[i-1] ) Period2[i] = 0.67 * Period1[i-1];
    else
    Period2[i] = Period1[i]; 
    } 
    }
    {
    if ( Period2[i] < 6 )    Period3[i] = 6;
    else
    {
    if ( Period2[i] > 50 )   Period3[i] = 50;
    else
    period3[i]=Period2[i];
    }
    }
    Period[i] = 0.2 * Period3[i] + 0.8 * Period[i-1];
    SmoothPeriod[i] = 0.33 * Period[i] + 0.67 * SmoothPeriod[i-1];
    DCPeriod[i] = int(SmoothPeriod[i]+0.5);
}

sp=DCperiod;
_SECTION_END();
_SECTION_BEGIN("Adaptive MACD V.1.0");
SetChartBkColor(colorWhite); 
fastper = 2/((sp)+1);
slowper = 2/(2*sp+1);
slowema = AMA(C,slowper);
fastema = AMA(C,fastper);
MACDee = fastema-slowema;
sig  = MA(MACDee,9);
Plot(MACDee,EncodeColor(colorBlue)+"MACD - Adaptive V.1.0"+"("+WriteVal(dcperiod/2,0)+","+WriteVal(dcperiod,0)+")",colorLime,1|styleThick);
Plot(MA(MACDee,9),"sig",colorRed,1|styleThick);
r = MACDee;
s = MA(MACDee,9);
j = MACDee-MA(MACDee,9);
SetBarFillColor(IIf( r-s > 0, colorAqua, colorOrange));
PlotOHLC(0,j,0,j,"",IIf( r-s > 0, colorAqua, IIf(r-s <0 ,colorOrange,colorWhite)), styleCandle |styleOwnScale) ;

_SECTION_END();

6 comments

1. 42gr

Output is good but the code needs refactoring (cleaning).

The param Cyclepart is being set to the value 0.7 but not used anywhere in the code.

2. 42gr

Refer to edit below

3. 42gr

Output is good but the code needs refactoring (cleaning).

The param Cyclepart is being set to the value 0.7 but not used anywhere in the code.

Also change

slowema = AMA( C ,slowper);

To

slowema = AMA( Avg ,slowper);

When crossing with
fastema = AMA(C,fastper);

You get signals on average 1 bar earlier.

Reason is that the slowema
forms a more stable base from the fastema is compared to.

.

4. 42gr

My comments are being changed by the system

The parameters for slowema = AMA and Fastema = AMA have lost their params

Admin: is the system changing or deleting parts of my edits ?

Thanks

5. administrator

I have fixed your comment. Comments are formatted using Markdown that’s why.

6. Yuvan

Dear All and Particularly to Admin,

I have just joined here. The resources available here are pretty awesome and very much useful.

Now my request to you is that i need Explorer for the adaptive macd indicator.

Thanks and Best Regards

Leave Comment

Please login here to leave a comment.

Back