Interpret and Convert

#1
MS FORMULA

EMA:=Input("Base EMA",1,100,22);
Factor:=Input("Factor",1,50,27);
avg:=Mov(C,EMA,E);
csize:= Stdev(2*Max(Abs(H-avg) ,Abs(L-avg)) / avg,100)*Factor/10;
{Use 100 days for stable channel size - default is 2.7 std}
Csize:= ValueWhen(1,
DayOfWeek()<Ref(DayOfWeek() ,-1) OR (
DayOfWeek()=Ref(DayOfWeek(),-1) AND DayOfMonth() <> Ref(DayOfMonth(),-1))
,Ref(csize,-1));
{ This pegs the Stdev to last bar of week and only changes once per week}
csize:=LastValue(csize);
{fix to constant using last value}
channel:=csize*avg;
avg+channel/2;
avg-channel/2;
avg;



Hello guys..
I need someone's help to interpret this MetaStock formula and then change it to AFL for amibroker.. Thanks in advance..
 

KelvinHand

Well-Known Member
#2
MS FORMULA

EMA:=Input("Base EMA",1,100,22);
Factor:=Input("Factor",1,50,27);
avg:=Mov(C,EMA,E);
csize:= Stdev(2*Max(Abs(H-avg) ,Abs(L-avg)) / avg,100)*Factor/10;
{Use 100 days for stable channel size - default is 2.7 std}
Csize:= ValueWhen(1,
DayOfWeek()<Ref(DayOfWeek() ,-1) OR (
DayOfWeek()=Ref(DayOfWeek(),-1) AND DayOfMonth() <> Ref(DayOfMonth(),-1))
,Ref(csize,-1));
{ This pegs the Stdev to last bar of week and only changes once per week}
csize:=LastValue(csize);
{fix to constant using last value}
channel:=csize*avg;
avg+channel/2;
avg-channel/2;
avg;



Hello guys..
I need someone's help to interpret this MetaStock formula and then change it to AFL for amibroker.. Thanks in advance..

Code:
Period=Param("Base EMA",22,1,100);
Factor=Param("Factor",27, 1,50);

iAvg=EMA(C,Period);

csize= StDev(2*Max(abs(H-iAvg) ,abs(L-iAvg)) / iAvg,100)*Factor/10;
//Use 100 days for stable channel size - default is 2.7 std
Csize= ValueWhen(
        DayOfWeek()<Ref(DayOfWeek() ,-1) OR 
       (DayOfWeek()==Ref(DayOfWeek(),-1) AND 
             Day() != Ref(Day(),-1)),Ref(csize,-1),1);

// This pegs the StDev to last bar of week AND only changes once per week
csize=LastValue(csize);
//fix to constant using last value
channel=csize*iAvg;


Plot(iAvg, "Mid Channel", colorBlue);
Plot(iAvg+channel/2, "Upr Channel", colorBlue);
Ploti(iAvg-channel/2, "Lwr Channel", colorBlue);
 
Last edited:

asnavale

Well-Known Member
#3
Code:
Period=Param("Base EMA",22,1,100);
Factor=Param("Factor",27, 1,50);

Avg=EMA(C,Period);

csize= StDev(2*Max(abs(H-Avg) ,abs(L-Avg)) / Avg,100)*Factor/10;
//Use 100 days for stable channel size - default is 2.7 std
Csize= ValueWhen(
        DayOfWeek()<Ref(DayOfWeek() ,-1) OR 
       (DayOfWeek()==Ref(DayOfWeek(),-1) AND 
             Day() != Ref(Day(),-1)),Ref(csize,-1),1);

// This pegs the StDev to last bar of week AND only changes once per week
csize=LastValue(csize);
//fix to constant using last value
channel=csize*Avg;


Plot(Avg, "Mid Channel", colorBlue);
Plot(Avg+channel/2, "Upr Channel", colorBlue);
Plot(Avg-channel/2, "Lwr Channel", colorBlue);
Hi Kevin,

Please note that AVG is a predefined identifier in AmiBroker. You should not use it as a variable. Therefore, in your code intstead of Avg, use some other identifies such as A.

-Anant
 

Similar threads