Quinn-Curtis Forums
Quinn-Curtis Forums
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Tools for Java
 QCChart2D for Java
 Dynamic update of time and OHLC data
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ilhany

Germany
4 Posts

Posted - 01 Jan 2014 :  10:17:35  Show Profile  Reply with Quote
Hello,

based on the example code in FinCandlestickPlot.java, I try to write a chart application. I want to dynamically update the time data and OHLC Data, keeping the number of candlesticks constant.

I tried this:

		
		for(int i=0; i<nNumPnts; i++)
		{
			xValues[i].setTime(new Date(Times.get(i)));
			stockPriceData[0][i] = O.get(i); //o
			stockPriceData[1][i] = H.get(i); //h
			stockPriceData[2][i] = L.get(i); //l
			stockPriceData[3][i] = C.get(i); //c
		}
		Dataset1.setTimeXData(xValues);
		Dataset1.setGroupData(stockPriceData);
		pTransform1.autoScale(Dataset1,ChartConstants.AUTOAXES_FAR,  ChartConstants.AUTOAXES_FAR);
		xAxis1.calcAutoAxis();
		yAxis1.calcAutoAxis();
		updateDraw();
		repaint();


While the axis boundaries are calculated correctly, the chart looks very weird. I narrowed the problem to "Dataset1.setTimeXData(xValues);", if I comment this out, the chart looks ok, beside that the time axis is not correct. Please give me a hint.

Thank you,
Ilhan

quinncurtis

1585 Posts

Posted - 01 Jan 2014 :  10:23:22  Show Profile  Reply with Quote
We don't know what your chart looks like. Try and include a picture in your post. You can do that uploading it to some server (a free picture posting site will work, or your own company server) and use the Insert Image icon. If you can't do that, send us the picture in an e-mail to support@quinn-curtis.com.

Go to Top of Page

ilhany

Germany
4 Posts

Posted - 01 Jan 2014 :  12:48:26  Show Profile  Reply with Quote
Chart ok, wrong time data (setTimeXData commented out):

http://s7.directupload.net/file/d/3489/bfmzq8or_png.htm

Chart weird:

http://s1.directupload.net/file/d/3489/wahcde6i_png.htm


Edited by - ilhany on 01 Jan 2014 12:52:31
Go to Top of Page

quinncurtis

1585 Posts

Posted - 01 Jan 2014 :  14:38:34  Show Profile  Reply with Quote
It looks like your dates are invalid. Something is going wrong in the conversion you identify:

xValues[i].setTime(new Date(Times.get(i)));


break it into two steps:

Date newdate = new Date(Times.get(i));
     xValues[i].setTime(newdate);


and look at the values of newdate using the debugger. See that it is a proper date, in the current era (i.e. > 1971).

What type of object, or value, is returned by Times.get(i) ?
Go to Top of Page

ilhany

Germany
4 Posts

Posted - 01 Jan 2014 :  15:37:47  Show Profile  Reply with Quote
Times is of type LongBuffer. I made some debug strings.

SimpleDateFormat df = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss.SSS");
Date newDate = new Date(Times.get(i));
xValues[i].setTime(newDate);
...
textArea.append(df.format(xValues[i].getTime())+", o: " + sO+", h: " + sH+", l: " + sL+", c: " + sC + "\n");


result:

2007.03.30 16:00:00.000, o: 1.33757, h: 1.33757, l: 1.33757, c: 1.33757
2007.03.30 16:00:10.000, o: 1.33787, h: 1.33787, l: 1.33787, c: 1.33787
2007.03.30 16:00:20.000, o: 1.33786, h: 1.33786, l: 1.33786, c: 1.33786
2007.03.30 16:00:30.000, o: 1.33751, h: 1.33751, l: 1.33723, c: 1.33723
2007.03.30 16:00:40.000, o: 1.3372, h: 1.3372, l: 1.3372, c: 1.3372
2007.03.30 16:00:50.000, o: 1.33716, h: 1.33716, l: 1.33716, c: 1.33716
2007.03.30 16:01:10.000, o: 1.3374, h: 1.3374, l: 1.3374, c: 1.3374
2007.03.30 16:01:20.000, o: 1.3374, h: 1.3376, l: 1.3374, c: 1.3375
2007.03.30 16:01:30.000, o: 1.3375, h: 1.3375, l: 1.33715, c: 1.33725
2007.03.30 16:01:40.000, o: 1.3373, h: 1.33745, l: 1.3372, c: 1.33745
2007.03.30 16:01:50.000, o: 1.3375, h: 1.3376, l: 1.33745, c: 1.3375
2007.03.30 16:02:00.000, o: 1.3375, h: 1.3376, l: 1.33745, c: 1.3375
...


The output is what I expected because my tick data stored in a file starts at 2007.03.30, 16:00.

Edited by - ilhany on 01 Jan 2014 15:39:06
Go to Top of Page

quinncurtis

1585 Posts

Posted - 01 Jan 2014 :  16:10:40  Show Profile  Reply with Quote
The times look OK. But with a separation of 10 seconds, I would guess that you are specifying an incorrect width parameter for the CandlestickPlot, or OHLCPLot object. For data spaced 10 seconds apart you should be using a 5 second width, calculated using the ChartCalendar.getCalendarWidthValue utility method.

CandlestickPlot thePlot2 = new CandlestickPlot(pTransform1, Dataset1, ChartCalendar.getCalendarWidthValue(Calendar.SECOND,5),  defaultattrib, fillattrib);



What value or expression are you using to set the width value? If you change the data so that the data points are much closer together, you must also change the width value.

thePlot2.setBarWidth(ChartCalendar.getCalendarWidthValue(Calendar.SECOND,5));


Go to Top of Page

ilhany

Germany
4 Posts

Posted - 01 Jan 2014 :  18:38:30  Show Profile  Reply with Quote
That was the solution.

Thank you.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Quinn-Curtis Forums © 2000-2018 Quinn-Curtis, Inc. Go To Top Of Page
Powered By: Snitz Forums 2000 Version 3.4.07