# help required- reversing macd

#### sandek07

##### New Member
help required in converting metastock code to amibroker afl code:
metastock code is for reversing macd by Johnny Dough
t1:= Input("fast periods", 5, 24, 12);
t2:= Input("slow periods", 10, 52, 26);
pick:= Input("plot: <1=MACDeq 2=MACDeq0 3=HLC 4=BBands>",1,4,1);

a1:= 2/(t1+1);
a2:= 2/(t2+1);
CMACDeq:=(Ref(Mov(C,t1,E)*a1,-1)-Ref(Mov(C,t2,E)*a2,-1))/(a1-a2);
HMACDeq:=(Ref(Mov(H,t1,E)*a1,-1)-Ref(Mov(H,t2,E)*a2,-1))/(a1-a2);
LMACDeq:=(Ref(Mov(L,t1,E)*a1,-1)-Ref(Mov(L,t2,E)*a2,-1))/(a1-a2);
MACDeq0:= Ref(Mov(C,t2,E)*(1-a2) - Mov(C,t1,E)*(1-a1),-1)/(a1-a2);

z:= LastValue(If(pick > 2, 0, Cum(1)+1));
plot1:= If(pick=3, HMACDeq, BBandTop(CMACDeq,10,S,1));
plot2:= If(pick=2, MACDeq0, CMACDeq);
plot3:= If(pick=3, LMACDeq, BBandBot(CMACDeq,10,S,1));

plot1 + Ref(0,+z);
plot2;
plot3 + Ref(0,+z);

--------------------------------------------------

t1:= Input("fast periods", 5, 24, 12);
t2:= Input("slow periods", 10, 52, 26);
t3:= Input("signal periods", 3, 18, 9);
pick:= Input("plot: <1=MACD 2=MACD_HLC 3=MACD_MTF>",1,4,1);

MACDH:=Mov(H,t1,E)-Mov(H,t2,E);
MACDL:=Mov(L,t1,E)-Mov(L,t2,E);
MACDC:=OscP(12,26,E,\$);
MTFw:=OscP(12*5,26*5,E,\$);
MTFM:=OscP(12*21,26*21,E,\$);

y:= LastValue(If(pick <>2, 0, Cum(1)+1));
z:= LastValue(If(pick > 1, 0, Cum(1)+1));
plot1:= MACDC;
plot2:= If(pick=2, MACDH, MTFw);
plot3:= If(pick=2, MACDL, MTFm);
plot4:= Mov(MACDC,t3,E);

plot1;
plot2 + Ref(0,+z);
plot3 + Ref(0,+z);
plot4 + Ref(0,+y);