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

[amibroker] Amibroker Code for MAMA adaptive moving average



PureBytes Links

Trading Reference Links

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);






------------------------ Yahoo! Groups Sponsor --------------------~--> 
In low income neighborhoods, 84% do not own computers.
At Network for Good, help bridge the Digital Divide!
http://us.click.yahoo.com/EpW3eD/3MnJAA/cosFAA/GHeqlB/TM
--------------------------------------------------------------------~-> 

Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For other support material please check also:
http://www.amibroker.com/support.html

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/