## Moving Average algorithm, problem or not?

Discussion about JFreeChart related to stockmarket charts.
Hrom
Posts: 8
Joined: Thu Feb 19, 2009 5:44 pm

### Moving Average algorithm, problem or not?

Hi everybody!

I have the following problem with Moving Average:

I do the project for my University and use the standard function MovingAverage.createMovingAverage( tm7 , "7 day m.a." , 7, 7), but my project manager said that the standard function computed the values wrong, although he used the same formula as JFreeChart. I tried to understand why and calculated MovingAverage for some points manually. I got the following results, for example for MovingAverage for the period 17.02.09-23.02.09:

21.02.09 and 22.02.09 was a weekend and JFreeChart skip the days and use only 5 values for computation MovingAverage for 7 days:
(value(17.02.09) + value(18.02.09) + value(19.02.09)+ value(20.02.09)+ value(23.02.09))/5

the project manager whant th have:
(value(13.02.09) + value(16.02.09) + value(17.02.09) + value(18.02.09) + value(19.02.09)+ value(20.02.09)+ value(23.02.09))/7
(14.02.09 and 15.02.09 was a weekend too)

I think that JFreeChart can't compute something wrong and the computation of MA as my project manager is very complicated and has no sense. Can anyone give me the explanation, whether I am right or not?

Thank you!

david.gilbert
Posts: 11680
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

### Re: Moving Average algorithm, problem or not?

I think you can use the createPointMovingAverage() method to calculate the average the same way your project manager wants it. I don't know which is the standard way, but then technical analysis of stock prices is not really a science, so it probably doesn't matter a whole lot.
David Gilbert

Check out other products sold by my company Object Refinery Limited

Hrom
Posts: 8
Joined: Thu Feb 19, 2009 5:44 pm

### Re: Moving Average algorithm, problem or not?

Thank you for the answer! Now it is clear for me.

javageek
Posts: 11
Joined: Tue Apr 14, 2009 2:26 pm

### Re: Moving Average algorithm, problem or not?

david.gilbert wrote:I think you can use the createPointMovingAverage() method to calculate the average the same way your project manager wants it. I don't know which is the standard way, but then technical analysis of stock prices is not really a science, so it probably doesn't matter a whole lot.
Actually it could matter a lot if you are doing technical analysis. When you are looking for specific signals based on a price moving to one side or other of a moving average, and that line is off, it can cause you to loose money.

Different commercial tools calculate specific moving averages differently and it can be frustrating when attempting to duplicate charts with a different tool.

david.gilbert
Posts: 11680
Joined: Fri Mar 14, 2003 10:29 am
antibot: No, of course not.
Contact:

### Re: Moving Average algorithm, problem or not?

javageek wrote:Actually it could matter a lot if you are doing technical analysis. When you are looking for specific signals based on a price moving to one side or other of a moving average, and that line is off, it can cause you to loose money.
Some of the time, yes, and some of the time it will save you money. On average over time, it'll make no difference at all. Unless all the studies got it wrong, and technical analysis really *can* predict stock prices. I don't believe it.
javageek wrote:Different commercial tools calculate specific moving averages differently and it can be frustrating when attempting to duplicate charts with a different tool.
In that case, just treat the MovingAverage code as a code sample illustrating how you might do your own preprocessing of the data set before handing it over to the chart engine.
David Gilbert