How to set candle start/end
Posted: Thu Jul 24, 2014 6:00 pm
I am trying to draw a basic candle stick chart, but confused on how to set the candle duration.
It seems to guess at the candle duration, and sometimes looks good, but a lot of the time looks bad (overlaps, gaps, does not start/end at right time).
I have seen some much more complex code in other posts, and have been banging my head against the wall trying some of them, but I must be missing something, there has to be an easier way to do this nicely?
My code is below, I would expect the OHLCDataItem to have a start/end date, not just a single date, or be able to set the candle duration in seconds somewhere?
What is the date in the OHLCDataItem, the start of the candle, end, or middle?
Some more details here,
http://stackoverflow.com/questions/2493 ... jfreechart
It seems to guess at the candle duration, and sometimes looks good, but a lot of the time looks bad (overlaps, gaps, does not start/end at right time).
I have seen some much more complex code in other posts, and have been banging my head against the wall trying some of them, but I must be missing something, there has to be an easier way to do this nicely?
My code is below, I would expect the OHLCDataItem to have a start/end date, not just a single date, or be able to set the candle duration in seconds somewhere?
What is the date in the OHLCDataItem, the start of the candle, end, or middle?
Code: Select all
OHLCDataItem[] data = new OHLCDataItem[candles.size()];
int index = 0;
for (Quote quote : candles) {
Date date = quote.getDateTime();
double open = quote.getOpen();
double high = quote.getHigh();
double low = quote.getLow();
double close = quote.getClose();
double volume = quote.getVolume();
OHLCDataItem item = new OHLCDataItem(date, open, high, low, close, volume);
data[index] = item;
index++;
}
String title = "Stock";
String symbol = "stock";
OHLCDataset dataSet = new DefaultOHLCDataset(symbol, data);
JFreeChart chart = ChartFactory.createCandlestickChart(title, "date", "price", dataSet, true);
//((CandlestickRenderer)((XYPlot)chart.getPlot()).getRenderer()).setAutoWidthMethod(CandlestickRenderer.WIDTHMETHOD_INTERVALDATA);
NumberAxis numberAxis = (NumberAxis)chart.getXYPlot().getRangeAxis();
numberAxis.setAutoRangeIncludesZero(false);
numberAxis.setAutoRangeStickyZero(false);
DateAxis dateAxis = (DateAxis)chart.getXYPlot().getDomainAxis();
SegmentedTimeline timeline = SegmentedTimeline.newFifteenMinuteTimeline();
dateAxis.setTimeline(timeline);
chartPanel.setChart(chart);
http://stackoverflow.com/questions/2493 ... jfreechart