Hi All,(adsbygoogle = window.adsbygoogle || []).push({});

I'm working on a little side-project (not school related) in Java for analyzing Financial Stocks (I understand the stuff I'm doing can be done online but I'm trying to learn some graphing/plotting in Java). Anyways, my question has to do with calculated EMAs (Exponential Moving Averages).

Example that demonstrates my question:

12-Day EMA:

k = (2/(12+1))

EMA(1) = k * P(13) + (1-k) * (SMA(P1...P12))

EMA(2) = k * P(14) + (1-k) * EMA(1)

...

EMA(N) = k * P(N) + (1-k) * EMA(N-1)

Where P(n) is the stock value on day n and SMA(P1...P12) is the Simple Moving Average of the first 12 elements (which is just their average). I think I'm calculating the EMA right, I'm just confused as to what to use for the first 12 values (in this case).

The issue is what values to use before EMA(1). EMA(1) takes twelve values to get the first "real" EMA value. So if I were plotting this against the stock values on a graph do I just use the SMA for the first 12 values? Do I neglect to plot the first 12 Values? I'm just having trouble figuring out how to handle the initial N-values for whatever N-Day EMA I'm calculating.

The issue seems moot at first, but if I'm calculating the difference between two EMA's (such as in an MACD calculation) the issue becomes more apparent because I have to subtract one EMA from another (both with different N-values) and I also have to plot the 9-Day EMA of the MACD and also plot the difference between those two (the Line and the Trigger line).

I suppose it's not the biggest deal because obviously you're using large sets of data (100+ data points) and focusing more on the recent data as opposed to the initial data, I just want to make sure I'm doing this right. It would also seem strange (maybe not?) to neglect these initial data points as you'd have to neglect (for a typical MACD calculation) 26+9 = 35 data points.

Can anyone shed some light? Or correct me if I'm calculating things wrong?

Thanks!

**Physics Forums | Science Articles, Homework Help, Discussion**

Join Physics Forums Today!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Quick Question about EMA Indices

**Physics Forums | Science Articles, Homework Help, Discussion**