Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers, Unverified Users Joined: 10/28/2004(UTC) Posts: 3,111 Location: Perth, Western Australia
Was thanked: 16 time(s) in 16 post(s)
|
I was playing with some AMA formula, trying to get my head around how Perry Kaufman came up with his Adaptive Moving Average. I started editing the code to make it more succinct and run faster on my P.O.C. computer. I also took out his weightings as they didn't seem logical to me, and I couldn't identify how he arrived at the settings he did (and IMHO it works better without it!)
What I came up with is this:
{Mod. Kaufman's Adaptive Moving Average}
{by wabbit}
prd:=Input("Time Periods",1,1000, 31);
K:=Power(ROC(CLOSE,prd,$)/Sum(Abs(ROC(CLOSE,1,$)),prd),2);
AMA:=If(Cum(1)=prd+1,C,PREV*(1-K)+C*K);
AMA;
Anyway, I was thinking about the seeding problem (see other threads on this forum for seeding definitions and problems - just do a search).
I tried to use a seed:
AMA:=If(Cum(1) <= prd+1,C,PREV*(1-K)+C*K); {note the less than symbol}
to say, in the first "prd" bars of the induicator return the CLOSE price. Once the formula gets to the "prd+1"th bar then carry on using the close of the "prd"th bar as the seed. This returns N/A in the first "prd" bars, and the CLOSE on the "prd+1"th bar?? BUT I have clearly stated that in the first "prd" bars, just return the close?
Can't seem to get my head around this??
What say you Patrick, Jose, anyone?
wabbit :D
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
It's not a logic problem, it is a "MetaStock" problem ... :cry:
There is no way around it unfortunately ... I tried to mess with the isdefined() function with no success.
Metastock will check in all the results in your if statement and see how many periods it needs for both results and then will calculate the value if it has enough data. It's kind of like the division by zero error, metastock check to see if it is possible to get a div by zero error and even though there is no way it could happen will pop up the error message.
So if you wrote
PDS:=10;
If(1>0,C,Mov(C,pds,E))
Even though the statement will never be false, metastock will wait till it can calculate your moving average to plot the close value.
Patrick
|
|
|
|
Rank: Advanced Member
Groups: Registered, Registered Users, Subscribers Joined: 9/8/2004(UTC) Posts: 2,266
Was thanked: 1 time(s) in 1 post(s)
|
I like your simplified version, it's almost the same and you got rid of some extra code :D
I do agree, it seems that the smoothing code is almost useless ... I wonder why that was done like this :-k
Patrick :mrgreen:
|
|
|
|
Users browsing this topic |
Guest (Hidden)
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.