logo
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
ronanm  
#1 Posted : Wednesday, April 15, 2009 4:58:15 PM(UTC)
ronanm

Rank: Newbie

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 5

Hi - I have spent a couple of hours trying to decipher what this code means. I think the first part calculates a 13 day exponential Moving Avg, but what about the bit in the Ref brackets? Does the -1 suggest 1 day previous? Any help would be great - thanks. [:)]

"Periods :=13;
Mov(C ,Periods ,E ) - Ref(Mov(C ,Periods ,E ),-1)"

wabbit  
#2 Posted : Wednesday, April 15, 2009 5:46:11 PM(UTC)
wabbit

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)
Yes it does. It could also have been written:

ROC(Mov(C ,Periods ,E ),1,$);


It's all in the MS Users Manual.



Hope this helps.

wabbit [:D]

ronanm  
#3 Posted : Thursday, April 16, 2009 5:07:15 AM(UTC)
ronanm

Rank: Newbie

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 5

Thanks for that - much appreciated :)

I am trying to replicate the 13 day EMA calculation in Excel for Citicorp.

This is the series I am looking at:

Day Date Close my SMA DAY 13 Metastocks 1 25/04/2006 47.46 2 26/04/2006 47.75 3 27/04/2006 48.15 4 28/04/2006 49.95 5 01/05/2006 49.46 6 02/05/2006 49.6 7 03/05/2006 49.85 8 04/05/2006 49.38 9 05/05/2006 50.37 10 08/05/2006 50.16 11 09/05/2006 50.35 12 10/05/2006 50.3 13 11/05/2006 49.48 49.40 49.43

To calculate the 13 day's SMA (and start the EMA process which is no problem), I summed the first 13 days of close prices and divided by 13, getting 49.40. When I run the chart in Metastock, the first value of the EMA is 49.43 - any idea as to why there's a difference? [:O]

wabbit  
#4 Posted : Thursday, April 16, 2009 5:22:34 AM(UTC)
wabbit

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 think you have some confusion in the different types of moving average.

From the MS Help files:

An exponential (or exponentially weighted) moving average is calculated by applying a percentage of today's closing price to yesterday's moving average value.
For example, to calculate a 9% exponential moving average of IBM: First, we would take today's closing price and multiply it by 9%. We would then add this product to the value of yesterday's moving average multiplied by 91% (100% - 9% = 91%).

A simple, or arithmetic, moving average is calculated by adding the closing price of the security for a number of time periods (e.g., 12 days) and then dividing this total by the number of time periods. The result is the average price of the security over the time period. For example, to calculate a 21-day moving average of IBM: First, we would add up IBM's closing prices for the preceding 21 days. Next, we would divide that sum by 21; this would give us the average price of IBM over the preceding 21 days. We would plot this average price on the chart. The following day (tomorrow) we would do the same calculations: add up the previous 21 days' closing prices, divide by 21, and plot the resulting figure on the chart.


You can recreate a SIMPLE moving average in code, like (simplistically)

prd:=13;
data:=CLOSE;
Sum(data,prd) / prd;


You can recreate an EXPONENTIAL moving average in code, like

prd:=13;
data:=CLOSE;
n:=2/(prd+1);
If(Cum(1)=1,data,PREV*(1-n) + data*n);




Hope this helps.

wabbit [:D]


ronanm  
#5 Posted : Thursday, April 16, 2009 5:38:22 AM(UTC)
ronanm

Rank: Newbie

Groups: Registered, Registered Users
Joined: 4/15/2009(UTC)
Posts: 5

Thanks again wabbit - you're right - I am confused!

I thought for the first period's exponential moving average (day 13 in the above example), the simple moving average would be used as the previous period's exponential moving average because no EMA exists at that stage. Then, from period 14 onward, the previous period's EMA was used? I can't understand where the 49.43 is coming from

wabbit  
#6 Posted : Thursday, April 16, 2009 6:47:24 AM(UTC)
wabbit

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)
The EMA only requires two bars of data: the first bar seeds the value and the second bar uses "some" of the first bar's moving average value and the current bar's data. MS uses the "length" as the number of bars, so it doesn't return values whilst there is less than "periods" data, but it is still used in the computation (I wrote a post in the last couple of days on the topic).

The SMA uses the average of the period data, so to take a 13 period average requires 13 periods of data. It is possible to use some codes (or the forum.dll) to return an average of the data which is valid before "periods" bars of data (but that is another topic) and there is a lot of imformation on the forum on the subject.



Hope this helps.

wabbit [:D]

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.