Req:Help for Power Moving Averages AFL

#1
Dear Friends,
Can someone correct this useful AFL so as to run proper EMA lines...???
I'm not sure "PREV" is the correct variable for the AFL....
Waiting for your great contribution....
Thanks in advance....


*************************************************
_SECTION_BEGIN("Power Moving Averages");

P1 = Param("EMA Periods1", 9, 2, 200, 1);
Pr=(H+L+2*C)/4;
MA1=TEMA(Pr,P1);
Shift=round(P1/2);
center=LastValue(Shift);
CMA=Ref(MA1,center);
y=LastValue(CMA+PREV-PREV);
CMA=IIf(y>0,y,Pr);
CMA1= Ref(TEMA(Pr,P1-1),center-1)
y=LastValue(CMA1+PREV-PREV);
CMA1=IIf(y>0,y,Pr);
CMA2= Ref(TEMA(Pr,P1-2),center-2)
y=LastValue(CMA2+PREV-PREV);
CMA2=IIf(y>0,y,Pr);
CMA3= Ref(TEMA(Pr,P1-3),center-3)

y=LastValue(CMA3+PREV-PREV);
CMA3=IIf(y>0,y,Pr);
CMA4= Ref(TEMA(Pr,P1-4),center-4)
y=LastValue(CMA4+PREV-PREV);
CMA4=IIf(y>0,y,Pr);
CMA5= Ref(TEMA(Pr,P1-5),center-5)
y=LastValue(CMA5+PREV-PREV);
CMA5=IIf(y>0,y,Pr);

CMAP=
IIf(Cum(1)=LastValue(Cum(1)-center+1),CMA1,
IIf(Cum(1)=LastValue(Cum(1)-center+2),CMA2,
IIf(Cum(1)=LastValue(Cum(1)-center+3),CMA3,
IIf(Cum(1)=LastValue(Cum(1)-center+4),CMA4,
IIf(Cum(1)=LastValue(Cum(1)-center+5),CMA5,CMA)))));
K=CMAP;
K1=EMA(K,4);
Plot(K,"",colorGreen,Styline);
Plot(K1,"",colorRed,Styline);


_SECTION_END();
 

asnavale

Well-Known Member
#2
Dear Friends,
Can someone correct this useful AFL so as to run proper EMA lines...???
I'm not sure "PREV" is the correct variable for the AFL....
Waiting for your great contribution....
Thanks in advance....


*************************************************
_SECTION_BEGIN("Power Moving Averages");

P1 = Param("EMA Periods1", 9, 2, 200, 1);
Pr=(H+L+2*C)/4;
MA1=TEMA(Pr,P1);
Shift=round(P1/2);
center=LastValue(Shift);
CMA=Ref(MA1,center);
y=LastValue(CMA+PREV-PREV);
CMA=IIf(y>0,y,Pr);
CMA1= Ref(TEMA(Pr,P1-1),center-1)
y=LastValue(CMA1+PREV-PREV);
CMA1=IIf(y>0,y,Pr);
CMA2= Ref(TEMA(Pr,P1-2),center-2)
y=LastValue(CMA2+PREV-PREV);
CMA2=IIf(y>0,y,Pr);
CMA3= Ref(TEMA(Pr,P1-3),center-3)

y=LastValue(CMA3+PREV-PREV);
CMA3=IIf(y>0,y,Pr);
CMA4= Ref(TEMA(Pr,P1-4),center-4)
y=LastValue(CMA4+PREV-PREV);
CMA4=IIf(y>0,y,Pr);
CMA5= Ref(TEMA(Pr,P1-5),center-5)
y=LastValue(CMA5+PREV-PREV);
CMA5=IIf(y>0,y,Pr);

CMAP=
IIf(Cum(1)=LastValue(Cum(1)-center+1),CMA1,
IIf(Cum(1)=LastValue(Cum(1)-center+2),CMA2,
IIf(Cum(1)=LastValue(Cum(1)-center+3),CMA3,
IIf(Cum(1)=LastValue(Cum(1)-center+4),CMA4,
IIf(Cum(1)=LastValue(Cum(1)-center+5),CMA5,CMA)))));
K=CMAP;
K1=EMA(K,4);
Plot(K,"",colorGreen,Styline);
Plot(K1,"",colorRed,Styline);


_SECTION_END();
Hi kargocu,

PREV is not a built-in variable or constant in AmiBroker. The code appears to be translated from some other software where PREV is defined variable. Probably it it is equivalent of Ref(X, -1) where X is an array like Close.

In the lines like the following:

y=LastValue(CMA1+PREV-PREV);

CMA1+PREV-PREV is equal to CMA1 itself (Mathematically) and Ami would evaluate it in the same way. May be some other syntax is missing in that line. If you can get the original code it may be possible to decipher it and write the proper AFL.

-Anant
 
#3
Hi kargocu,

PREV is not a built-in variable or constant in AmiBroker. The code appears to be translated from some other software where PREV is defined variable. Probably it it is equivalent of Ref(X, -1) where X is an array like Close.

In the lines like the following:

y=LastValue(CMA1+PREV-PREV);

CMA1+PREV-PREV is equal to CMA1 itself (Mathematically) and Ami would evaluate it in the same way. May be some other syntax is missing in that line. If you can get the original code it may be possible to decipher it and write the proper AFL.

-Anant
Dear Friend Anant,

The original code is in MetaStock as follow(and it works in MS without any problem)...
Best Regards,
******************************************************
P1:=Input(" period",1,100,9);
Pr:=(H+L+2*C)/4;
MA:=Mov(Pr,P1,TRI);
Shift:=Round(P1/2);
center:=LastValue(Shift);
CMA:=Ref(MA,center);
y:=LastValue(CMA+PREV-PREV);
CMA:=If(y>0,y,Pr);
CMA1:=Ref(Mov(Pr,P1-1,TRI),center-1);
y:=LastValue(CMA1+PREV-PREV);
CMA1:=If(y>0,y,Pr);
CMA2:=Ref(Mov(Pr,P1-2,TRI),center-2);
y:=LastValue(CMA2+PREV-PREV);
CMA2:=If(y>0,y,Pr);
CMA3:=Ref(Mov(Pr,P1-3,TRI),center-3);
y:=LastValue(CMA3+PREV-PREV);
CMA3:=If(y>0,y,Pr);
CMA4:=Ref(Mov(Pr,P1-4,TRI),center-4);
y:=LastValue(CMA4+PREV-PREV);
CMA4:=If(y>0,y,Pr);
CMA5:=Ref(Mov(Pr,P1-5,TRI),center-5);
y:=LastValue(CMA5+PREV-PREV);
CMA5:=If(y>0,y,Pr);

CMAP:=
If(Cum(1)=LastValue(Cum(1)-center+1),CMA1,
If(Cum(1)=LastValue(Cum(1)-center+2),CMA2,
If(Cum(1)=LastValue(Cum(1)-center+3),CMA3,
If(Cum(1)=LastValue(Cum(1)-center+4),CMA4,
If(Cum(1)=LastValue(Cum(1)-center+5),CMA5,CMA)))));
CMAP;Mov(CMAP,4,E);
 

Similar threads