Moving Averages - where am I going wrong?

Discussion about JFreeChart related to stockmarket charts.
Locked
Sid
Posts: 1
Joined: Thu Jan 15, 2009 3:20 pm

Moving Averages - where am I going wrong?

Post by Sid » Thu Jan 15, 2009 4:00 pm

Hi - I have added a moving average to a chart with some sample ohlc data but I can't understand the MA graph. I am using:

ohlcChart = ChartFactory.createCandlestickChart(null, null, null,
ohlcData, false);
XYDataset dataset2 = MovingAverage.createMovingAverage(
ohlcData, "-MAVG", 2, 1); //2 period MA, skip first item
plot.setDataset(1, dataset2);
plot.setRenderer(1, new StandardXYItemRenderer());

My test ohlcData is:
Data Item, open, high, low, close, 2 period SMA
1, 90, 90, 90, 90,
2, 91, 91, 91, 91, 90.5
3, 93, 93, 93, 93, 92
4 , 96, 96, 96, 96, 94.5
5, 95, 95, 95, 95, 95.5
6, 96, 96, 96, 96, 95.5
7, 97, 97, 97, 97, 96.5
8, 98, 98, 98, 98, 97.5
9, 99, 99, 99, 99, 98.5
10, 100, 100, 100, 100, 99.5

The SMA lags the data when computed manually as in the table above but the chart shows the MA line passing through all the data points.

(Paste url into browser) "www.assi73.dsl.pipex.com/Index.html"

What am I missing here please?

Sid

RoyW
Posts: 93
Joined: Wed Apr 23, 2008 7:42 pm
Contact:

Post by RoyW » Fri Jan 16, 2009 3:25 pm

http://www.assi73.dsl.pipex.com/Index.html

I cannot see the image because it is still on your C: drive
<img alt="ohlcWithMA"
src="file:///C:/Documents%20and%20Settings/user/Desktop/ohlcWithMA.jpg"
style="width: 1280px; height: 1200px;">

How do you create your ohlcData dataset from your data?
What type of domain axis are you using?
The answer does not come from thinking outside the box, rather the answer comes from realizing the truth; There is no Box. my js site

Locked