Re: More help: Exponential Moving Averages
- Posted by Pete Lomax <petelomax at blueyonder.co.uk> Jan 19, 2003
- 413 views
On Sat, 18 Jan 2003 21:37:52 +0930, noranross at optusnet.com.au wrote: >Thanks for Query The period is 5. The actual EMA is as follows. My >calculations do not get these figures or anything close. >Date EMA Close >2/1/02 3419 3440 >3/1/02 3418 3414 >4/1/02 3425.5 3443 >7/1/02 3429 3463 >8/1/02 3436 3430 >9/1/02 3431 3420 > >Ross Elliott Darwin The following code does not always get the right results either, actually, it only gets one answer right.... Maybe Yahoo Finance (or where ever you got those figures from) does not use a textbook formula, at the very least it looks to be rounding to nearest 0.5. I tried three variations, see what you think. constant ema=3D{ {"2/1/02", 3419, 3440}, {"3/1/02", 3418, 3414}, {"4/1/02", 3425.5, 3443}, {"7/1/02", 3429, 3463}, {"8/1/02", 3436, 3430}, {"9/1/02", 3431, 3420}} atom pma,csp for i =3D 2 to 6 do pma=3Dema[i-1][2] csp=3Dema[i][3] -- print ema from above table and three attempts at calculating it printf(1,"%f:%f:%f:%f\n",{ema[i][2], (1/5)*csp+(1-1/5)*pma, (2/5)*(csp-pma)+pma, (2/6)*csp+(1-2/6)*pma}) -- a failed attempt at reverse engineering the weighting: -- printf(1," %f/%f=3D%f\n",{(ema[i][2]-csp),(pma-csp), -- (ema[i][2]-csp)/(pma-csp)}) =09 end for if getc(0) then end if Pete