Candlestick chart - Problem with MovingAverage

Discussion about JFreeChart related to stockmarket charts.
Locked
steschko
Posts: 1
Joined: Sun Mar 15, 2009 5:53 pm

Candlestick chart - Problem with MovingAverage

Post by steschko » Mon Mar 16, 2009 10:19 pm

Hi all,

I am writing a chart program using JFreeChart to display candlestick charts. Creating this chart was quite easy so far, but I still have a problem with the moving average. Of course there is a comfortable method MovingAverage.createMovingAverage(), but this one seems to consider non-trading days (weekend) and hence the results are improper in my opinion. For example:

A 3-day moving average for monday seems to be the same value as monday's closing price itself, because there are naturally no quotes for sunday and saturday.

Now I identified another method - createPointMovingAverage() - which could probably solve this problem. Unfortunately this methods expects a TimeSeries source object (instead of the given XYDataset). But the XYPlot object only returns a XYDataset. I can't find a way to get the data as the needed TimeSeries object. Essential code lines are the following:

Code: Select all

JFreeChart chart = ChartFactory.createCandlestickChart(getModel().getSymbol(), null, null, getModel().toOHLCDataset(), false);
XYPlot plot = (XYPlot) chart.getPlot();
long ma3 = 3 * 60*60*1000L*24; // 3 days moving average for example
XYDataset maDS = MovingAverage.createMovingAverage(plot.getDataset(), "MA3", ma3, ma3);
plot.setDataset(1, maDS);
plot.mapDatasetToRangeAxis(1, 0);
Can anyone tell me how to do this using the method createPointMovingAverage()? Thank you very much.

Locked