Moving Averages - where am I going wrong?
Posted: 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
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