hi,
I want to plot stock data (Candlesticks) and superposed to that I want to display certain signals. See:
http://members.home.nl/empottasch/A.png
The signals are the blue squares. Unfortunatelly they are not exactly displayed at the point I want them to, instead they are slightly shifted to the right.
The Candlestick data en the volume data are both of the type HighLowDataset. The signals however are of the type XYDataset. Could this be the problem? And how to solve it?
thanks,
regards, Edward
problem with overlaid chart
Re: problem with overlaid chart
Hi Edward,
Look into the getXValue(...) method of whichever classes you are using to implement HighLowDataset and XYDataset. They should be returning a Number that represents milliseconds since 1 Jan 1970 (that's what the DateAxis assumes). There must be a difference between the two classes you are using (one might be returning midnight, the other midday, or something like that).
Regards,
DG.
Look into the getXValue(...) method of whichever classes you are using to implement HighLowDataset and XYDataset. They should be returning a Number that represents milliseconds since 1 Jan 1970 (that's what the DateAxis assumes). There must be a difference between the two classes you are using (one might be returning midnight, the other midday, or something like that).
Regards,
DG.
Re: problem with overlaid chart
yes, I thought it would be something like that. Still I provide the HighLowDataset with XValues of the type Date in which I create the date following (just like you do in your example):
private Date createDate(int year, int month, int day) {
GregorianCalendar calendar = new GregorianCalendar(year, month, day, 0, 0, 0);
return calendar.getTime();
}
The signals I add to the plot by creating:
// create dataset
BasicTimeSeries series1 = new BasicTimeSeries("Price", Day.class);
next I add:
series1.add(new Day(dd),data_close[indexLongPositions]);
where dd:
Date dd = this.createDate((int)data_year[indexLongPositions],
this.getMonth((int)data_month[indexLongPositions]),
(int)data_day[indexLongPositions]);
So basicly all XValues should be of the same type Date which I both create with the same method createDate ......
The getMonth() method I use is also the same for all the series of XValues.
Still I see this shift unfortunatelly. Could there be another reason?
regards, Edward
private Date createDate(int year, int month, int day) {
GregorianCalendar calendar = new GregorianCalendar(year, month, day, 0, 0, 0);
return calendar.getTime();
}
The signals I add to the plot by creating:
// create dataset
BasicTimeSeries series1 = new BasicTimeSeries("Price", Day.class);
next I add:
series1.add(new Day(dd),data_close[indexLongPositions]);
where dd:
Date dd = this.createDate((int)data_year[indexLongPositions],
this.getMonth((int)data_month[indexLongPositions]),
(int)data_day[indexLongPositions]);
So basicly all XValues should be of the same type Date which I both create with the same method createDate ......
The getMonth() method I use is also the same for all the series of XValues.
Still I see this shift unfortunatelly. Could there be another reason?
regards, Edward
Re: problem with overlaid chart
It's to do with the Day class which is used by the TimeSeries. In TimeSeriesCollection (the class that implements the XYDataset interface) you will see that the getXValue method returns the 'middle' millisecond from the Day object. To match your original Date object, you probably want the 'start' millisecond. Try changing the following line:
return new Long(dp.getPeriod().getMiddle(workingCalendar));
to:
return new Long(dp.getPeriod().getStart(workingCalendar));
Alternatively, when you populate your HighLowDataset, create the Day object first, using the constructor:
public Day(int day, int month, int year);
...then create your Date object like this:
Date dd = newDate(myDay.getMiddle());
Then they should be in synch.
Regards,
DG.
P.S. Watch out for the fact that the Day class uses 1-12 for the months, not 0-11.
return new Long(dp.getPeriod().getMiddle(workingCalendar));
to:
return new Long(dp.getPeriod().getStart(workingCalendar));
Alternatively, when you populate your HighLowDataset, create the Day object first, using the constructor:
public Day(int day, int month, int year);
...then create your Date object like this:
Date dd = newDate(myDay.getMiddle());
Then they should be in synch.
Regards,
DG.
P.S. Watch out for the fact that the Day class uses 1-12 for the months, not 0-11.