Add moving average to candle stick

Discussion about JFreeChart related to stockmarket charts.
Locked
paphus
Posts: 3
Joined: Thu Jul 24, 2014 5:48 pm
antibot: No, of course not.

Add moving average to candle stick

Post by paphus » Fri Oct 31, 2014 9:25 pm

I'm trying to add a moving average to a candlestick chart. It should be simple, but doesn't seem to work.

Code: Select all

		        
JFreeChart chart = ChartFactory.createCandlestickChart(title, "date", "price", dataSet, true);
 XYPlot xyplot = (XYPlot)chart.getPlot();
xyplot.setRangeAxis(1, new NumberAxis("Value 1")); 

XYDataset xydataset = MovingAverage.createMovingAverage(dataSet, "-MA5", 50, 0);
xyplot.setDataset(1, xydataset);
xyplot.setRenderer(1, new StandardXYItemRenderer());
This draw a blue line, but it seems to be an average, not a moving average. It does not lag the candle price, but just connect the average price in each candle?

Help pls.

paphus
Posts: 3
Joined: Thu Jul 24, 2014 5:48 pm
antibot: No, of course not.

Re: Add moving average to candle stick

Post by paphus » Fri Nov 07, 2014 8:16 pm

I think I found the issue. The time period for the moving average is in milliseconds, not candles, so for 5 day it would be 1000L * 60L *60L * 24L * 5L.

Locked