[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Amibroker Code for MAMA adaptive moving average



PureBytes Links

Trading Reference Links

HI,

I am an absolute beginner, kindly explain how do we get this code in
amibroker and how do we run the same.

Also tell me the advantages of this system. I guess it is for
distinguishing cycles in the stocks, right?

--- In amibroker@xxxxxxxxxxxxxxx, "walkegra" <walkegra@xxx> wrote:
>
> Easy-Language code for MAMA adaptive moving average (ref: 
> www.mesasoftware.com) is posted in the files section tilted MAMA.doc.
> Following is my attempted AB implementation of this code but it does 
> not produce anything like the expected moving averages.  Can anyone 
> point out and correct the errors in my AB code?
> 
> Thank you.
> 
> 
> //MAMA  Adaptive MA
> 
> Pr = (H + L)/2;
> FastLimit = 0.5;
> SlowLimit = 0.05;
> 
> Smooth = (Pr * 4 + Ref(Pr,-1) * 3 + Ref(Pr,-2) * 2 + Ref(Pr,-3))/10;
> 
> Detrender = (0.0962 * Smooth + 0.5769 * Ref(Smooth,-2) -  0.5769 * Ref
> (Smooth,-4) -  0.0962 * Ref(Smooth,-6))* (0.075 * Ref(Pr,-1) + 0.54);
> 
> Q1 = (0.0962 * Detrender + 0.5769 * Ref(Detrender,-2) -  0.5769 * Ref
> (Detrender,-4) -  0.0962 * Ref(Detrender,-6))* (0.075 * Ref(Pr,-1) + 
> 0.54);
> 
> I1 = Ref(Detrender,-3);
> 
> jI = (0.0962 * I1 + 0.5769 * Ref(I1,-2) -  0.5769 * Ref(I1,-4) -  
> 0.0962 * Ref(I1,-6))* (0.075 * Ref(Pr,-1) + 0.54);
> 
> jQ = (0.0962 * Q1 + 0.5769 * Ref(Q1,-2) -  0.5769 * Ref(Q1,-4) -  
> 0.0962 * Ref(Q1,-6))* (0.075 * Ref(Pr,-1) + 0.54);
> 
> I2 = I1 - jQ;
> Q2 = Q1 + jI;
> 
> I2 = 0.2 * I2 + 0.8 * Ref(I2,-1);
> Q2 = 0.2 * Q2 + 0.8 * Ref(Q2,-1);
> 
> Re = I2 * Ref(I2,-1) + Q2 * Ref(Q2,-1);
> Im = I2 * Ref(Q2,-1) - Q2 * Ref(I2,-1);
> 
> Re = 0.2 * Re + 0.8 * Ref(Re,-1);
> Im = 0.2 * Im + 0.8 * Ref(Im,-1);
> 
> Period = IIf(Im != 0 AND RE != 0, 360/atan(Im/Re),0);
> 
> Period = IIf(Period > 1.5 * Ref(Period,-1), 1.5 * Ref(Period,-
> 1),Period);
> 	IIf(Period < 0.67 * Ref(Period,-1),0.67 * Ref(Period,-
> 1),Period);
> 	IIf(Period < 6, 6,Period);
> 	IIf(Period > 50, 50, Period);
> 
> Phase = IIf(I1 != 0, atan(Q1/I1),0);
> DeltaPhase = Ref(Phase,-1) - Phase;
> DeltaPhase = IIf(DeltaPhase < 1, 1, DeltaPhase);
> Alpha = FastLimit/DeltaPhase;
> Alpha = IIf(Alpha < SlowLimit, SlowLimit, Alpha);
> MAMA = Alpha * Pr;
> MAMA = Alpha * Pr + (1 - Alpha) + Ref(MAMA,-1);
> FAMA = 0.5 * Alpha * MAMA;
> FAMA =  0.5 * Alpha * MAMA + (1 - 0.5 * Alpha) * Ref(FAMA,-1);
> 
> Plot(C,"Price",1,styleCandle);
> Plot(MAMA,"MAMA",2);
> Plot(FAMA,"FAMA",3);
>