OHLC dataset

Please advice how to create OHLC dataset with high, low, open and close data directly from raw data, without preparation Oracle tables.
I bought JFree Chart Developer Guide learn it and also google this question, but everywhere discussed only how to present existing static data at the candlestick chart, but nowhere says how to create this dataset from straight forwarded raw data.
I know now how to create candlestick chart, but no idea how to feed it with fresh data.
gbcbrAsked:
Who is Participating?
 
for_yanConnect With a Mentor Commented:

Sorry, I again forgot about this lable in the beginning - change it to:

DefaultHighLowDataset  dataset = new DefaultHigLowDataset("Series 1" ,finalDates, highs, lows, opens, closes);

But no - what I see above in your code is incorrect!!!
Don't change the code - leave the method exactly as I posted it (with just those corrections which I sent you - with "new" ).
Just as a whole entity - place the method inside your class alomngside with that other method where you get new values
of avg_ts, etc.

This is the method which should not be changed - all preparations - creation of myDates, myPrices - should be outside it -
it should be somewhere in your code where you obtain these new values of avg_ts - immeditately after you get new values
- no trace of any of it should be insicde
either my method or the Moment cklass. You should prepare all that outside it, you should call it with these arrays as parameters
and get nback to your code dataset and then go on and manipulate twith this dataset using JFreeChart.



0
 
CEHJCommented:
You need to create a new DefaultHighLowDataset and give it to the chart
0
 
CEHJCommented:
(Or DefaultOHLCDataset)
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
gbcbrAuthor Commented:
I understand this, but how to set interval and sort incoming data inside it to get high, low, open and close variables?
This is the main question?
In TimeSeriesCollection I say :
TimeSeries s1 = new TimeSeries("s1");
    TimeSeries s2 = new TimeSeries("s2");
    int sc = 0;

    public void doEvent_avg(double[] avg) {
        sc++;
        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(avg[0]));
        if (sc > 150) {
            s1.delete(0, 0);
        }
    }
......................
    private XYDataset createDataset() {

        TimeSeriesCollection dataset = new TimeSeriesCollection();

        dataset.addSeries(s1);

        return dataset;
    }

Open in new window

but it's plain data and line chart.
In this case needs some sorting machine which will find all these variables
0
 
gbcbrAuthor Commented:
I checked these links before. I don't understand how to connect to this code my raw data like I do it in previous sample
>> s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(avg[0]));
so, here I'm getting values of avg[0]
0
 
CEHJCommented:
You should probably already be associating price data with times in your code. This will make it much easier to transition to visualizing your data
0
 
CEHJCommented:
With what you have above, you'll need to sort the TimeSeries to get open, close, highsand lows etc.
0
 
gbcbrAuthor Commented:
This is for what I'm asking for.
I don't know but by my opinion it has to be code like this:
int interval = 10000; // milliseconds
first value of avg[0] is open;
all values during this interval comparing and last value in this interval is close;
But how to write it properly?
Very strange that for so many year using JFree Chart nobody publish this sample.
0
 
gbcbrAuthor Commented:
Generally it has to be only few lines of code.
Simple OHLCDataset sorting machine.
0
 
CEHJCommented:
It's the TimeSeries  that you should be sorting first, since it's that you're starting with is it not?
0
 
gbcbrAuthor Commented:
>>It's the TimeSeries  that you should be sorting first
But how?
0
 
CEHJCommented:
Start by getting open and close:


// (For TimeSeries 'ts')

List<TimeSeriesDataItem> items = ts.getItems();
Collections.sort(items);
// Open now at items(0) and close at items(items.getSize() - 1)

Open in new window

0
 
gbcbrAuthor Commented:
I work with this code since you post it.
Sorry, but again it's rebus for me, can your please clarify more.
0
 
for_yanCommented:
I'm perhaps missing something, but I don't understand
where is the problem.
There is a simple constructor in this DefaultHighLowDataSet which takes
arrays of times, high, low, open, close.

Why can't you feed these arrays into constructor?
Would it not show you the chart?

Maybe I don't understand what is  the raw data.


0
 
gbcbrAuthor Commented:
raw data is simple stream data.
From these data I need create OHLC dataset for some period, let's say 10 seconds which has to include high, low, open, close parameters.
So, the question is how to make OHLC dataset from arrived data in some period?
0
 
for_yanCommented:
what you mean stream data - say at each millisecond you get the price?
0
 
CEHJCommented:
This should return the data you need from the TimeSeries:
static TimeSeriesDataItem[] getOpenCloseHighLowData(TimeSeries ts) {
	TimeSeriesDataItem[] result = new TimeSeriesDataItem[4];
	List<TimeSeriesDataItem> items = new ArrayList<TimeSeriesDataItem>(ts.getItems());
	//List items = ts.getItems();
	Collections.sort(items);
	// Open now at items(0) and close at items(items.getSize() - 1)
	result[0] = items.get(0);
	result[1] = items.get(items.size() - 1);
	Collections.sort(items, new Comparator<TimeSeriesDataItem>() {
		public int compare(TimeSeriesDataItem i1, TimeSeriesDataItem i2) {
		return i1.compareTo(i2);
	    }
	});
	result[2] = items.get(0);
	result[3] = items.get(items.size() - 1);
	return result;
    }

Open in new window

0
 
gbcbrAuthor Commented:
Raw data means "as it is" without any sorting. Doesn't matter with which interval it's arrive.
But for OHLCSeriesCollection dataset we need these data to be sorted inside any settled timeframe (10 sec, 10 min, 10 hours) to be sorted and found these four parameters high, low, open and close data. And after these parameters will appear as a CandleStick chart
0
 
CEHJCommented:
Sorry - there was a copy paste error there: should have been
static TimeSeriesDataItem[] getOpenCloseHighLowData(TimeSeries ts) {
	TimeSeriesDataItem[] result = new TimeSeriesDataItem[4];
	List<TimeSeriesDataItem> items = new ArrayList<TimeSeriesDataItem>(ts.getItems());
	//List items = ts.getItems();
	Collections.sort(items);
	// Open now at items(0) and close at items(items.getSize() - 1)
	result[0] = items.get(0);
	result[1] = items.get(items.size() - 1);
	Collections.sort(items, new Comparator<TimeSeriesDataItem>() {
		public int compare(TimeSeriesDataItem i1, TimeSeriesDataItem i2) {
		    Double d1= new Double(i1.getValue().doubleValue());
		    Double d2= new Double(i2.getValue().doubleValue());
		return d1.compareTo(d2);
	    }
	});
	result[2] = items.get(0);
	result[3] = items.get(items.size() - 1);
	return result;
    }

Open in new window

0
 
CEHJCommented:
Oh  and 'getOpenCloseLowHighData' would be a better name as that's the order they come out in ;)
0
 
for_yanCommented:
You don't need them to be sorted, you just need to determine minimum, maximum, vlaues,
the vlaues at the start of the interval and at the end - it is much faster and  I don't see
any problems with those - I thought at each moment you already have data organized
from previous intervals - so you need to analyze only last interval, but even if every time
you analize all of them - just create Object with four numbers inside numbers and use HashMap for each interval number as a key
and then make arrays out of them in the end. Isn't it possible to do it this way?
I don't know perhaps I still don't undertastan where is the complexity

0
 
gbcbrAuthor Commented:
>>I still don't undertastan where is the complexity
I don't say that it's complexity - I just don't know how to do this and set my OHLC dataset properly.
0
 
gbcbrAuthor Commented:
>>CENG
        result[0] = items.get(0);
        result[1] = items.get(items.size() - 1);
        Collections.sort(items, new Comparator<TimeSeriesDataItem>() {
                public int compare(TimeSeriesDataItem i1,
                                   TimeSeriesDataItem i2) {
                    Double d1 = new Double(i1.getValue().doubleValue());
                    Double d2 = new Double(i2.getValue().doubleValue());
                    return d1.compareTo(d2);
                }
            });
        result[2] = items.get(0);
        result[3] = items.get(items.size() - 1);
This, as I understood 4 necessary parameters, but why result[2] ==result[0]
0
 
for_yanCommented:
Yes, you are right - as always, when you start thinking of it - you realize that it does require some work.
I originally thought it is some question about JFreeChart, but in fact it is not -
just an interesting task dealing with sophisticated kind of sorting.
Saw it so many times on the charts - never thought it actually needs some thinking.
Hopefully you are already on your way.
0
 
gbcbrAuthor Commented:
>>CENG
Please advice how to connect my raw data to this code and get at least terminal output.
0
 
gbcbrAuthor Commented:
Hope it can help to everybody who try to help me.
jfreechart-1.0.13-A4.pdf
0
 
gbcbrAuthor Commented:
This is my present for community.
0
 
CEHJCommented:
>>Please advice how to connect my raw data to this code and get at least terminal output.

You have at least one TimeSeries there already:

>>TimeSeries s1 = new TimeSeries("s1");

Just feed it/them to the method i gave you
0
 
CEHJCommented:
>> but why result[2] ==result[0]

That will be the case when the open value is also the lowest
0
 
for_yanCommented:


This is my grandfathers version of collecting OHLC data from the raw data on times and prices - much longer than the one shown above but
in my mind quite understandable
If we assume that we have raw data in the form of arrays of dates and prices dates[] and prices[]
and starting date (probably dates[0]) as well as interval in milliseconds for which we want to construct OHLC data,
then we can construct

 OHLCData oh = new OHLCData(dates, prices,dates[0],interval); (see class OHLCData in the code below)

and then OHLCD dataset for JFreeChart can be created using constructor

DefaultHigLowDataset(oh.getDates(), oh.getHighs(), oh.getLows(), oh.getOpens(), oh.getCloses())

This code below does compile, but requires debugging with real data.

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;

public class OHLCData {



    java.util.Date [] finalDates;
    double [] highs;
    double [] opens;
    double [] closes;
    double [] lows;



 public OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){



     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }




     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];


     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();



     }



 }


    public double [] getLows() { return lows; }
       public double [] getHighs() { return highs; }
       public double [] getCloses() { return closes; }
       public double [] getOpens() { return opens; }
    public java.util.Date [] getDates() { return finalDates; }





}

class Moment {

    long num;
    double high;
    double low;
    double open;
    double close;
    long openTime;
    long closeTime;


 public Moment(java.util.Date orig, double price) {

     this.low = price;
     this.high = price;
     this.open = price;
     this.close = price;
     this.openTime = orig.getTime();
     this.closeTime = orig.getTime();

 }

public void update(java.util.Date myDate, double price){
    if(price<low)low = price;
    if(price>high)high = price;
    if(myDate.getTime()<openTime){
        open = price;
        openTime = myDate.getTime();
    }
   if(myDate.getTime()>closeTime){
        close = price;
        closeTime = myDate.getTime();
    }




}

 public double getLow(){
         return low;
 }
 public double getHigh(){
     return high;
 }

public double getClose(){
    return close;

}

public double getOpen(){
    return open;
}
}

Open in new window

0
 
objectsCommented:
> In TimeSeriesCollection I say :

You definitely don't want to be using a TimeSeries, for_yan is on the right track.
0
 
gbcbrAuthor Commented:
>> for_yan
Thank you for the code.
I have two questions:
1. I change double[] prices to my double[] avg but I don't understand where is the method to which I have to refer to send there my avg[];
2. How to define interval;
0
 
gbcbrAuthor Commented:
Also, when I create  
private DefaultHighLowDataset createDataset() {

        DefaultHighLowDataset dataset =
            new DefaultHighLowDataset(oh.getDates(), oh.getHighs(),
                                     oh.getLows(), oh.getOpens(),
                                     oh.getCloses());
        dataset = createDataset();

        return dataset;
    }

Open in new window

I have an error:
DefaultHighLowDataset(Date[], double[], double[], double[], double[]) cannot invoke DefaultHighLowDataset(Comparable, Date[], double[], double[], double[], double[])
Means it's missed parameter Comparable key?
0
 
CEHJCommented:
The method i gave you already contains all the parameters you need to construct an OHLCDataItem, apart from the volume
0
 
for_yanCommented:
I understand that your raw data is a set of two arrays - one is the array of dates (dates of course include times)- another is array of prices, so if one array is called "dates" another one is called "avg". This array of dates and prices may include say prices at one second interval. Now you want to present your plot at say one minute range - then your interval in millisecond would become 60000.
So in order to create dataset for these conditions you would first create this OHLCData object as
new OHLCData(dates,avg,date[0],60000) and then use methods getDates(), getOpens(), etc. To retrieve all those five arrays which you'll need to construct the DefaultHighLowDataset as defined by JFreeChart
0
 
CEHJCommented:
>>You definitely don't want to be using a TimeSeries, for_yan is on the right track.

In point of fact, that code reinvents TimeSeries (which gbcbr already has in his code) in the form of 'Moment'. Why?
0
 
for_yanCommented:
That"s true I forgot about Comparable key, in that DefaultHighLowData constructor - as far a I understand this key is just identifier of your set of data to identify it among others - I thought it could be any string - don't know - maybe I'm wrong, I was concerned by creating the data part
0
 
gbcbrAuthor Commented:
>>CEHJ
>>The method i gave you already contains all the parameters you need to construct an OHLCDataItem, apart from the volume<<

Unfortunately I can't send any avg[] value into this method.

>>You have at least one TimeSeries there already:

>>>>TimeSeries s1 = new TimeSeries("s1");

>>Just feed it/them to the method i gave you

How I can send avg[] to this TimeSeries?
I tried all way which I can understand, but unsuccessfully.
0
 
for_yanCommented:

As you see  in this example they just use empty string ("")
as a first argument (Comparable key):

http://www.roseindia.net/chartgraphs/candle-stick-chart.shtml

I guess,  JFreeChart uses it as identification of the series, in case you have many
datasets in your application.
0
 
gbcbrAuthor Commented:
I make it s1, but I have now another NPE.
I little bit change your code like this:
public class ChartCommander {

    LineEURUSD lineEURUSD;
//    CandleStickEURUSD_CEHJ candleStickEURUSD;
    OHLCData oh;
    String title;
    Comparable s1;
    RegularTimePeriod period;
    java.util.Date[] dates;
//    double[] avg;
    java.util.Date startDate;
    long interval;

    double open;
    double high;
    double low;
    double close;
//  TimeSeries s1;

    private static ChartCommander instance = new ChartCommander();

    public static ChartCommander getInstance() {
        return instance;
    }

    public ChartCommander() {

//        lineEURUSD = new LineEURUSD(title);
//        candleStickEURUSD = new CandleStickEURUSD_CEHJ(key);
        oh = new OHLCData();

    }

    public void chartEURUSD(double[] avg, double[] outY) {

        System.out.println("CC avg[0]    = " + avg[0]);
        System.out.println("CC outY[0]    = " + outY[0]);

        if (avg[0] != 0) {
//            lineEURUSD.doEvent_avg(avg);
//            candleStickEURUSD.doEvent_avg(avg);
            oh.ohlcData(s1, dates, avg, startDate, interval);
        }
        if (outY[0] != 0) {

            //            lineEURUSD.doEvent_outY(outY);
        }
    }
}

Open in new window

public class OHLCData {

    java.util.Date[] finalDates;
    double[] highs;
    double[] opens;
    double[] closes;
    double[] lows;

    public void ohlcData(Comparable s1, java.util.Date[] dates, double[] avg,
                         java.util.Date startDate, long interval) {

        interval = 6000;

        System.out.println("OHLCData avg[0]    = " + avg[0]);
        System.out.println("OHLCData interval    = " + interval);

        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

        for (int j = 0; j < dates.length; j++) {
            long cur = dates[j].getTime();
            long num = ((cur - start) / interval);
            Long anchor = new Long(start + num * interval + interval / 2);
            if (h.get(anchor) == null) {
                Moment mm = new Moment(dates[j], avg[j]);
                h.put(anchor, mm);
                anchors.add(anchor);
            } else {
                Moment mm = (Moment)h.get(anchor);
                mm.update(dates[j], avg[j]);
                h.put(anchor, mm);
            }
        }

        Collections.sort(anchors);

        finalDates = new java.util.Date[anchors.size()];
        opens = new double[anchors.size()];
        highs = new double[anchors.size()];
        lows = new double[anchors.size()];
        closes = new double[anchors.size()];

        for (int j = 0; j < anchors.size(); j++) {
            Long ttime = (Long)anchors.get(j);
            Moment mm = (Moment)h.get(ttime);
            finalDates[j] = new java.util.Date(ttime.longValue());
            opens[j] = mm.getOpen();
            closes[j] = mm.getClose();
            highs[j] = mm.getHigh();
            lows[j] = mm.getLow();


        }
    }

    public double[] getLows() {
        return lows;
    }

    public double[] getHighs() {
        return highs;
    }

    public double[] getCloses() {
        return closes;
    }

    public double[] getOpens() {
        return opens;
    }

    public java.util.Date[] getDates() {
        return finalDates;
    }


    class Moment {

        long num;
        double high;
        double low;
        double open;
        double close;
        long openTime;
        long closeTime;


        public Moment(java.util.Date orig, double price) {

            this.low = price;
            this.high = price;
            this.open = price;
            this.close = price;
            this.openTime = orig.getTime();
            this.closeTime = orig.getTime();

        }

        public void update(java.util.Date myDate, double price) {
            if (price < low)
                low = price;
            if (price > high)
                high = price;
            if (myDate.getTime() < openTime) {
                open = price;
                openTime = myDate.getTime();
            }
            if (myDate.getTime() > closeTime) {
                close = price;
                closeTime = myDate.getTime();
            }
        }

        public double getLow() {
            return low;
        }

        public double getHigh() {
            return high;
        }

        public double getClose() {
            return close;

        }

        public double getOpen() {
            return open;
        }
    }
}

Open in new window

 
 
OHLCData avg[0]    = 1.4004949999999998
OHLCData interval    = 6000
07.03.2011 17:43:44 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:26) >>> long start = startDate.getTime();
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:53)

Open in new window

So, <avg[0]> and <interval> are OK, but why it's problem with <startDate>?
0
 
for_yanCommented:
But I don't see where you assign startDate before calling ohlcData method. I see you declaring it but not assigning
You can just use dates[0] as a startDate if the begiinig of your time period and the start of the stream
is the same time moment
0
 
gbcbrAuthor Commented:
startDate = dates[0];
the same error
0
 
gbcbrAuthor Commented:
even I make:
public void ohlcData(Comparable s1, java.util.Date[] dates, double[] avg,
                         java.util.Date startDate, long interval) {
 
        interval = 6000;
        System.out.println("OHLCData avg[0]    = " + avg[0]);
        System.out.println("OHLCData interval    = " + interval);
//        startDate = dates[0];
        System.out.println("OHLCData dates[0]    = " + dates[0]);
        System.out.println("OHLCData startDate    = " + startDate);

Open in new window

and I have only this output
CC avg[0]    = 1.398065
CC outY[0]    = 0.0
OHLCData avg[0]    = 1.398065
OHLCData interval    = 6000
07.03.2011 19:10:25 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:25)
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:53

Open in new window

As I understand each java.util.Date dates[0] has to show time when each next data arrive.
But I don't see where we create size of array?
0
 
for_yanCommented:
Once again we should understand what is your raw data.
My assumption that you have arry of dates and prices - someone gives you/sends you that array.
If someone sends it to you - then they should be responsible for creating array.

Otherwise you need to explain - what is your raw data?
My code starts from the point where we already have array of dates and array of prices.

0
 
CEHJCommented:
>>
How I can send avg[] to this TimeSeries?
I tried all way which I can understand, but unsuccessfully.
>>

I'm only working with what you've given, rather than imagining you've given something else. All you supplied was a TimeSeries to which you added TimeSeriesDataItem instances. You mentioned OHLC but didn't supply any of your own code showing that you have this kind of data ...
0
 
for_yanCommented:
If you are accumulating these points one by one, then what I would
suggest that you maintain two ArrayList(s) - as new point arrives you just add to the
list of dates one more Date and to the list of prices add new Double(price) object.
When at some intervals you want to show the picture,
then you copy the whole ArrayList of Dates to the array of dates, and
create new array of double of the size of number of your points  and assign
say in the for loop the doubleValue() of each Double object to
the corresponding element of the array of prices - so now you have starting arrays
which you can feed  into this void ohlcData method and then go ahead and redraw the picture.
In the meantime you continue to accumulate your data into ArrayList(s).
When next moment when you want to re-draw the picture arrives - you repeat the
same operation starting with the  ArrayList which now contains more data points.
 
0
 
gbcbrAuthor Commented:
@for_yan
I suppose that this code generate OHLCSeries only from price data and get Time data from system, this reason I didn't make array of Dates. For my analysis I don't care about real time of data, I need to compare real data with forecasted.
So, I need the loop , let's say 10 seconds which will monitor, separate and send to publish arrived data from price array and Date array has to be added from system time.
0
 
CEHJCommented:
>>
suggest that you maintain two ArrayList(s) - as new point arrives you just add to the
list of dates one more Date and to the list of prices add new Double(price) object.
>>

That's essentially a TimeSeries, consisting of a time + a value, i.e. a TimeSeriesDataItem

This is *already* being done
0
 
gbcbrAuthor Commented:
@CEHJ
Thank you for your code, but unfortunately you didn't answer to my question: How to send my avg[0] to your code. You said just common: >>Just feed it/them to the method i gave you
But you didn't say way HOW to feed.
Without this I spent two days for nothing.
I ask you many times, please if you want to help - give complete answer, if not, don't write rebuses for me.
0
 
for_yanCommented:
It certainly does not matter - with the Date it is simply more general - an you require Date objects for constructor
of DefaultHighLowDataset. What you can do - you can create the current Date object at the moment when you receive
the first point:

java.util.Date now = new java.util.Date();

then as you recieve seconds and prices your date values will be

java.util.Date current = new java.util.Date(now.getTime() + relative_time_in_sec*1000L);
and with this current values you populate your array.

You can do it in some other way, but
anyway you need to have some dates to feed into DefaultHighLowdataset


0
 
for_yanCommented:

You can start all these dates even from zero , so that you fisrt date would be new java.uti.Date(0L),
your second date (after 10 sec) will be new java.util.Date(1000L), etc.- it all should create dataset and
drwa everything = you need to be sure though that
the graph in JFreeChart will not priintout any remnants of the absolute date values
soomewhere when it uses this HighLow dataset. If it does, then it would be reasonable
to get hold of the actual date which corresponds to your zero second interval and use
it in the way I suggested to use the current date above.
0
 
CEHJCommented:
>>
@CEHJ
Thank you for your code, but unfortunately you didn't answer to my question: How to send my avg[0] to your code. You said just common: >>Just feed it/them to the method i gave you
But you didn't say way HOW to feed.
>>

 Given a TimeSeries, such as the one you're starting with, you want to extract the OHLC values from it and display them in a chart. Is that the case? If so, i'll give you a complete example?
0
 
gbcbrAuthor Commented:
I have only incoming, with irregular interval, variable avg[0] witch has data about every new rate of EURUSD.
 
if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    ChartCommander.getInstance().chartEURUSD(avg, outY);
                }

Open in new window

and this variable arrive into ChartCommander class.
From this class it has to go into another class OHLCXXXXXXX which will sort this data inside the interval 10 seconds with OHLC algorithm and do it with endless loop.
I'm not interested about real time of data, I filter it when I receive original message.
So, I'm interested only about CandleSticks builded from mine artificial avg[0] with real time axis.
I suppose it's clear.
0
 
for_yanCommented:
OK, you can for now just create array dates[] corresponding to your interval in seconds - say let's say your first point will be at
new java.util.Date(0L), then suppose your second point arrives in n milliseconds later
then your naxt element of dates [] array wiould be new java.util.Date(n) (n should be cast to long),
the next one arrives m milliseconds after the previous one or n+m millisecods from the beginning then dates[2] = new java.util.Date(n+m);
and so on.  each one should have corresponding price - thes tow arrays will be  the data which you feed in that ohlcData function.

0
 
gbcbrAuthor Commented:
@CEHJ
>> f so, i'll give you a complete example?
Please do it.

0
 
CEHJCommented:
Try the following (containing source)

http://technojeeves.com/tech/ohlc.jar

Just add it to your classpath, e.g.

java -cp %CLASSPATH%;ohlc.jar TimeSeriesChartDemo1

This takes a TimeSeries such as you have, extracting ohlc data from it and displays it
0
 
for_yanCommented:
What you mean by "your artificial avg[0]" - ?
Don't you have the time and price information?
0
 
objectsCommented:
you need to change the code you have that generates the TimeSeries to generate the appropriate data source.
Creating a TimeSeries then converting it to an OHLC dataset is messy and inefficient. Thats the last thing your code needs :)

Its a simple problem, so keep it simple :)
0
 
gbcbrAuthor Commented:
@objects
>> you need to change the code you have that generates the TimeSeries to generate the appropriate data source.
??????
0
 
for_yanCommented:
Can you just post an example of the real raw data which you are talking about  - say, attach a file with real numbers - I can debug my code with that data
and see how it works
0
 
objectsCommented:
you posted code earlier that is creating a TimeSeries. you don't need a timeseries for what you are doing.
0
 
CEHJCommented:
Sorry - forgot to put the source in that jar - it's now in it
0
 
gbcbrAuthor Commented:
@for_jan
These data are filtered and recalculated from real raw data. I call it raw data because it's just data stream selected, cleaned and prepared for work.
It's just double array data sorted by currency pairs.
You can see it above
it looks like this:
OHLCData avg[0]    = 1.39688
OHLCData avg[0]    = 1.39689
OHLCData avg[0]    = 1.396925
OHLCData avg[0]    = 1.396256
OHLCData avg[0]    = 1.396894

So, as soon new rate for this currency pair arrive, I extract two values Bid and Ask and make from them average, because this is analytical program, I don't need exact value for the deal.
And after I send this value into ChartCommander class which has to create chart from this data.
This is raw data before filtering:
MarketDataSnapshot{QuoteID='Q-EU0094524-AUDNZD-61615821',Instrument={28,AUD/NZD}, Time=22:05:00, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={28-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='28-1-0', mMDEntryPx=1.37265, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:00, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-AUDNZD-61615821'}, 28-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='28-7-0', mMDEntryPx=1.3786, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:00, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 28-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='28-8-0', mMDEntryPx=1.37075, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:00, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 28-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='28-0-0', mMDEntryPx=1.37195, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:00, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-AUDNZD-61615821'}}}
MarketDataSnapshot{QuoteID='1-c5983812-e554-c828-c185-d0c187002eb5##87EURCAD1S--9FFHjGlT2.GosDA',Instrument={15,EUR/CAD}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={15-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='15-1-0', mMDEntryPx=1.35976, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-c5983812-e554-c828-c185-d0c187002eb5##87EURCAD1S--9FFHjGlT2.GosDA'}, 15-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='15-7-0', mMDEntryPx=1.36211, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 15-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='15-0-0', mMDEntryPx=1.35817, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-c5983812-e554-c828-c185-d0c187002eb5##87EURCAD1S--9FFHjGlT2.GosDA'}, 15-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='15-8-0', mMDEntryPx=1.35768, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}}}
MarketDataSnapshot{QuoteID='1-9ff4e05d-09d9-c406-ea9c-9db3645000dc##87CADJPY1S--7qT4b7LJR.GosDA',Instrument={18,CAD/JPY}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={18-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='18-7-0', mMDEntryPx=84.695, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 18-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='18-8-0', mMDEntryPx=84.235, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 18-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='18-1-0', mMDEntryPx=84.629, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-9ff4e05d-09d9-c406-ea9c-9db3645000dc##87CADJPY1S--7qT4b7LJR.GosDA'}, 18-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='18-0-0', mMDEntryPx=84.501, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-9ff4e05d-09d9-c406-ea9c-9db3645000dc##87CADJPY1S--7qT4b7LJR.GosDA'}}}
MarketDataSnapshot{QuoteID='1-234325ca-ba3c-c854-c17f-bf71f216d5b6##87USDCAD1S--2YixMMFwF.GosDA',Instrument={7,USD/CAD}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={7-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='7-1-0', mMDEntryPx=0.97307, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-234325ca-ba3c-c854-c17f-bf71f216d5b6##87USDCAD1S--2YixMMFwF.GosDA'}, 7-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='7-0-0', mMDEntryPx=0.97232, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='1-234325ca-ba3c-c854-c17f-bf71f216d5b6##87USDCAD1S--2YixMMFwF.GosDA'}, 7-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='7-8-0', mMDEntryPx=0.97095, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 7-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='7-7-0', mMDEntryPx=0.9745, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}}}
MarketDataSnapshot{QuoteID='Q-EU0094524-CADCHF-61616011',Instrument={90,CAD/CHF}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={90-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='90-7-0', mMDEntryPx=0.95355, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 90-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='90-0-0', mMDEntryPx=0.9523, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-CADCHF-61616011'}, 90-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='90-1-0', mMDEntryPx=0.9528, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-CADCHF-61616011'}, 90-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='90-8-0', mMDEntryPx=0.9497, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}}}
MarketDataSnapshot{QuoteID='Q-EU0094524-EURCAD-61616007',Instrument={15,EUR/CAD}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={15-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='15-1-0', mMDEntryPx=1.35909, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-EURCAD-61616007'}, 15-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='15-7-0', mMDEntryPx=1.36211, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 15-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='15-0-0', mMDEntryPx=1.35858, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-EURCAD-61616007'}, 15-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='15-8-0', mMDEntryPx=1.35768, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}}}
MarketDataSnapshot{QuoteID='Q-EU0094524-AUDCAD-61616009',Instrument={16,AUD/CAD}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={16-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='16-8-0', mMDEntryPx=0.9826, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 16-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='16-1-0', mMDEntryPx=0.9845, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-AUDCAD-61616009'}, 16-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='16-0-0', mMDEntryPx=0.9841, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-AUDCAD-61616009'}, 16-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='16-7-0', mMDEntryPx=0.9866, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}}}
MarketDataSnapshot{QuoteID='Q-EU0094524-CADJPY-61616005',Instrument={18,CAD/JPY}, Time=22:05:04, Date=20110307, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={18-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='18-7-0', mMDEntryPx=84.695, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 18-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='18-8-0', mMDEntryPx=84.235, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 18-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='18-1-0', mMDEntryPx=84.585, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-CADJPY-61616005'}, 18-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='18-0-0', mMDEntryPx=84.55, mMDEntrySize=0.0, mMDEntryDate=20110307, mMDEntryTime=22:05:04, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-CADJPY-61616005'}}}

Open in new window

0
 
gbcbrAuthor Commented:
@CEHJ
Sorry, I copy it into ./src and make:
sh-3.2# java -cp ohlc.jar TimeSeriesChartDemo1
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/ui/ApplicationFrame
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Caused by: java.lang.ClassNotFoundException: org.jfree.ui.ApplicationFrame
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	... 12 more

Open in new window

Can you post it as snippet, so I'll manage it manually
0
 
gbcbrAuthor Commented:
@objects
>> you posted code earlier that is creating a TimeSeries. you don't need a timeseries for what you are doing.
I don't create special TimeSeries for OHLC, I just post what I have for line chart ID:35036093 and try to understand how I can convert it into OHLC chart.
0
 
CEHJCommented:
>>java -cp ohlc.jar TimeSeriesChartDemo1

As i said, you need to add it to your *existing* classpath (the one that contains the freechart libraries)



JFree.java.txt
0
 
CEHJCommented:
0
 
objectsCommented:
> and try to understand how I can convert it into OHLC chart.

you wouldn't. Will just result in complicating your code which is the last thing you need.
Generating the OHLC dataset directly will give you a much simpler solution.
0
 
gbcbrAuthor Commented:
@objects
>> Generating the OHLC dataset directly will give you a much simpler solution.
Mamma mia!!!
If I know how to do this directly I'll never ask this question here.
0
 
gbcbrAuthor Commented:
@CEHJ
Thank you. Everything looks very nice.
Just I still don't understand what I have to write in ChartCommander to send my avg[0] data to this code.
I see everywhere only TimeSeries but nowhere my avg[0].
0
 
CEHJCommented:
>>I see everywhere only TimeSeries but nowhere my avg[0].

You're already adding avg[0] TO your TimeSeries

>>s1.addOrUpdate(new FixedMillisecond(new Date().getTime()), new Float(avg[0]));
0
 
objectsCommented:
> If I know how to do this directly I'll never ask this question here.

understand that :)
I see for_yan is on the right track to helping you.
I have also mentioned it to our jfreechart developer and they will try and have a look when they have some time (we're a bit busy over here at the moment)

Heres a couple of examples of generating the dataset that may (or may not) help you get an idea what is required.


/**
     * Creates a sample high low dataset.
     *
     * @return a sample high low dataset.
     */
    public static HighLowDataset createHighLowDataset() {

        Date[] date = new Date[47];
        double[] high = new double[47];
        double[] low = new double[47];
        double[] open = new double[47];
        double[] close = new double[47];
        double[] volume = new double[47];

        int jan = 1;
        int feb = 2;

        date[0]  = DateUtilities.createDate(2001, jan, 4, 12, 0);
        high[0]  = 47.0;
        low[0]   = 33.0;
        open[0]  = 35.0;
        close[0] = 33.0;
        volume[0] = 100.0;

        date[1]  = DateUtilities.createDate(2001, jan, 5, 12, 0);
        high[1]  = 47.0;
        low[1]   = 32.0;
        open[1]  = 41.0;
        close[1] = 37.0;
        volume[1] = 150.0;

        date[2]  = DateUtilities.createDate(2001, jan, 6, 12, 0);
        high[2]  = 49.0;
        low[2]   = 43.0;
        open[2]  = 46.0;
        close[2] = 48.0;
        volume[2] = 70.0;

        date[3]  = DateUtilities.createDate(2001, jan, 7, 12, 0);
        high[3]  = 51.0;
        low[3]   = 39.0;
        open[3]  = 40.0;
        close[3] = 47.0;
        volume[3] = 200.0;

        date[4]  = DateUtilities.createDate(2001, jan, 8, 12, 0);
        high[4]  = 60.0;
        low[4]   = 40.0;
        open[4]  = 46.0;
        close[4] = 53.0;
        volume[4] = 120.0;

        date[5]  = DateUtilities.createDate(2001, jan, 9, 12, 0);
        high[5]  = 62.0;
        low[5]   = 55.0;
        open[5]  = 57.0;
        close[5] = 61.0;
        volume[5] = 110.0;

        date[6]  = DateUtilities.createDate(2001, jan, 10, 12, 0);
        high[6]  = 65.0;
        low[6]   = 56.0;
        open[6]  = 62.0;
        close[6] = 59.0;
        volume[6] = 70.0;

        date[7]  = DateUtilities.createDate(2001, jan, 11, 12, 0);
        high[7]  = 55.0;
        low[7]   = 43.0;
        open[7]  = 45.0;
        close[7] = 47.0;
        volume[7] = 20.0;

        date[8]  = DateUtilities.createDate(2001, jan, 12, 12, 0);
        high[8]  = 54.0;
        low[8]   = 33.0;
        open[8]  = 40.0;
        close[8] = 51.0;
        volume[8] = 30.0;

        date[9]  = DateUtilities.createDate(2001, jan, 13, 12, 0);
        high[9]  = 47.0;
        low[9]   = 33.0;
        open[9]  = 35.0;
        close[9] = 33.0;
        volume[9] = 100.0;

        date[10]  = DateUtilities.createDate(2001, jan, 14, 12, 0);
        high[10]  = 54.0;
        low[10]   = 38.0;
        open[10]  = 43.0;
        close[10] = 52.0;
        volume[10] = 50.0;

        date[11]  = DateUtilities.createDate(2001, jan, 15, 12, 0);
        high[11]  = 48.0;
        low[11]   = 41.0;
        open[11]  = 44.0;
        close[11] = 41.0;
        volume[11] = 80.0;

        date[12]  = DateUtilities.createDate(2001, jan, 17, 12, 0);
        high[12]  = 60.0;
        low[12]   = 30.0;
        open[12]  = 34.0;
        close[12] = 44.0;
        volume[12] = 90.0;

        date[13]  = DateUtilities.createDate(2001, jan, 18, 12, 0);
        high[13]  = 58.0;
        low[13]   = 44.0;
        open[13]  = 54.0;
        close[13] = 56.0;
        volume[13] = 20.0;

        date[14]  = DateUtilities.createDate(2001, jan, 19, 12, 0);
        high[14]  = 54.0;
        low[14]   = 32.0;
        open[14]  = 42.0;
        close[14] = 53.0;
        volume[14] = 70.0;

        date[15]  = DateUtilities.createDate(2001, jan, 20, 12, 0);
        high[15]  = 53.0;
        low[15]   = 39.0;
        open[15]  = 50.0;
        close[15] = 49.0;
        volume[15] = 60.0;

        date[16]  = DateUtilities.createDate(2001, jan, 21, 12, 0);
        high[16]  = 47.0;
        low[16]   = 33.0;
        open[16]  = 41.0;
        close[16] = 40.0;
        volume[16] = 30.0;

        date[17]  = DateUtilities.createDate(2001, jan, 22, 12, 0);
        high[17]  = 55.0;
        low[17]   = 37.0;
        open[17]  = 43.0;
        close[17] = 45.0;
        volume[17] = 90.0;

        date[18]  = DateUtilities.createDate(2001, jan, 23, 12, 0);
        high[18]  = 54.0;
        low[18]   = 42.0;
        open[18]  = 50.0;
        close[18] = 42.0;
        volume[18] = 150.0;

        date[19]  = DateUtilities.createDate(2001, jan, 24, 12, 0);
        high[19]  = 48.0;
        low[19]   = 37.0;
        open[19]  = 37.0;
        close[19] = 47.0;
        volume[19] = 120.0;

        date[20]  = DateUtilities.createDate(2001, jan, 25, 12, 0);
        high[20]  = 58.0;
        low[20]   = 33.0;
        open[20]  = 39.0;
        close[20] = 41.0;
        volume[20] = 80.0;

        date[21]  = DateUtilities.createDate(2001, jan, 26, 12, 0);
        high[21]  = 47.0;
        low[21]   = 31.0;
        open[21]  = 36.0;
        close[21] = 41.0;
        volume[21] = 40.0;

        date[22]  = DateUtilities.createDate(2001, jan, 27, 12, 0);
        high[22]  = 58.0;
        low[22]   = 44.0;
        open[22]  = 49.0;
        close[22] = 44.0;
        volume[22] = 20.0;

        date[23]  = DateUtilities.createDate(2001, jan, 28, 12, 0);
        high[23]  = 46.0;
        low[23]   = 41.0;
        open[23]  = 43.0;
        close[23] = 44.0;
        volume[23] = 60.0;

        date[24]  = DateUtilities.createDate(2001, jan, 29, 12, 0);
        high[24]  = 56.0;
        low[24]   = 39.0;
        open[24]  = 39.0;
        close[24] = 51.0;
        volume[24] = 40.0;

        date[25]  = DateUtilities.createDate(2001, jan, 30, 12, 0);
        high[25]  = 56.0;
        low[25]   = 39.0;
        open[25]  = 47.0;
        close[25] = 49.0;
        volume[25] = 70.0;

        date[26]  = DateUtilities.createDate(2001, jan, 31, 12, 0);
        high[26]  = 53.0;
        low[26]   = 39.0;
        open[26]  = 52.0;
        close[26] = 47.0;
        volume[26] = 60.0;

        date[27]  = DateUtilities.createDate(2001, feb, 1, 12, 0);
        high[27]  = 51.0;
        low[27]   = 30.0;
        open[27]  = 45.0;
        close[27] = 47.0;
        volume[27] = 90.0;

        date[28]  = DateUtilities.createDate(2001, feb, 2, 12, 0);
        high[28]  = 47.0;
        low[28]   = 30.0;
        open[28]  = 34.0;
        close[28] = 46.0;
        volume[28] = 100.0;

        date[29]  = DateUtilities.createDate(2001, feb, 3, 12, 0);
        high[29]  = 57.0;
        low[29]   = 37.0;
        open[29]  = 44.0;
        close[29] = 56.0;
        volume[29] = 20.0;

        date[30]  = DateUtilities.createDate(2001, feb, 4, 12, 0);
        high[30]  = 49.0;
        low[30]   = 40.0;
        open[30]  = 47.0;
        close[30] = 44.0;
        volume[30] = 50.0;

        date[31]  = DateUtilities.createDate(2001, feb, 5, 12, 0);
        high[31]  = 46.0;
        low[31]   = 38.0;
        open[31]  = 43.0;
        close[31] = 40.0;
        volume[31] = 70.0;

        date[32]  = DateUtilities.createDate(2001, feb, 6, 12, 0);
        high[32]  = 55.0;
        low[32]   = 38.0;
        open[32]  = 39.0;
        close[32] = 53.0;
        volume[32] = 120.0;

        date[33]  = DateUtilities.createDate(2001, feb, 7, 12, 0);
        high[33]  = 50.0;
        low[33]   = 33.0;
        open[33]  = 37.0;
        close[33] = 37.0;
        volume[33] = 140.0;

        date[34]  = DateUtilities.createDate(2001, feb, 8, 12, 0);
        high[34]  = 59.0;
        low[34]   = 34.0;
        open[34]  = 57.0;
        close[34] = 43.0;
        volume[34] = 70.0;

        date[35]  = DateUtilities.createDate(2001, feb, 9, 12, 0);
        high[35]  = 48.0;
        low[35]   = 39.0;
        open[35]  = 46.0;
        close[35] = 47.0;
        volume[35] = 70.0;

        date[36]  = DateUtilities.createDate(2001, feb, 10, 12, 0);
        high[36]  = 55.0;
        low[36]   = 30.0;
        open[36]  = 37.0;
        close[36] = 30.0;
        volume[36] = 30.0;

        date[37]  = DateUtilities.createDate(2001, feb, 11, 12, 0);
        high[37]  = 60.0;
        low[37]   = 32.0;
        open[37]  = 56.0;
        close[37] = 36.0;
        volume[37] = 70.0;

        date[38]  = DateUtilities.createDate(2001, feb, 12, 12, 0);
        high[38]  = 56.0;
        low[38]   = 42.0;
        open[38]  = 53.0;
        close[38] = 54.0;
        volume[38] = 40.0;

        date[39]  = DateUtilities.createDate(2001, feb, 13, 12, 0);
        high[39]  = 49.0;
        low[39]   = 42.0;
        open[39]  = 45.0;
        close[39] = 42.0;
        volume[39] = 90.0;

        date[40]  = DateUtilities.createDate(2001, feb, 14, 12, 0);
        high[40]  = 55.0;
        low[40]   = 42.0;
        open[40]  = 47.0;
        close[40] = 54.0;
        volume[40] = 70.0;

        date[41]  = DateUtilities.createDate(2001, feb, 15, 12, 0);
        high[41]  = 49.0;
        low[41]   = 35.0;
        open[41]  = 38.0;
        close[41] = 35.0;
        volume[41] = 20.0;

        date[42]  = DateUtilities.createDate(2001, feb, 16, 12, 0);
        high[42]  = 47.0;
        low[42]   = 38.0;
        open[42]  = 43.0;
        close[42] = 42.0;
        volume[42] = 10.0;

        date[43]  = DateUtilities.createDate(2001, feb, 17, 12, 0);
        high[43]  = 53.0;
        low[43]   = 42.0;
        open[43]  = 47.0;
        close[43] = 48.0;
        volume[43] = 20.0;

        date[44]  = DateUtilities.createDate(2001, feb, 18, 12, 0);
        high[44]  = 47.0;
        low[44]   = 44.0;
        open[44]  = 46.0;
        close[44] = 44.0;
        volume[44] = 30.0;

        date[45]  = DateUtilities.createDate(2001, feb, 19, 12, 0);
        high[45]  = 46.0;
        low[45]   = 40.0;
        open[45]  = 43.0;
        close[45] = 44.0;
        volume[45] = 50.0;

        date[46]  = DateUtilities.createDate(2001, feb, 20, 12, 0);
        high[46]  = 48.0;
        low[46]   = 41.0;
        open[46]  = 46.0;
        close[46] = 41.0;
        volume[46] = 100.0;

        return new DefaultHighLowDataset("Series 1", date, high, low, open, close, volume);

    }

    /**
     * Creates a sample high low dataset for a SegmentedTimeline
     *
     * @param timeline SegmenteTimeline that will use this dataset.
     * @param start Date from where the dataset will be generated. Actual dates will
     *        be generated dynamically based on the timeline.
     *
     * @return a sample high low dataset.
     */
    public static HighLowDataset createSegmentedHighLowDataset(
        SegmentedTimeline timeline, Date start) {

        // some open-high-low-close data
        double[][] data =
               {{248.1999, 249.3999, 247.0499, 247.6999},
                {247.4999, 250.6499, 246.7999, 249.3999},
                {249.5999, 249.7499, 247.4999, 248.5999},
                {248.5999, 251.5499, 248.4999, 248.6499},
                {248.8499, 249.4499, 247.8499, 248.7999},
                {249.1999, 250.5499, 248.4999, 248.7999},
                {249.2999, 251.1499, 248.9499, 249.1499},
                {248.1499, 249.8999, 247.2999, 249.0499},
                {248.5999, 248.8999, 246.2999, 246.9499},
                {247.1999, 248.3999, 246.6499, 248.3499},
                {246.0999, 246.5999, 244.4999, 244.5999},
                {243.1999, 243.3999, 240.9499, 242.3499},
                {243.5999, 243.5999, 242.2499, 242.8999},
                {242.4999, 243.1499, 241.5999, 242.8499},
                {244.1999, 247.0499, 243.7499, 246.9999},
                {246.9499, 247.6499, 245.2999, 246.0499},
                {245.5999, 248.0999, 245.1999, 247.8999},
                {247.9499, 247.9499, 243.8499, 243.9499},
                {242.1999, 245.9499, 242.1999, 244.7499},
                {244.6499, 246.5999, 244.4999, 245.5999},
                {245.4499, 249.1999, 245.0999, 249.0999},
                {249.0999, 250.2999, 248.4499, 249.2499},
                {249.4999, 249.8499, 246.7499, 246.8499},
                {246.8499, 247.6499, 245.8999, 246.8499},
                {247.6999, 250.7999, 247.6999, 250.6999},
                {250.8999, 251.4499, 249.0999, 249.4999},
                {249.6499, 252.4999, 249.5999, 251.6499},
                {251.9499, 252.2999, 249.4999, 250.0499},
                {251.2499, 251.6999, 248.7999, 248.9499},
                {249.0999, 250.2499, 247.9499, 249.7499},
                {250.0499, 251.1499, 249.4499, 249.9499},
                {250.0499, 251.1499, 249.4499, 249.9499},
                {249.9999, 250.3499, 246.5999, 246.9499},
                {247.0999, 249.6999, 246.8999, 249.2999},
                {249.8999, 252.9499, 249.8499, 252.3999},
                {252.7999, 253.3499, 251.1999, 251.6999},
                {250.4999, 251.2999, 248.9499, 249.8999},
                {250.6999, 253.4499, 250.6999, 253.1999},
                {252.9999, 253.8999, 252.2999, 253.2499},
                {253.6999, 255.1999, 253.4999, 253.9499},
                {253.4499, 254.7999, 252.7999, 254.3499},
                {253.4499, 254.5999, 252.4999, 254.2999},
                {253.5999, 253.8999, 251.6999, 251.7999},
                {252.3499, 253.6999, 251.7999, 253.5499},
                {253.5499, 254.2499, 251.1999, 251.3499},
                {251.2499, 251.9499, 249.9999, 251.5999},
                {251.9499, 252.5999, 250.2499, 251.9999},
                {251.2499, 252.7499, 251.0999, 252.1999},
                {251.6499, 252.5499, 248.8499, 248.9499},
                {249.6499, 249.8999, 248.5499, 249.0999},
                {249.3499, 250.4499, 248.9499, 250.0999},
                {249.5499, 252.1499, 249.2999, 252.0499},
                {252.1499, 252.1499, 250.2499, 250.8499},
                {251.2499, 254.9499, 250.9999, 254.4499},
                {254.0999, 255.1999, 253.4499, 254.5999},
                {254.4999, 254.9499, 252.3999, 252.8999},
                {253.2999, 253.6499, 252.1499, 252.8999},
                {253.4999, 254.1499, 251.8999, 252.0499},
                {252.3499, 254.4499, 252.3499, 254.2999},
                {254.6499, 255.7499, 251.4499, 251.6499},
                {254.6499, 255.7499, 251.4499, 251.6499},
                {252.2499, 253.1499, 251.5999, 252.9499},
                {253.4499, 253.9499, 251.0999, 251.4999},
                {251.7499, 251.8499, 249.4499, 251.0999},
                {250.8499, 251.7999, 249.9499, 251.5499},
                {251.5499, 252.1499, 250.3499, 251.5999},
                {252.9999, 254.9499, 252.7999, 254.8499},
                {254.6999, 255.4499, 253.8999, 255.3499},
                {254.9999, 256.9500, 254.9999, 256.0999},
                {256.4500, 258.2499, 255.3499, 258.1499},
                {257.4500, 258.6499, 257.2499, 257.9500},
                {257.7499, 259.1499, 257.2000, 258.7999},
                {257.8999, 258.2000, 256.7499, 257.7000},
                {257.9500, 260.2999, 257.5999, 259.9500},
                {259.2499, 260.4500, 258.8499, 259.4999},
                {259.4500, 260.2499, 259.1499, 259.5499},
                {260.0499, 260.3499, 257.4999, 257.8999},
                {257.8999, 261.9999, 257.3999, 261.8999},
                {261.8999, 262.5499, 259.8499, 261.6499},
                {261.5499, 263.3499, 261.0999, 263.0499},
                {263.1499, 264.4500, 262.3499, 263.9999},
                {264.1499, 264.2999, 261.8499, 262.7999},
                {262.6499, 263.2499, 261.5499, 262.9500},
                {263.2999, 264.9500, 262.6499, 263.9500},
                {263.5999, 264.8499, 263.4500, 264.5999},
                {264.7499, 268.0999, 264.7499, 267.2499},
                {266.3499, 267.7499, 265.7000, 266.8499},
                {267.0999, 267.6499, 266.6499, 266.8499},
                {266.6499, 267.0499, 264.7499, 265.7499},
                {265.4500, 265.7499, 264.2499, 264.8999},
                {265.3499, 266.4500, 265.2999, 265.5999},
                {263.8499, 264.0499, 262.8499, 263.9999},
                {263.9500, 264.5499, 262.9500, 264.2999},
                {264.5999, 265.5499, 262.7499, 262.7999},
                {263.3999, 263.5499, 261.3999, 261.8999},
                {262.2000, 262.2000, 260.8499, 261.7000},
                {260.2499, 263.8499, 260.0999, 263.7000},
                {263.2999, 266.0999, 263.2999, 265.8999},
                {266.2000, 266.9999, 264.8499, 266.6499}};

            int m = data.length;

            Date[] date = new Date[m];
            double[] high = new double[m];
            double[] low = new double[m];
            double[] open = new double[m];
            double[] close = new double[m];
            double[] volume = new double[m];

            SegmentedTimeline.Segment segment = timeline.getSegment(start);
            for (int i = 0; i < m; i++) {
                while (!segment.inIncludeSegments()) {
                    segment.inc();
                }
                date[i] = segment.getDate();
                open[i] = data[i][0];
                high[i] = data[i][1];
                low[i] = data[i][2];
                close[i] = data[i][3];

                segment.inc();
            }

            return new DefaultHighLowDataset("Series 1", date, high, low, open, close, volume);

    }

Open in new window

0
 
gbcbrAuthor Commented:
so I have to add to this class my doEvent method?
public void doEvent_avg(double[] avg) {
        sc++;

        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(avg[0]));

        if (sc > 100) {
            s1.delete(0, 0);
        }
    }

Open in new window

0
 
objectsCommented:
> so I have to add to this class my doEvent method?

no, you should be adding it to a new ohlc dataset, keep the TimeSeries seperate (its unrelated)
0
 
gbcbrAuthor Commented:
I'm 1000% confused.
Hundreds of live CandleStick charts work and I can't find one simple solution.
0
 
CEHJCommented:
You don't have an ohlc dataset. What you have is datapoints arriving periodically (i.e. a TimeSeries). You need to derive the ohlc info

>>so I have to add to this class my doEvent method?

There seems to be some confusion about what your doEvent method is doing. What are you intending it to do?

>>Hundreds of live CandleStick charts work and I can't find one simple solution.

You saw the candlestick chart in the app i gave you i hope?
0
 
gbcbrAuthor Commented:
>> You saw the candlestick chart in the app i gave you i hope?
I saw plenty static OHLC charts like your in Internet for last four days, but I didn't see any dynamic, what I need
>>here seems to be some confusion about what your doEvent method is doing. What are you intending it to do?
It builds for me line chart
0
 
for_yanCommented:
You showed a few of your avg data, but you should have also times (either absolute - like data and time - or relative, like say number of seconds from the start) associated with each of these avg  values - correct?
0
 
CEHJCommented:
You'll need to update the chart as regularly as you need it to be

>>It builds for me line chart

It takes a series of regular observations and builds a TimeSeries from it. When your TimeSeries is as large as you need it, you can get the ohlc data from it
0
 
gbcbrAuthor Commented:
I have starting 3 parameters:
1. absolute real time get from the System;
2. absolute duration of interval in milliseconds;
3. double avg[0] which arrive during this interval, doesn't matter in which moment inside ofvthis interval. Only important first and last in each interval.
0
 
for_yanCommented:
Can you post these three parameters table for a considerable block of time?
Say, attach file with these parameters?
0
 
gbcbrAuthor Commented:
Sorry, it should  be first parameter (RegularTimePeriod period) which define duration of these calculations.
Second is a startDate which has to be taken from system time. Generally, we can ignore it, because calculation has to start from initializing this class and go to the loop, so absolute Time doesn't need for us.
Inside of this period we are not interested about arriving time for this data avg[0], only important first and last inside of period.
So, we have only two starting parameters(RegularTimePeriod period, double[0] avg0
period we define here and avg[0] we receive from ChartCommander class.
0
 
CEHJCommented:
Your code is using FixedMillisecond
0
 
for_yanCommented:
I don't understand - what means "period we define here" -?
Yes we can define period for which we can show candles on the screen - but underlying
second we should get it from somewhere - we should have some feed of price values - do we have it coming say every
100 milliseoncds or we have them coming at random intervals - but for each price value we need associated time moment,
or say small time period - then out of this basic data - indeed the user can define if he wants to see candles by bigger intervals -
by minutes, by five mminutes
by half hour, day or week. And for each interval this code would create the OHLC dataset - but it needs to rely on some
basic information about prices at certain moments.
0
 
gbcbrAuthor Commented:
I write the answer last night, but something wrong with system last four days.
0
 
gbcbrAuthor Commented:
So, I'll repeat.
>> I don't understand - what means "period we define here" -?
Period we define in OHLC class manually, you can see in output.
Date array we don't need, because we have only ONE date, when created candle publish in the chart, so we will have this Date for whole candle.
Only data avg[0] has real array and has to be sorted inside of period. But this data come in your OHLCData class without problem.
And as soon we change period size it will nothing changed, only QTY of sorted data.
So, the question now how to sort in inside defined period
OHLCData avg[0]    = 1.398065
OHLCData interval    = 6000

Open in new window

0
 
objectsCommented:
> Date array we don't need, because we have only ONE date, when created candle publish in the chart, so we will have this Date for whole candle.

Date is actually really time, are you saying you only have data for one point in time?
ie. just one candlestick to be plotted

What you need for each point in time is: high,  low, open, close, volume
Do you have this data?
0
 
objectsCommented:
> but no idea how to feed it with fresh data.

i posted an example of how to create the dataset earlier, if any of that code is unclear then let me know
0
 
gbcbrAuthor Commented:
@objects
>> ie. just one candlestick to be plotted

of course not, but I don't think that we need Date for each data value.
I suppose it's possible organize directly in axis X, so each new published candle will have "timestamp".

>>What you need for each point in time is: high,  low, open, close, volume
Do you have this data?

This what I try to do last four days. I need this sorting machine which will sort incoming data in real time. I have two samples one from CEHJ and another one from for_yan, but no one works correct.

>>i posted an example of how to create the dataset earlier

Your sample also with STATIC dataset, but I need DYNAMIC dataset, which created inside each new interval dynamically, accordingly to arriving new data.
0
 
for_yanCommented:
I'm also wondering what means you have only one point in time. I understand that what objects posted - those are the data already prepared for creating OLHC dataset for given interval. I also believe that when the user specifies in stock-following software that they want candles for certain intervals, those are not pre-stored and loaded for aLl possible intervals - I thought waht is in fact stored is the stream of prices at each minimal moment - say at each transaction or at each tick. If that would be this way, then the code I wrote had the goal to create OHLC data for any chosen interval, starting with this full feed of prices, which I would think is called raw data. When you say you have just one time point - then I'm losing ground - probably after all I do not understand - what is the essence of this task.
If all our points are inside one interval corresponding to one candle, then we can just find the max and min values for high and low and if we do not distinguish time within that interval then any value will be good for open and close values
0
 
objectsCommented:
> of course not, but I don't think that we need Date for each data value.
> I suppose it's possible organize directly in axis X, so each new published candle will have "timestamp".

the date is the timestamp
and yes you need one for each, its needed for the x axis

> Your sample also with STATIC dataset, but I need DYNAMIC dataset, which created inside each new interval dynamically, accordingly to arriving new data.

not sure jfreechart support dynamic ohlc dataset
will see what I can find
0
 
gbcbrAuthor Commented:
@for_yan
I don't try to develop bicycle and make competition with professional builded candlestick chart from the bank.
I need my primitive candle stick chart for comparing real arrived data with data generated by my bot. At the moment I use line chart, but I don't satisfied with it. This is the reason why I try to build simple chart with two datasets, not a line chart, but candle.
The problem is for second chart, it has not date value.
But if you think that with Date array it will be easy to finish this job, I can add Date array.
if (message instanceof MarketDataSnapshot) {

            incomingQuote = (MarketDataSnapshot)message;
            symbol = incomingQuote.getInstrument().getSymbol();
            double bPx = incomingQuote.getBidOpen();
            double aPx = incomingQuote.getAskOpen();
            UTCTimestamp ts = incomingQuote.getOpenTimestamp();


            try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    avg_ts[0] = ts;
                    ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);
                }

Open in new window

0
 
objectsCommented:
theres a dataset class here that may help, lets you dynamically add data points
0
 
gbcbrAuthor Commented:
@objects
Very good sample, but I need some time to study it.
Thank you
0
 
objectsCommented:
no worries :)
0
 
CEHJCommented:
That code is essentially no different (though heavier) from what i've already demonstrated works

Are you taking observations every six seconds?
0
 
for_yanCommented:
I think you need to add Date array if you want to use the OHLC machinery from JFreeChart - as their OHLC dataset was designed with the dates (meaning of course dates-and-times) in mind. If you just want to see one candlestick just add any date - say new java.utils.Date() - and create one eleement array out of it as well as one element arrays from all open, close, etc values - it should draw one candle. And in a sense of dynamic - you can recreate your dataset at each step - whether you want it to contain one candlestiuck or many - and replace the dataset in the chart - given that your sets do not have many elements you'll probably not notice it timewise.
Maybe if you post some picture illustrating the point that you want to change the line chart into candlestick in your particular case, it will still help to understand your need
0
 
gbcbrAuthor Commented:
@CEHJ I agree that your code much lighter than this from the link.
But anyway I don't see in your code how to add my avg[0] to  TimeSeries.
Shall I use the same way like in line chart?
s1.addOrUpdate(new FixedMillisecond(new Date().getTime()), new Float(avg[0]));
0
 
CEHJCommented:
>>
Shall I use the same way like in line chart?
s1.addOrUpdate(new FixedMillisecond(new Date().getTime()), new Float(avg[0]));
>>

Yes, that IS adding to a TimeSeries
0
 
gbcbrAuthor Commented:
@CEHJ
I can't find where to add :
s1.addOrUpdate(new FixedMillisecond(new Date().getTime()), new Float(avg[0]));
Please advice
0
 
gbcbrAuthor Commented:
@for_yan
I create Data array and pass previous stack point, so now I have new stack point:
public void ohlcData(Comparable s1, java.util.Date[] avg_ts, double[] avg,
                         java.util.Date startDate, long interval) {
 
        interval = 6000;
        System.out.println("OHLCData avg[0]    = " + avg[0]);
        System.out.println("OHLCData interval    = " + interval);
        java.util.Date now = new java.util.Date();
        startDate = avg_ts[0];
        System.out.println("OHLCData dates[0]    = " + avg_ts[0]);
        System.out.println("OHLCData startDate    = " + startDate);

        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

for(int j=0; j<avg_ts.length; j++){
         long cur = avg_ts[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(avg_ts[j],avg[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(avg_ts[j], avg[j]);
             h.put(anchor,mm);
         }
}
        Collections.sort(anchors);

        finalDates = new java.util.Date[anchors.size()];
        opens = new double[anchors.size()];
        highs = new double[anchors.size()];
        lows = new double[anchors.size()];
        closes = new double[anchors.size()];

        for (int j = 0; j < anchors.size(); j++) {
            Long ttime = (Long)anchors.get(j);
            Moment mm = (Moment)h.get(ttime);
            finalDates[j] = new java.util.Date(ttime.longValue());
            opens[j] = mm.getOpen();
            closes[j] = mm.getClose();
            highs[j] = mm.getHigh();
            lows[j] = mm.getLow();


        }
    }

    public double[] getLows() {
        return lows;
    }

    public double[] getHighs() {
        return highs;
    }

    public double[] getCloses() {
        return closes;
    }

    public double[] getOpens() {
        return opens;
    }

    public java.util.Date[] getDates() {
        return finalDates;
    }

Open in new window

OHLCData avg[0]    = 1.390695
OHLCData interval    = 6000
OHLCData dates[0]    = Tue Mar 08 18:38:47 EET 2011
OHLCData startDate    = Tue Mar 08 18:38:47 EET 2011
08.03.2011 18:38:47 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:37) >> long cur = avg_ts[j].getTime();

Open in new window

Please advice.
0
 
gbcbrAuthor Commented:
@CEHJ Thank you for comment
>>Are you taking observations every six seconds?
for 10 seconds interval has to be 10000
0
 
for_yanCommented:
It looks like some elements of your array avg_ts
were not populated.

When I was writing this code I was thinking of it as aclass which will transfer your
information of the type array of dates - array of prices into OHLC data with interval as parameter.
It should work in this way - and even if your arrays contain one element, it should
work - provided that JFreeChart hanldes one-element DeafaultHiehLowDataset dataset
without problems.

And that is how I still suggest to use it.
Then we create object (see my original code) feed in array of dates and array of prices and the interval into
constructor. After that we can go to that object and
get the required four arrays which we can use in the constructor of
DraultHighLowDataset.

That is in gegneral how it should be used. And then it would be simple
to understand what is going in within this code. And all arrays which we
feed in there should have all element populated.




 
0
 
gbcbrAuthor Commented:
what you mean
>>It looks like some elements of your array avg_ts
were not populated.
I suppose that we have conflict of ordinary array avg_ts[0], which represent timestamp of EURUSD avg[0] and double array which has to be avg[0][j], so we have to convert single array into double and after get avg[0][0], avg[0][1] etc.
0
 
gbcbrAuthor Commented:
I'm already have similar situation when I prepare date for analysis.  
public void arrayConverter(double[] outX) throws Exception {

        for (int j = 29; j > 0; j--) {

            Y[0][j] = Y[0][j - 1];

        }

        Y[0][j] = outX[0];

Open in new window

Maybe we need to do something like this and convert avg[0] and avg_ts[0] which represent data from EURUSD into secondary arrays avg[0][j] and avg_ts[0][j] which will have dynamic data from this pair?
0
 
for_yanCommented:
Well, I'm not sure I understand what you mean about two-dimensional arrays.
As much as I can, in general, I try to avoid using two-dimensional arrays
and especially converting between one- and two-dimensional arrays, as
it requires too much thinking.

But yes, the arrays which you feed to ohlcData should be one dimensional and fully
populated, as it uses their length as the upper limit of the for loop.
0
 
gbcbrAuthor Commented:
1. As I know, before using any array we have to define it's size, but it's still undefined.
2. If we already have one-dimentional (single) array which represent exact data from exact currency pair, we have to convert it in two-dimentional (double) array to keep series of data from single array.
This, I repeat, I'm doing with very good result in my analytical part.
Especially for this case we will have correlated two double arrays avg[0][j] and avg_ts[0][j], so it has to solve this problem.
Please think about this.
0
 
CEHJCommented:
I'm not sure what the trouble is. Is that method

>>public void doEvent_avg(double[] avg)

getting called as you expect it to be?
0
 
gbcbrAuthor Commented:
So, I have to add this method completely?
0
 
objectsCommented:
you're overcomplicating things again :)
all you need is the 5 values (and timestamp) for each sample, and add that to your ohlc dataset. No TimeSeries required (there for drawing different graphs)
0
 
gbcbrAuthor Commented:
@CEHJ Please advice
package charts;

import org.jfree.data.time.*;
import org.jfree.data.xy.*;

import java.util.*;


public class JFree {
    public static void main(String[] args) {
        dumpTimeSeries(makeRandomTimeSeries());
    }

    TimeSeries result = new TimeSeries("s1");

    public void doEvent_avg(double[] avg) {


        result.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                           new Float(avg[0]));

    }

    static XYDataset makeDataset() {
        // Make a DefaultHighLowDataset
        final int NUM_DATA_POINTS = 20;
        Date[] dates = new Date[NUM_DATA_POINTS];
        double[] highs = new double[NUM_DATA_POINTS];
        double[] lows = new double[NUM_DATA_POINTS];
        double[] opens = new double[NUM_DATA_POINTS];
        double[] closes = new double[NUM_DATA_POINTS];
        double[] volumes = new double[NUM_DATA_POINTS];
        for (int i = 0; i < NUM_DATA_POINTS; i++) {
            TimeSeries ts = makeRandomTimeSeries();
            TimeSeriesDataItem[] tsdi = getOpenCloseLowHighData(ts);
            OHLCDataItem odi = TimeSeriesDataItemsToOHLCDataItem(tsdi);
            // Set arrays
            dates[i] = odi.getDate();
            highs[i] = odi.getHigh().doubleValue();
            lows[i] = odi.getLow().doubleValue();
            opens[i] = odi.getOpen().doubleValue();
            closes[i] = odi.getClose().doubleValue();
            volumes[i] = odi.getVolume().doubleValue();
        }
        return new DefaultHighLowDataset("A", dates, highs, lows, opens,
                                         closes, volumes);
    }

    static OHLCDataItem TimeSeriesDataItemsToOHLCDataItem(TimeSeriesDataItem[] items) {
        // items are entered in open,close,low,high order
        // Coalesce dates by averaging
        final double volume = 4;
        long sum = 0;
        for (TimeSeriesDataItem i : items) {
            sum += i.getPeriod().getLastMillisecond();
        }
        sum /= 4;
        return new OHLCDataItem(new Date(sum),
                                items[0].getValue().doubleValue(),
                                items[3].getValue().doubleValue(),
                                items[2].getValue().doubleValue(),
                                items[1].getValue().doubleValue(), volume);

    }


    static TimeSeriesDataItem[] getOpenCloseLowHighData(TimeSeries ts) {
        TimeSeriesDataItem[] result = new TimeSeriesDataItem[4];
        List<TimeSeriesDataItem> items =
            new ArrayList<TimeSeriesDataItem>(ts.getItems());
        Collections.sort(items);
        // Open now at items(0) and close at items(items.getSize() - 1)
        result[0] = items.get(0);
        result[1] = items.get(items.size() - 1);
        Collections.sort(items, new Comparator<TimeSeriesDataItem>() {
                public int compare(TimeSeriesDataItem i1,
                                   TimeSeriesDataItem i2) {
                    Double d1 = new Double(i1.getValue().doubleValue());
                    Double d2 = new Double(i2.getValue().doubleValue());

                    return d1.compareTo(d2);
                }
            });
        result[2] = items.get(0);
        result[3] = items.get(items.size() - 1);

        return result;
    }

    static TimeSeries makeRandomTimeSeries() {
        
        long now = System.currentTimeMillis();
        final int NUM_DATA_ITEMS = 20;
        for (int i = 0; i < NUM_DATA_ITEMS; i++) {
            long t = now + (long)(Math.random() * 10000);
            double v = Math.random() * 20;
            result.addOrUpdate(new FixedMillisecond(t), v);
        }

        return result;
    }

    

    static void dumpTimeSeries(TimeSeries ts) {
        List<TimeSeriesDataItem> items =
            new ArrayList<TimeSeriesDataItem>(ts.getItems());

        for (TimeSeriesDataItem i : items) {
            System.out.printf("%-15d%f\n", i.getPeriod().getLastMillisecond(),
                              i.getValue().doubleValue());
        }
    }
}

Open in new window

package charts;

import org.jfree.data.time.*;
import org.jfree.data.xy.*;

import java.util.*;


public class JFree {
    public static void main(String[] args) {
        dumpTimeSeries(makeRandomTimeSeries());
    }

    TimeSeries result = new TimeSeries("s1");

    public void doEvent_avg(double[] avg) {


        result.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                           new Float(avg[0]));

    }

    static XYDataset makeDataset() {
        // Make a DefaultHighLowDataset
        final int NUM_DATA_POINTS = 20;
        Date[] dates = new Date[NUM_DATA_POINTS];
        double[] highs = new double[NUM_DATA_POINTS];
        double[] lows = new double[NUM_DATA_POINTS];
        double[] opens = new double[NUM_DATA_POINTS];
        double[] closes = new double[NUM_DATA_POINTS];
        double[] volumes = new double[NUM_DATA_POINTS];
        for (int i = 0; i < NUM_DATA_POINTS; i++) {
            TimeSeries ts = makeRandomTimeSeries();
            TimeSeriesDataItem[] tsdi = getOpenCloseLowHighData(ts);
            OHLCDataItem odi = TimeSeriesDataItemsToOHLCDataItem(tsdi);
            // Set arrays
            dates[i] = odi.getDate();
            highs[i] = odi.getHigh().doubleValue();
            lows[i] = odi.getLow().doubleValue();
            opens[i] = odi.getOpen().doubleValue();
            closes[i] = odi.getClose().doubleValue();
            volumes[i] = odi.getVolume().doubleValue();
        }
        return new DefaultHighLowDataset("A", dates, highs, lows, opens,
                                         closes, volumes);
    }

    static OHLCDataItem TimeSeriesDataItemsToOHLCDataItem(TimeSeriesDataItem[] items) {
        // items are entered in open,close,low,high order
        // Coalesce dates by averaging
        final double volume = 4;
        long sum = 0;
        for (TimeSeriesDataItem i : items) {
            sum += i.getPeriod().getLastMillisecond();
        }
        sum /= 4;
        return new OHLCDataItem(new Date(sum),
                                items[0].getValue().doubleValue(),
                                items[3].getValue().doubleValue(),
                                items[2].getValue().doubleValue(),
                                items[1].getValue().doubleValue(), volume);

    }


    static TimeSeriesDataItem[] getOpenCloseLowHighData(TimeSeries ts) {
        TimeSeriesDataItem[] result = new TimeSeriesDataItem[4];
        List<TimeSeriesDataItem> items =
            new ArrayList<TimeSeriesDataItem>(ts.getItems());
        Collections.sort(items);
        // Open now at items(0) and close at items(items.getSize() - 1)
        result[0] = items.get(0);
        result[1] = items.get(items.size() - 1);
        Collections.sort(items, new Comparator<TimeSeriesDataItem>() {
                public int compare(TimeSeriesDataItem i1,
                                   TimeSeriesDataItem i2) {
                    Double d1 = new Double(i1.getValue().doubleValue());
                    Double d2 = new Double(i2.getValue().doubleValue());

                    return d1.compareTo(d2);
                }
            });
        result[2] = items.get(0);
        result[3] = items.get(items.size() - 1);

        return result;
    }

    static TimeSeries makeRandomTimeSeries() {
        
        long now = System.currentTimeMillis();
        final int NUM_DATA_ITEMS = 20;
        for (int i = 0; i < NUM_DATA_ITEMS; i++) {
            long t = now + (long)(Math.random() * 10000);
            double v = Math.random() * 20;
            result.addOrUpdate(new FixedMillisecond(t), v);
        }

        return result;
    }

    

    static void dumpTimeSeries(TimeSeries ts) {
        List<TimeSeriesDataItem> items =
            new ArrayList<TimeSeriesDataItem>(ts.getItems());

        for (TimeSeriesDataItem i : items) {
            System.out.printf("%-15d%f\n", i.getPeriod().getLastMillisecond(),
                              i.getValue().doubleValue());
        }
    }
}

Open in new window

0
 
CEHJCommented:
>>@CEHJ Please advice

Not sure what i'm meant to be advising on
0
 
gbcbrAuthor Commented:
@objects
My brain near to explode with this question.
Can you please advice with exact code how I can get these 5 values from my avg[0] incoming data
0
 
objectsCommented:
can't believe you thought that was less complicated :)
0
 
objectsCommented:
> My brain near to explode with this question.

Not surprised, that codes very difficult to follow.

> Can you please advice with exact code how I can get these 5 values from my avg[0] incoming data

send me some sample data, and I'll see what I can do
0
 
gbcbrAuthor Commented:
@objects
I'm already sent it few times.
But let's start from the beginning.
1. I get MarketDataSnapShot message into PMDS class;
MarketDataSnapshot{QuoteID='Q-EU0094524-EURUSD-127239364',Instrument={1,EUR/USD}, Time=21:23:08, Date=20110308, Interval=FXCMTimingInterval:Tick (0), Complete=true, MDReqID='null', TradingSessionID='FXCM', TradingSessionSubID='DBFXUSDD1', Originator='null', IsTradeable=true, ContinuousFlag=0, PriceStream=null, Entries={1-0-0=MarketDataEntry{mCurrency='null', mMDEntryType='0', mMDEntryID='1-0-0', mMDEntryPx=1.39027, mMDEntrySize=0.0, mMDEntryDate=20110308, mMDEntryTime=21:23:08, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-EURUSD-127239364'}, 1-7-0=MarketDataEntry{mCurrency='null', mMDEntryType='7', mMDEntryID='1-7-0', mMDEntryPx=1.39249, mMDEntrySize=0.0, mMDEntryDate=20110308, mMDEntryTime=21:23:08, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 1-8-0=MarketDataEntry{mCurrency='null', mMDEntryType='8', mMDEntryID='1-8-0', mMDEntryPx=1.38862, mMDEntrySize=0.0, mMDEntryDate=20110308, mMDEntryTime=21:23:08, mTradingSessionID='null', mTradingSessionSubID='null', mQuoteCondition='null', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=0, mQuoteEntryID='null'}, 1-1-0=MarketDataEntry{mCurrency='null', mMDEntryType='1', mMDEntryID='1-1-0', mMDEntryPx=1.39044, mMDEntrySize=0.0, mMDEntryDate=20110308, mMDEntryTime=21:23:08, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mQuoteCondition='A', mMDEntryOriginator='null', mExpireDate=null, mExpireTime=null, mMDQuoteType=1, mQuoteEntryID='Q-EU0094524-EURUSD-127239364'}}}

Open in new window

2. I extract 2 parameters BidPx[0] and AskPx[0] ant constrain avg[0] from them and also extract avg_ts[0] which is timestamp of this avg[0];
And send these 2 values to the class ChartCommander which has to manage all charts
if (message instanceof MarketDataSnapshot) {

            incomingQuote = (MarketDataSnapshot)message;
            symbol = incomingQuote.getInstrument().getSymbol();
            double bPx = incomingQuote.getBidOpen();
            double aPx = incomingQuote.getAskOpen();
            UTCTimestamp ts = incomingQuote.getOpenTimestamp();
            Date d = ts.toDate();

            try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    avg_ts[0] = d;
                    ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);
                }

Open in new window

As you know I have plenty datasets samples, but no one provide how to join these two variables to the OHLC machine.
All codes look perfect, but for me they are useless like Moon dust.
Nobody write: ohlc.method(double avg[0]); and up to the final realisation.
I'm full from theory.
0
 
CEHJCommented:
Here's an example showing a dynamic chart from the same basis (starting with YOUR code), updatingevery five seconds:

http://technojeeves.com/tech/dynchart.jar

Again, ADD this to your existing jfree classpath and execute
java -cp %CLASSPATH%;dynchart.jar DynamicChart

Open in new window

0
 
for_yanCommented:
All these problems because you all the time change everything,
not following recommendations. If you do it in the way below it should work:

I'm everywhere referring to your class, where these
values avg[0] and avg_ts[0] are sent ainto some method.

So in the decalration part of this class declare insrtance variables:
--------------------------
ArrayList datesArrayList;
ArrayList pricesArrayList;
long interval;
--------------------------------


In the constructor part of this class ( again the class where you receive your avg[0] and avg_ts[0], perhaps in some method below):
-------------------------------------------------------
datesArrayList = new ArrayList();
pricesArrayList = new ArrayList();
interval = 6000L;
-----------------------------------------------------------


in the method where your values avg[0], and avg_ts[0] appear/arrive,
immediately after they arrivve (using the class OHLCData in the way I wrote it):

-------------------------------------------------------------
datesArrayList.add(avg_ts[0]);
pricesArrayList.add(new Double(avg[0]));

Date[] myDates = dateArrayList.toArray();
double [] myPrices = new double[pricesArrayList.size()];
for(int j=0; j<myPrices.length; j++){
myPrices[j] = ((Double) pricesArrayList.get(j)).doubleValue();
}

l
 OHLCData oh = new OHLCData("Series 1", myDates, myPrices,myDates[0],interval);

DefaultHighLowDataset  dataset =  DefaultHigLowDataset(oh.getDates(), oh.getHighs(), oh.getLows(), oh.getOpens(), oh.getCloses());

------------------------------------------------------------------------------------------------------

So you constructed  HighLow dataset - then create graph using JFreeChart
based on this dataset and display it
 









0
 
gbcbrAuthor Commented:
@CEHJ
I have the same error like before
sh-3.2# java -cp /Users/gbcbr/jdeveloper/StopLimitTradeStationEURUSDCHF60/StopLimitTradeStation/src/ dynchart.jar DynamicChart
Exception in thread "main" java.lang.NoClassDefFoundError: dynchart/jar
Caused by: java.lang.ClassNotFoundException: dynchart.jar
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

Open in new window

0
 
objectsCommented:
> All these problems because you all the time change everything,

Thats a fair call. Get rid of all that messing with TimeSeries and follow for_yan's suggestions. They sound very sound to me.
0
 
CEHJCommented:
If the first path is your full classpath  for jfree then it should be (assuming the jar is in the current directory)
java -cp /Users/gbcbr/jdeveloper/StopLimitTradeStationEURUSDCHF60/StopLimitTradeStation/src/:dynchart.jar DynamicChart

Open in new window

0
 
for_yanCommented:
@objects,
Thanks for the support.
With a little bit of cooperation we may be able to help gbcbr a little bit shy of 1000 messages in this trail :)

0
 
objectsCommented:
> Thanks for the support.

no worries :)
0
 
gbcbrAuthor Commented:
@for_yan
So, we have a chance to get a cup
0
 
gbcbrAuthor Commented:
@CEHJ
anyway it doesn't want to install, despite of that this jar into /scr directory.
 dynchart.tiff   dynchart.tiff
sh-3.2# java -cp /Users/gbcbr/jdeveloper/StopLimitTradeStationEURUSDCHF60/StopLimitTradeStation/src/:dynchart.jar DynamicChart
Exception in thread "main" java.lang.NoClassDefFoundError: org/jfree/ui/ApplicationFrame
	at java.lang.ClassLoader.defineClass1(Native Method)
	at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632)
	at java.lang.ClassLoader.defineClass(ClassLoader.java:616)
	at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
	at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
	at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Caused by: java.lang.ClassNotFoundException: org.jfree.ui.ApplicationFrame
	at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
	... 12 more

Open in new window

0
 
CEHJCommented:
>>Again, ADD this to your existing jfree classpath

You haven't got the jfree classes in your classpath
0
 
gbcbrAuthor Commented:
@CEHJ
Please advice where is the method which I can refer with avg[0]?
public class JFree {
	private XYDataset dataset;



	public static void main(String[] args) {
		//dumpTimeSeries(makeRandomTimeSeries());
	}

	public XYDataset getDataset() {
		// Make a DefaultHighLowDataset
		final int NUM_DATA_POINTS = 20;
		Date[] dates = new Date[NUM_DATA_POINTS];
		double[] highs = new double[NUM_DATA_POINTS];
		double[] lows = new double[NUM_DATA_POINTS];
		double[] opens = new double[NUM_DATA_POINTS];
		double[] closes = new double[NUM_DATA_POINTS];
		double[] volumes = new double[NUM_DATA_POINTS];

		for (int i = 0; i < NUM_DATA_POINTS; i++) {
			TimeSeries ts = makeRandomTimeSeries();
			TimeSeriesDataItem[] tsdi = getOpenCloseLowHighData(ts);
			OHLCDataItem odi = TimeSeriesDataItemsToOHLCDataItem(tsdi);
			// Set arrays
			dates[i] = odi.getDate();
			highs[i] = odi.getHigh().doubleValue();
			lows[i] = odi.getLow().doubleValue();
			opens[i] = odi.getOpen().doubleValue();
			closes[i] = odi.getClose().doubleValue();
			volumes[i] = odi.getVolume().doubleValue();
		}

		return (this.dataset = new DefaultHighLowDataset("A", dates, highs, lows, opens, closes, volumes));
	}


	public OHLCDataItem TimeSeriesDataItemsToOHLCDataItem(
		TimeSeriesDataItem[] items) {
		// items are entered in open,close,low,high order
		// Coalesce dates by averaging
		final double volume = 4;
		long sum = 0;

		for (TimeSeriesDataItem i : items) {
			sum += i.getPeriod().getLastMillisecond();
		}

		sum /= 4;

		return new OHLCDataItem(new Date(sum),
			items[0].getValue().doubleValue(),
			items[3].getValue().doubleValue(),
			items[2].getValue().doubleValue(),
			items[1].getValue().doubleValue(), volume);
	}

	public TimeSeriesDataItem[] getOpenCloseLowHighData(TimeSeries ts) {
		TimeSeriesDataItem[] result = new TimeSeriesDataItem[4];
		List<TimeSeriesDataItem> items = new ArrayList<TimeSeriesDataItem>(ts.getItems());
		Collections.sort(items);
		// Open now at items(0) and close at items(items.getSize() - 1)
		result[0] = items.get(0);
		result[1] = items.get(items.size() - 1);
		Collections.sort(items,
			new Comparator<TimeSeriesDataItem>() {
				public int compare(TimeSeriesDataItem i1, TimeSeriesDataItem i2) {
					Double d1 = new Double(i1.getValue().doubleValue());
					Double d2 = new Double(i2.getValue().doubleValue());

					return d1.compareTo(d2);
				}
			});
		result[2] = items.get(0);
		result[3] = items.get(items.size() - 1);

		return result;
	}

	public TimeSeries makeRandomTimeSeries() {
		TimeSeries result = new TimeSeries("s1");
		long now = System.currentTimeMillis();
		final int NUM_DATA_ITEMS = 20;

		for (int i = 0; i < NUM_DATA_ITEMS; i++) {
			long t = now + (long) (Math.random() * 60000);
			double v = Math.random() * 20;
			result.addOrUpdate(new FixedMillisecond(t), v);
		}

		return result;
	}

	public void dumpTimeSeries(TimeSeries ts) {
		List<TimeSeriesDataItem> items = new ArrayList<TimeSeriesDataItem>(ts.getItems());

		for (TimeSeriesDataItem i : items) {
			System.out.printf("%-15d%f\n", i.getPeriod().getLastMillisecond(),
				i.getValue().doubleValue());
		}
	}
}

Open in new window

0
 
objectsCommented:
I thought we had stopped wasting time on theory :)
0
 
CEHJCommented:
>>Please advice where is the method which I can refer with avg[0]?

As i've mentioned numerous times, it's the TimeSeries which you start out with that provides the input to get ohlc items from. You can see that happening in the code i annotated below
public XYDataset getDataset() {
		// Make a DefaultHighLowDataset
		final int NUM_DATA_POINTS = 20;
		Date[] dates = new Date[NUM_DATA_POINTS];
		double[] highs = new double[NUM_DATA_POINTS];
		double[] lows = new double[NUM_DATA_POINTS];
		double[] opens = new double[NUM_DATA_POINTS];
		double[] closes = new double[NUM_DATA_POINTS];
		double[] volumes = new double[NUM_DATA_POINTS];

		for (int i = 0; i < NUM_DATA_POINTS; i++) {
			TimeSeries ts = makeRandomTimeSeries(); // << You already have a TimeSeries so this isn't need
			TimeSeriesDataItem[] tsdi = getOpenCloseLowHighData(ts); // << Transmuting via TimeSeriesDataItem to...
			OHLCDataItem odi = TimeSeriesDataItemsToOHLCDataItem(tsdi);//  OHLCDataItem instance, which you can use as input to a ...
			// Set arrays
			dates[i] = odi.getDate();
			highs[i] = odi.getHigh().doubleValue();
			lows[i] = odi.getLow().doubleValue();
			opens[i] = odi.getOpen().doubleValue();
			closes[i] = odi.getClose().doubleValue();
			volumes[i] = odi.getVolume().doubleValue();
		}

		return (this.dataset = new DefaultHighLowDataset("A", dates, highs, lows, opens, closes, volumes)); << ohlc dataset and chart
	}

Open in new window

0
 
gbcbrAuthor Commented:
@for_yan
strange error
public class OHLCData {

    ArrayList datesArrayList;
    ArrayList pricesArrayList;
    long interval;
    java.util.Date[] finalDates;
    double[] highs;
    double[] opens;
    double[] closes;
    double[] lows;
    java.util.Date[] avg_ts;
    java.util.Date startDate;

    public OHLCData() {
        datesArrayList = new ArrayList();
        pricesArrayList = new ArrayList();
        interval = 10000L;
    }

    public void ohlcData(Comparable s1, java.util.Date[] avg_ts, double[] avg,
                         java.util.Date startDate, long interval) {

        datesArrayList.add(avg_ts[0]);
        pricesArrayList.add(new Double(avg[0]));

        Date[] myDates = (Date[])datesArrayList.toArray();
        double[] myPrices = new double[pricesArrayList.size()];
        for (int j = 0; j < myPrices.length; j++) {
            myPrices[j] = ((Double)pricesArrayList.get(j)).doubleValue();
        }

        System.out.println("OHLCData avg[0]    = " + avg[0]);
        System.out.println("OHLCData interval    = " + interval);
        java.util.Date now = new java.util.Date();
        startDate = avg_ts[0];
        System.out.println("OHLCData dates[0]    = " + avg_ts[0]);
        System.out.println("OHLCData startDate    = " + startDate);

        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

        for (int j = 0; j < avg_ts.length; j++) {
            long cur = avg_ts[j].getTime();
            long num = ((cur - start) / interval);
            Long anchor = new Long(start + num * interval + interval / 2);
            if (h.get(anchor) == null) {
                Moment mm = new Moment(avg_ts[j], avg[j]);
                h.put(anchor, mm);
                anchors.add(anchor);
            } else {
                Moment mm = (Moment)h.get(anchor);
                mm.update(avg_ts[j], avg[j]);
                h.put(anchor, mm);
            }

Open in new window

CC avg[0]    = 1.390635
CC avg_ts[0]    = Wed Mar 09 01:24:35 EET 2011
09.03.2011 1:24:35 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.util.Date;
	at charts.OHLCData.ohlcData(OHLCData.java:33)>> Date[] myDates = (Date[])datesArrayList.toArray();

Open in new window

Please advice
0
 
gbcbrAuthor Commented:
@CEHJ
>>As i've mentioned numerous times,
And me also mentioned multy-numerous times , just show the solution, but not exercise my brain.
Show me your real advise where I can see receiving of avg[0] value in this class.
Just publish this class  with the method which will include this variable.
So, I can refer from the ChartCommander class => class.method(avg[0]);
Without this, it's wasting of yours and mine time.
0
 
for_yanCommented:
A few options:

Is your avg_ts[0] of the type java.util.Date - ?

In this
Date[] myDates = datesArrayList.toArray();
do you need to have the cast (Date[]) - ?

I am always cautious with this Date - are you sure it is java.util.Date - I sometimes
write in full - it sometimes picks up some other Date object

Please, check these things

0
 
CEHJCommented:
>>
    public void doEvent_avg(double[] avg) {
        sc++;
        s1.addOrUpdate(new FixedMillisecond(new Date().getTime()),
                       new Float(avg[0]));
        if (sc > 150) {
            s1.delete(0, 0);
        }
    }
>>

>>Show me your real advise where I can see receiving of avg[0] value in this class.

It's YOUR class that's receiving that value  in the method above. When your TimeSeries is the size you want, simply feed the TimeSeries into the code i gave you.

Did you get the dynamic chart i gave you running?

0
 
gbcbrAuthor Commented:
@CEHJ
public void doEvent_avg(double[] avg)  is the method in the another class which serving line chart.
I introduce it in your JFree class, but date don't go to anywhere, just stay inside of this method.
I can't join this data with any method of your class.
0
 
objectsCommented:
> Date[] myDates = datesArrayList.toArray();

should be:

Date[] myDates = datesArrayList.toArray(new Date[0]);

Better to declare datesArrayList as:

    List<Date> datesArrayList = new ArrayList<Date>();
0
 
objectsCommented:
> public void doEvent_avg(double[] avg)  is the method in the another class which serving line chart.

thats right, don't mix the two you'll end up with a huge mess. The TimeSeries is for a different type of chart and is not related.
You need to generate a new dataset for your new chart
0
 
gbcbrAuthor Commented:
@for_yan
it has to be java.util.Date  
java.util.Date[] avg_ts = new java.util.Date[10];
    java.util.Date[] d;

    public void parseMarketDataSnapshot(ITransportable message) 
    ......

        if (message instanceof MarketDataSnapshot) {

            incomingQuote = (MarketDataSnapshot)message;
            symbol = incomingQuote.getInstrument().getSymbol();
            double bPx = incomingQuote.getBidOpen();
            double aPx = incomingQuote.getAskOpen();
            UTCTimestamp ts = incomingQuote.getOpenTimestamp();
            Date d = ts.toDate();

            try {

                if ("EUR/USD".equalsIgnoreCase(symbol.trim())) {
                    
                    BorderControl.getInstance().borderControl(bidPx,
                                                              askPx);
                    bidPx[0] = bPx;
                    eurusd_bid = String.valueOf(bidPx[0]);
                    DCC.getInstance().setEURUSD_bid(eurusd_bid);
                    askPx[0] = aPx;
                    eurusd_ask = String.valueOf(askPx[0]);
                    DCC.getInstance().setEURUSD_ask(eurusd_ask);
                    avg[0] = (bidPx[0] + askPx[0])/2;
                    avg_ts[0] = d;
                    ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);
                }

Open in new window

The question is why it doesn't recognize it as a java.util.Date?
0
 
for_yanCommented:
Well, try to do it as objects recommended,
I usually cast it to array of Strings and there were no problems.
With other Object(s) it probably requires...
0
 
gbcbrAuthor Commented:
Surpriiise! next line error
OHLCData avg[0]    = 1.389185
OHLCData interval    = 0
OHLCData dates[0]    = Wed Mar 09 02:04:20 EET 2011
OHLCData startDate    = Wed Mar 09 02:04:20 EET 2011
09.03.2011 2:04:21 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.ArithmeticException: / by zero
	at charts.OHLCData.ohlcData(OHLCData.java:54)>>long num = ((cur - start) / interval);

Open in new window

Hope we'll finish before my sunrise
0
 
for_yanCommented:
In the worst case you can do it the same way as with Double's:

  java.uti.Date [] myDates = new java.util.Date[datesArrayList.size()];
        for (int j = 0; j < myDates.length; j++) {
            myDates[j] = (java.util.Date)datessArrayList.get(j);
        }

thsi has to work as long as these avg_ts are java.util.Date
0
 
CEHJCommented:
>>I introduce it in your JFree class,

You shouldn't be doing that. You should be calling the JFree class from YOUR class, not mixing the two
0
 
for_yanCommented:
This is because interval is either not declared as instance variable or its initialization takes
place after you use it
0
 
gbcbrAuthor Commented:
 the problem with arithmetic was here
OHLCData interval    = 0, you can't divide to zero, so I move this initialization inside.
But it still NPE at >> long cur = avg_ts[j].getTime();
OHLCData avg[0]    = 1.3891749999999998
OHLCData interval    = 10000
OHLCData dates[0]    = Wed Mar 09 02:24:55 EET 2011
OHLCData startDate    = Wed Mar 09 02:24:55 EET 2011
09.03.2011 2:24:55 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:58)

Open in new window

0
 
objectsCommented:
>       at charts.OHLCData.ohlcData(OHLCData.java:54)>>long num = ((cur - start) / interval);

you're not setting interval
0
 
gbcbrAuthor Commented:
we pass this, now another problem:
at charts.OHLCData.ohlcData(OHLCData.java:58)>>long cur = avg_ts[j].getTime();
0
 
for_yanCommented:
You should not have this avg_ts[j] at all - go back to my original code
and make it as a separate class - don't use this void method - use original class
0
 
gbcbrAuthor Commented:
your plan to make your original method as return?
0
 
for_yanCommented:
You just create the instance of the class OHLCData  as I posted it (look up in this trail and grab it fropm there).
Use the constructior with all those parameters you now have - it will calculate in constructor all necessary arrays -
and then you'll get them from the instance you created in order to construct DefaulLowHighDataset for JFreeChart.
0
 
gbcbrAuthor Commented:
original, what you post is the constructor, but not a method.
This reason I asked you from the beginning
>>I have two questions:
1. I change double[] prices to my double[] avg but I don't understand where is the method to which I have to refer to send there my avg[];
because it was no one method in this class to send there avg[0], this is the reason why I change your constructor to void method.
Now, as soon I remove void, I have the same error: Constructor declaration: Invalid method declaration, return type required.
0
 
gbcbrAuthor Commented:
@for_yan
Can you please revise your code and publish final edition?
0
 
for_yanCommented:
There is nothing to change there (at least about what I know right now - I wrote that I didn't debug it - only compiled).
You just grab it from there and place it as a separate java file among your codes -
there is one public class and one another class within the same java file.
There is nothing that I know to change now. Start running it, and maybe we'll encounter some unexpected
things. Otherwise, I don't see any need for having final edition.
If we cannot debug it in this way, I can try to do it myself - but I'll need your input values for that.
0
 
gbcbrAuthor Commented:
How I can send value to constructor? Because your original code is no a method, even not a return method
public OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){

     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }
     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];


     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();



     }

Open in new window

0
 
for_yanCommented:
You do it exactly like i showed you in a post today:

in the method where your values avg[0], and avg_ts[0] appear/arrive,
immediately after they arrivve (using the class OHLCData in the way I wrote it):

--------------------------------------------
datesArrayList.add(avg_ts[0]);
pricesArrayList.add(new Double(avg[0]));

Date[] myDates = dateArrayList.toArray();
double [] myPrices = new double[pricesArrayList.size()];
for(int j=0; j<myPrices.length; j++){
myPrices[j] = ((Double) pricesArrayList.get(j)).doubleValue();
}
---------------------------------------------------------

By now you already done what is written above.
You already have arrays myDates and myPrices filled in with data.
You also have interval, so go ahead and put next two lines (with
these lines you'll create and instance of this class, and use this instance to perform calculations
and grab results from it and construct dataset using these resulst):

----------------------------------------------------------
 OHLCData oh = new OHLCData("Series 1", myDates, myPrices,myDates[0],interval);

DefaultHighLowDataset  dataset =  DefaultHigLowDataset(oh.getDates(), oh.getHighs(), oh.getLows(), oh.getOpens(), oh.getCloses());

------------------------------------------------------------------------------------------------------
0
 
gbcbrAuthor Commented:
But I have error:
OHLCData avg[0]    = 1.3891749999999998
OHLCData interval    = 10000
OHLCData dates[0]    = Wed Mar 09 02:24:55 EET 2011
OHLCData startDate    = Wed Mar 09 02:24:55 EET 2011
09.03.2011 2:24:55 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
      at charts.OHLCData.ohlcData(OHLCData.java:58)

how I can go ahead?
0
 
for_yanCommented:
I can't see the issue easily - can you add before

OHLCData oh = new OHLCData("Series 1", myDates, myPrices,myDates[0],interval);

such loops:
System.out.println("Dates: ");
for(int j=0; j<myDates.length; j++){
System.out.println(myDates[j].toString());
}
System.out.println("Prices: ");

for(int j=0; j<myPrices.length; j++){
System.out.println(myPrices[j]);
}
System.out.println("interval: " + interval);

and paste me the output - I'll try to debug
0
 
gbcbrAuthor Commented:
@for_yan
I'm already at home, now 3:35, I'll come back tomorrow.
Have a good day.
0
 
objectsCommented:
> java.lang.NullPointerException
>      at charts.OHLCData.ohlcData(OHLCData.java:58)

that suggests something is null on line 58.
check the values at line 58 to see whats null.
then check why it is null
0
 
for_yanCommented:
Ok, then paste these results when you come - then when I come tomorrow morning - I'll try to debug it on my end.
I don't see the error easily - but with some debugging we should be able to track it down
0
 
objectsCommented:
yes, I've lost track of what code is currently being run :)
Seem to be on the right track now though, we just need to iron out remaining issues one at a time.
0
 
for_yanCommented:

If the lines were not changed, then line 58 should be here

    for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();   <----   line 58 -----------------------------------------
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();

So it looks like it retrieved null from the HashMap,
even though only those keys which have values should have been stored
in the ArrayList - so i can't see anything directly

If I have the same input arrays - I'll try to debug it
tomorrow - at least this should have some explanation


0
 
for_yanCommented:
this is the whol code again:

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;

public class OHLCData {



    java.util.Date [] finalDates;
    double [] highs;
    double [] opens;
    double [] closes;
    double [] lows;



 public OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){



     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }




     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];


     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();



     }



 }


    public double [] getLows() { return lows; }
       public double [] getHighs() { return highs; }
       public double [] getCloses() { return closes; }
       public double [] getOpens() { return opens; }
    public java.util.Date [] getDates() { return finalDates; }





}

class Moment {

    long num;
    double high;
    double low;
    double open;
    double close;
    long openTime;
    long closeTime;


 public Moment(java.util.Date orig, double price) {

     this.low = price;
     this.high = price;
     this.open = price;
     this.close = price;
     this.openTime = orig.getTime();
     this.closeTime = orig.getTime();

 }

public void update(java.util.Date myDate, double price){
    if(price<low)low = price;
    if(price>high)high = price;
    if(myDate.getTime()<openTime){
        open = price;
        openTime = myDate.getTime();
    }
   if(myDate.getTime()>closeTime){
        close = price;
        closeTime = myDate.getTime();
    }




}

 public double getLow(){
         return low;
 }
 public double getHigh(){
     return high;
 }

public double getClose(){
    return close;

}

public double getOpen(){
    return open;
}
}

Open in new window

0
 
objectsCommented:
>     for(int j=0; j<anchors.size(); j++){
>         Long ttime = (Long) anchors.get(j);

you don't actually need anchors list.
you can replace that with:

for (Long ttime : h.keySet()) {
0
 
for_yanCommented:
Yes, that's true
Maybe anchors was useful before for ordering them although it may not be necessary for dataset.
In any case there should not be null retrieved - maybe it is still different line - better to debug it not in "distributed" version
0
 
gbcbrAuthor Commented:
this line 58
>>long cur = dates[j].getTime();
0
 
objectsCommented:
the dates array being passed in appears to be null
0
 
for_yanCommented:
This is strange - why you have different line 58?
Did you use the same code?


Well, in any case, make printout which I suggested and post it - it should help with any debugging
0
 
gbcbrAuthor Commented:
This is current code:
package charts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Collections;
import java.util.Date;
import java.util.List;

public class OHLCData {

    List<Date> datesArrayList = new ArrayList<Date>();
    ArrayList pricesArrayList;
    long interval;
    java.util.Date[] finalDates;
    double[] highs;
    double[] opens;
    double[] closes;
    double[] lows;
    java.util.Date[] avg_ts;
    java.util.Date startDate;

    public OHLCData() {
        datesArrayList = new ArrayList();
        pricesArrayList = new ArrayList();
//        interval = 10000L;
    }
        
      public void ohlcData(Comparable s1, java.util.Date[] avg_ts, double[] avg,
                           java.util.Date startDate, long interval) {
        interval = 10000L;
        datesArrayList.add(avg_ts[0]);
        pricesArrayList.add(new Double(avg[0]));

        Date[] myDates = datesArrayList.toArray(new Date[0]);
        double[] myPrices = new double[pricesArrayList.size()];
        for (int j = 0; j < myPrices.length; j++) {
            myPrices[j] = ((Double)pricesArrayList.get(j)).doubleValue();
        }

//        java.util.Date[] myDates = new java.util.Date[datesArrayList.size()];
//        for (int j = 0; j < myDates.length; j++) {
//            myDates[j] = (java.util.Date)datesArrayList.get(j);
//        }

        System.out.println("OHLCData avg[0]    = " + avg[0]);
        System.out.println("OHLCData interval    = " + interval);
        java.util.Date now = new java.util.Date();
        startDate = avg_ts[0];
        System.out.println("OHLCData dates[0]    = " + avg_ts[0]);
        System.out.println("OHLCData startDate    = " + startDate);

        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

        for (int j = 0; j < avg_ts.length; j++) {
            long cur = avg_ts[j].getTime();
            long num = ((cur - start) / interval);
            Long anchor = new Long(start + num * interval + interval / 2);
            if (h.get(anchor) == null) {
                Moment mm = new Moment(avg_ts[j], avg[j]);
                h.put(anchor, mm);
                anchors.add(anchor);
            } else {
                Moment mm = (Moment)h.get(anchor);
                mm.update(avg_ts[j], avg[j]);
                h.put(anchor, mm);
            }
        }
        Collections.sort(anchors);

        finalDates = new java.util.Date[anchors.size()];
        opens = new double[anchors.size()];
        highs = new double[anchors.size()];
        lows = new double[anchors.size()];
        closes = new double[anchors.size()];

        for (int j = 0; j < anchors.size(); j++) {
            Long ttime = (Long)anchors.get(j);
            Moment mm = (Moment)h.get(ttime);
            finalDates[j] = new java.util.Date(ttime.longValue());
            opens[j] = mm.getOpen();
            closes[j] = mm.getClose();
            highs[j] = mm.getHigh();
            lows[j] = mm.getLow();
        }
    }

Open in new window

this output
client: reply = PositionReport --- begin superclass toString mAccount=00779442,mOrderID=41071217,mClOrdID=DB_U100D1_HqweyaiTphRXIW85WdKbTuSF5S3GtzghSZxr7Q2kRYIaP39vIDzLOG-223,mSecondaryClOrdID=EURUSD.AlgoTradeMarket_EURUSD.<init>(),mInstrument=TradingSecurityAdj --- begin superclass toString TradingSecurity --- begin superclass toString Instrument{mCFICode='null', mContractMultiplier=1, mFactor=1, mFXCMCondDistEntryLimit=0.0, mFXCMCondDistEntryStop=0.0, mFXCMCondDistLimit=0.0, mFXCMCondDistStop=0.0, mFXCMMaxQuantity=5.0E7, mFXCMMinQuantity=1.0, mFXCMProductID=1, mFXCMSymID=1, mFXCMSymPointSize=1.0E-4, mFXCMSymPrecision=5, mFXCMSymSortOrder=1, mFXCMTradingStatus='O', mProduct=4, mSecurityType='null', mSymbol='EUR/USD', mTouchTime=0} --- end superclass toString {mCurrency='EUR', mRoundLot=1.0, mFXCMSymInterestBuy=0.45, mFXCMSymInterestSell=-1.02, mFXCMSubscriptionStatus='T'} --- end superclass toString {mAskAdjustment=0.0, mBidAdjustment=0.0, mPriceStream=PriceStream{mName='Default', mID=1}},mParties=Parties [Party:3:D:FXCM ID(26:32;2:dbd11070132001;22:Grebnevsky;10:779442;);],mTradingSessionID=FXCM,mTradingSessionSubID=DBFXUSDD1,mTransactTime=20110302-13:18:00 --- end superclass toString {mCurrency='EUR', mFXCMPosCommission=0.0, mFXCMPosID='16704506', mFXCMPosIDRef='null', mFXCMPosInterest=-1.78, mFXCMPosOpenTime=20110302-13:18:00, mFXCMUsedMargin=100.0, mLastRptRequested=true, mListID='null', mPositionQty=Position amount (Sell) 10000.0, mPosMaintRptID='540655849', mPosReqID='DB_U100D1_Ja0vOBhmQshcRtdPifSSKJw3ZwPwqcsdvhJKd6O8f9lQYx4U6gKOYc-12', mPosReqType=PosReqType:Positions (0), mSettlPrice=1.38075, mText='null', mTotalNumPosReports=33, mUnsolicitedIndicator=false}
client: close positions = RequestForPositionsAck{mAccount='all', mFXCMErrorDetails='No close positions in response', mFXCMRequestRejectReason=2, mParties=Parties [Party:3:D:FXCM ID();], mPosReqID='DB_U100D1_Ja0vOBhmQshcRtdPifSSKJw3ZwPwqcsdvhJKd6O8f9lQYx4U6gKOYc-13', mPosReqResult=PosReqResult:No positions found that match criteria (2), mPosReqStatus=PosReqStatus:Rejected (2), mText='No trades in response', mTotalNumPosReports=0, mTradingSessionID='FXCM', mTradingSessionSubID='DBFXUSDD1', mPosMaintRptID='0', mMakingTime=1299660253159}
CC avg[0]    = 1.3867349999999998
CC avg_ts[0]    = Wed Mar 09 10:44:11 EET 2011
OHLCData avg[0]    = 1.3867349999999998
OHLCData interval    = 10000
OHLCData dates[0]    = Wed Mar 09 10:44:11 EET 2011
OHLCData startDate    = Wed Mar 09 10:44:11 EET 2011
09.03.2011 10:44:13 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:58)
	at charts.ChartCommander.chartEURUSD(ChartCommander.java:56)
	at connect.PMDS.parseMarketDataSnapshot(PMDS.java:94)
	at connect.DBFXConnect$1.messageArrived(DBFXConnect.java:133)
	at com.fxcm.internal.transport.FXCMGateway.update(FXCMGateway.java:828)
	at com.fxcm.messaging.util.fix.FIXUserSession$BackToUserQueue.run(FIXUserSession.java:675)
	at java.lang.Thread.run(Thread.java:680)
CC avg[0]    = 1.3867150000000001
CC avg_ts[0]    = Wed Mar 09 10:44:14 EET 2011
OHLCData avg[0]    = 1.3867150000000001
OHLCData interval    = 10000
OHLCData dates[0]    = Wed Mar 09 10:44:14 EET 2011
OHLCData startDate    = Wed Mar 09 10:44:14 EET 2011
09.03.2011 10:44:15 connect.PMDS parseMarketDataSnapshot
SEVERE: null
java.lang.NullPointerException
	at charts.OHLCData.ohlcData(OHLCData.java:58)

Open in new window

this is line 58
long cur = avg_ts[j].getTime();

Open in new window

0
 
for_yanCommented:
Why would not you use the class exactly as it was posted? There were no avg_ts inside it.
0
 
gbcbrAuthor Commented:
ID:35076044 Author:gbcbr Date:09/03/11 03:04 AM Your Comment
0
 
for_yanCommented:
For some reason I can't see your last comment.
Anyway, please return to the original code.
0
 
gbcbrAuthor Commented:
I did it yesterday, but I can't call this class from ChartCommender because no method inside.
0
 
for_yanCommented:
I can't understand that. Why can't you create instance with constructor and then get necessary arrays using get... methods? The way I showed you many times.
0
 
gbcbrAuthor Commented:
I ask you this from very beginning
>> for_yan
Thank you for the code.
I have two questions:
1. I change double[] prices to my double[] avg but I don't understand where is the method to which I have to refer to send there my avg[];
0
 
objectsCommented:
looks like you call it with this

            oh.ohlcData(s1, dates, avg, startDate, interval);

which gets called by:

                    ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);

But these ararays being passed look like they only have one element set. is that correct?
0
 
gbcbrAuthor Commented:
It's beyond my comprehension, it should be some method which I can call
class.method(avg[0]);
class.getInstance.method(avg[0]);
Otherwise how to send value of (avg[0]);
0
 
gbcbrAuthor Commented:
@objects

>>which gets called by:
>>ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);

But who will initialize OHLCData class? I understand this way in case if some data initialize OHLCData class and after this it request value of (avg[0]) from ChartCommander.
Please advice

>> But these ararays being passed look like they only have one element set. is that correct?

I don't understand this question, please clarify
0
 
for_yanConnect With a Mentor Commented:
Inside any executable code in Java you can instantiate any class which has publuc constructor. You do this all the time with some standard classes. Why can't you instantiate the custom class which we wrote in order to encapsulate calculations of OHLC data set. You create instance of this calss feeding some parameters into it, and then you can access this instance to retrieve the results of calculations. It is absolutely natural thing to do in Java. You can do it in any executabe code of other class, in any method. So I suggest to do it immediatley after you receieve new value onto your avg array and associated date in avg_ts array. Do it as I showed you above, return to my original code - create a Java file out of it and drop it in the same folder as all your code - don't change that file (maybe only add package at the top) and then in your main class, the one where you get these new data coming from somewhere call constructor of this class as I showed above. It is really difficult to understand what it is that you don't understand.
0
 
gbcbrAuthor Commented:
First time I have to use so sophisticated way.
OK, I'll try.
Hope, when you wake up, I'll finish:)
0
 
objectsCommented:
did you look at the code i posted earlier?
http://www.jfree.org/phpBB2/viewtopic.php?f=10&t=16791
0
 
for_yanCommented:
Look this is the simple example of class which can be used to calculate the square of a double number with exactly the same loguiic:

public class CalcSquare {

double result;

public CalcSquare(double x){

result = x*x;

}

public double getResult() {
return result;
}
}

Then in some other class you can calculate square using this class above - somewhere in the code of any suitable method you can say:

CalcSquare cs = new CalcSquare(5.0);
Double result = cs.getResult();
System.out.println("result: " + result);

This would print you 25, as 25 is a squaare of 5.0

We want to perform logically very similar operatiom, the only difference being that within the class we calculate data for several arrays and then retrieve them one by one.


0
 
for_yanCommented:
One small correction in the above post:

Should read:

double result=cs.getResul();

It starts with word "double" all in lower case

0
 
gbcbrAuthor Commented:
@objects
>>did you look at the code i posted earlier?

yes, as I told you after detailed reading this sample
>>@objects
>>My brain near to explode with this question.

I start study Java, Solaris, PL/SQL, Oracle all together in August 2010 because I don't want to be dependent from anybody. But even my brain has limit for absorbing volume of information per day.
This is overload. I need some more time and some much easy samples to adopt this code.
Especially for_yan now give another rebus with creating instances.
But I never go back and finally I'll win it.
0
 
for_yanConnect With a Mentor Commented:


Well, to avoid buring your brain, this is the same thing wrapped in a method
which returns DeafaultHighLowDataset; you can add this method to
your class - please, don't make arbitrary changes in it though.
And you can feed the arrays we prepared before to this method.

You'll still have to grab the code from the secomd snippet on this posting,
put it into file named Moment.java (maybe add your package at the top) and drop it into the same place with
the rest of your code.


public DefaultHighLowDataset  OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){
 
 
  java.util.Date [] finalDates;
     double [] highs;
     double [] opens;
     double [] closes;
    double [] lows;



     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }




     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];


     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();



     }







DefaultHighLowDataset  dataset =  DefaultHigLowDataset(finalDates, highs, lows, opens, closes);

return dataset;
}

Open in new window




public class Moment {

    long num;
    double high;
    double low;
    double open;
    double close;
    long openTime;
    long closeTime;


 public Moment(java.util.Date orig, double price) {

     this.low = price;
     this.high = price;
     this.open = price;
     this.close = price;
     this.openTime = orig.getTime();
     this.closeTime = orig.getTime();

 }

public void update(java.util.Date myDate, double price){
    if(price<low)low = price;
    if(price>high)high = price;
    if(myDate.getTime()<openTime){
        open = price;
        openTime = myDate.getTime();
    }
   if(myDate.getTime()>closeTime){
        close = price;
        closeTime = myDate.getTime();
    }




}

 public double getLow(){
         return low;
 }
 public double getHigh(){
     return high;
 }

public double getClose(){
    return close;

}

public double getOpen(){
    return open;
}
}

Open in new window

0
 
gbcbrAuthor Commented:
@for_yan
I just come back to my office and start to study your instruction how to call classes, so give my 15 minutes for study it and also your new code.

>>don't make arbitrary changes in it though.
If your answer to my question
>>1. I change double[] prices to my double[] avg but I don't understand where is the method to which I have to refer to send there my avg[];
I never make any changes, but because you didn't reply I suppose that it's mistyping.
0
 
for_yanCommented:
OK, don't rush - i'm anyway in the morning hours of preparing to go to work, - I'll be more avaialble in about 2 hours,
so take your time - and don't make arbitrary changes - rather ask questions before you want to change  
0
 
for_yanConnect With a Mentor Commented:
If it does not work - for the beginning probably it would not - it is still
good idea to make System.out.println loops after you create input arrays
and just before you call this method - which
should return DefaultHighLowDataset to you:



System.out.println("Dates: ");
for(int j=0; j<myDates.length; j++){
System.out.println(myDates[j].toString());
}
System.out.println("Prices: ");

for(int j=0; j<myPrices.length; j++){
System.out.println(myPrices[j]);
}
System.out.println("interval: " + interval);

and then post the printout of this.


0
 
gbcbrAuthor Commented:
shall I change double[] prices to double avg[0] ?
0
 
for_yanConnect With a Mentor Commented:

No you shall not. By now you already
created arrays - myPrices and myDates - use them as input to this method which returns DefaultHighLowDataset
object to you. Something like that:

datesArrayList.add(avg_ts[0]);
pricesArrayList.add(new Double(avg[0]));

Date[] myDates = dateArrayList.toArray();
double [] myPrices = new double[pricesArrayList.size()];
for(int j=0; j<myPrices.length; j++){
myPrices[j] = ((Double) pricesArrayList.get(j)).doubleValue();
}

// or however you got to this place where you have both arrays prepared
//---------------------------------------------------------

//By now you already done what is written above.
//You already have arrays myDates and myPrices filled in with data.
//You also have interval, so go ahead and put next two lines (with
//these lines you'll create and instance of this class, and use this instance to perform calculations
//and grab results from it and construct dataset using these resulst):

//----------------------------------------------------------
  

DefaultHighLowDataset  dataset =  OHLCData("Series 1", myDates, myPrices,myDates[0],interval); 

Open in new window

0
 
gbcbrAuthor Commented:
DefaultHighLowDataset dataset =
            DefaultHighLowDataset(finalDates, highs, lows, opens, closes);

Open in new window

Error: Create method  DefaultHighLowDataset(finalDates, highs, lows, opens, closes);
0
 
gbcbrAuthor Commented:
Date[] myDates = datesArrayList.toArray();

Open in new window

Error: Cannot assign value of type java.lang.Object[] to variable of type java.util.Date
0
 
for_yanCommented:


Replace the following line:
----
Date[] myDates = dateArrayList.toArray();
---

with this code:
-------
 java.uti.Date [] myDates = new java.util.Date[datesArrayList.size()];
        for (int j = 0; j < myDates.length; j++) {
            myDates[j] = (java.util.Date)datesArrayList.get(j);
        }
----------------------
0
 
for_yanCommented:
replace line:

--------------------
DefaultHighLowDataset  dataset =  DefaultHigLowDataset(finalDates, highs, lows, opens, closes);
--------------------------

with line:
----------------------------
DefaultHighLowDataset  dataset = new DefaultHigLowDataset(finalDates, highs, lows, opens, closes);
------------------------------------

That was my mistake.
0
 
gbcbrAuthor Commented:
DefaultHighLowDataset  dataset = new DefaultHigLowDataset(finalDates, highs, lows, opens, closes);
this demands: DefaultHighLowDataset(Date[], double[], double[], double[], double[] ) cannot invoke DefaultHighLowDataset();
Maybe we need to change constructor.
Anyway look at final code:
package charts;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Date;
import java.util.List;

import java.util.Collections;

public class DefaultHighLowDataset {

    List<Date> datesArrayList = new ArrayList<Date>();
    ArrayList pricesArrayList;
    long interval;
    java.util.Date[] finalDates;
    double[] highs;
    double[] opens;
    double[] closes;
    double[] lows;
    double[] avg = new double[10];
    java.util.Date[] avg_ts;
    java.util.Date startDate;


    public DefaultHighLowDataset() {
        datesArrayList = new ArrayList();
        pricesArrayList = new ArrayList();
        interval = 10000L;
    }

    public DefaultHighLowDataset OHLCData(java.util.Date[] dates,
                                          double[] prices,
                                          java.util.Date startDate,
                                          long interval) {

        java.util.Date[] finalDates;
        double[] highs;
        double[] opens;
        double[] closes;
        double[] lows;

        datesArrayList.add(avg_ts[0]);
        pricesArrayList.add(new Double(avg[0]));
        java.util.Date[] myDates = new java.util.Date[datesArrayList.size()];
        for (int j = 0; j < myDates.length; j++) {
            myDates[j] = (java.util.Date)datesArrayList.get(j);
        }
        double[] myPrices = new double[pricesArrayList.size()];
        for (int j = 0; j < myPrices.length; j++) {
            myPrices[j] = ((Double)pricesArrayList.get(j)).doubleValue();
        }

        System.out.println("Dates: ");
        for (int j = 0; j < myDates.length; j++) {
            System.out.println(myDates[j].toString());
        }
        System.out.println("Prices: ");

        for (int j = 0; j < myPrices.length; j++) {
            System.out.println(myPrices[j]);
        }
        System.out.println("interval: " + interval);


        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

        for (int j = 0; j < dates.length; j++) {
            long cur = dates[j].getTime();
            long num = ((cur - start) / interval);
            Long anchor = new Long(start + num * interval + interval / 2);
            if (h.get(anchor) == null) {
                Moment mm = new Moment(dates[j], prices[j]);
                h.put(anchor, mm);
                anchors.add(anchor);
            } else {
                Moment mm = (Moment)h.get(anchor);
                mm.update(dates[j], prices[j]);
                h.put(anchor, mm);
            }

        }

        Collections.sort(anchors);

        finalDates = new java.util.Date[anchors.size()];
        opens = new double[anchors.size()];
        highs = new double[anchors.size()];
        lows = new double[anchors.size()];
        closes = new double[anchors.size()];

        for (int j = 0; j < anchors.size(); j++) {
            Long ttime = (Long)anchors.get(j);
            Moment mm = (Moment)h.get(ttime);
            finalDates[j] = new java.util.Date(ttime.longValue());
            opens[j] = mm.getOpen();
            closes[j] = mm.getClose();
            highs[j] = mm.getHigh();
            lows[j] = mm.getLow();

        }

        DefaultHighLowDataset dataset =
           new DefaultHighLowDataset(finalDates, highs, lows, opens, closes);

        return dataset;
    }
}

Open in new window

0
 
for_yanConnect With a Mentor Commented:
This is the advantage of Java - I give you selfsufficient pieces - don't change  them.
The only changes we can introduce is the result of our debugging - yes I forgiot "new", forgot that
this constructor needs the String in the beginning - these wrere my mistakes - thwey need to be corrected.
Otherwise - don't cvhange anything - Granb the code below - place it as a whole into the same class
where you obtain these avg_ts, and avg values as a parllel method to your other methods there -
don't change a single character there without severe reason which may come only out of our debugging.

then immediately after you get new values of avg and avg_ts - in your code in some other method - do all this stuf to prepare arrays.
Then call this method, feed arrays which you prepared as parameters,  with the return value of the type DeafultHighLowDataset - get this value
and further manipulate with it using JFreeChart facilities, the same way you manipulated with other JFreeChart datasets.

public DefaultHighLowDataset  OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){
 
 
  java.util.Date [] finalDates;
     double [] highs;
     double [] opens;
     double [] closes;
    double [] lows;



     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }




     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];


     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();



     }







DefaultHighLowDataset  dataset =  new DefaultHigLowDataset("Series 1", finalDates, highs, lows, opens, closes);

return dataset;
}

Open in new window


 
0
 
gbcbrAuthor Commented:
So, I have to move them into ChartCommander class method chartEURUSD and invoke this method from DefaultHighLowDataset.
I understand correct?
0
 
for_yanConnect With a Mentor Commented:
yes, first part is yes, you paste this code as it is into ChartCommander class - make sure
this code is sittying right inside the class itself - not in any method - but as a separate method inside the class.

then identify the place where you receive the new value of price and time - perhaps it happens
in parseMarketDataSnapshot method - as you parse your snapshot and get price and time information -
I don't understadn your code sufficiently - you should make this decision - but it should be somehwre
where you get access of this new point.
Then in this method you do all that stuuff - to prepare arrays.
Then from this same place you call OHLCData method and receive the result into variable declared
as DefaultHighLowDataset, Then it will become the dataset typ - and i hope you already worked with datasets
to have them drwan in a graph by JFreeChart. It should be the same process,
JFreeChart should hopefuilly know that this is a special type
of dataset and should know how to dadraw it.

0
 
gbcbrAuthor Commented:
package charts;

import com.fxcm.fix.UTCTimestamp;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;

import java.util.HashMap;
import java.util.List;

import org.jfree.data.time.RegularTimePeriod;

public class ChartCommander {

    LineEURUSD lineEURUSD;
    List<Date> datesArrayList = new ArrayList<Date>();
    ArrayList pricesArrayList;
    DefaultHighLowDataset dhld;
    String title;
    Comparable s1;
    RegularTimePeriod period;
    java.util.Date[] avg_ts;
    java.util.Date startDate;
    long interval;

    double open;
    double high;
    double low;
    double close;
    double[] prices;
    java.util.Date dates;

    //  TimeSeries s1;

    private static ChartCommander instance = new ChartCommander();

    public static ChartCommander getInstance() {
        return instance;
    }

    public ChartCommander() {

        lineEURUSD = new LineEURUSD(title);
        datesArrayList = new ArrayList();
        pricesArrayList = new ArrayList();
        interval = 10000L;
    }

    public void chartEURUSD(double[] avg, java.util.Date[] avg_ts,
                            double[] outY) {

        if (avg[0] != 0) {
            System.out.println("CC avg[0]    = " + avg[0]);
            System.out.println("CC avg_ts[0]    = " + avg_ts[0]);

            datesArrayList.add(avg_ts[0]);
            pricesArrayList.add(new Double(avg[0]));
            java.util.Date[] myDates =
                new java.util.Date[datesArrayList.size()];
            for (int j = 0; j < myDates.length; j++) {
                myDates[j] = (java.util.Date)datesArrayList.get(j);
            }
            double[] myPrices = new double[pricesArrayList.size()];
            for (int j = 0; j < myPrices.length; j++) {
                myPrices[j] = ((Double)pricesArrayList.get(j)).doubleValue();
            }

            System.out.println("Dates: ");
            for (int j = 0; j < myDates.length; j++) {
                System.out.println(myDates[j].toString());
            }
            System.out.println("Prices: ");

            for (int j = 0; j < myPrices.length; j++) {
                System.out.println(myPrices[j]);
            }
            System.out.println("interval: " + interval);

            lineEURUSD.doEvent_avg(avg);


        }
        if (outY[0] != 0) {
            System.out.println("CC outY[0]    = " + outY[0]);

            lineEURUSD.doEvent_outY(outY);
        }
    }

    public DefaultHighLowDataset OHLCData(java.util.Date[] dates,
                                          double[] prices,
                                          java.util.Date startDate,
                                          long interval) {

        java.util.Date[] finalDates;
        double[] highs;
        double[] opens;
        double[] closes;
        double[] lows;

        ArrayList anchors = new ArrayList();
        HashMap h = new HashMap();

        long start = startDate.getTime();

        for (int j = 0; j < dates.length; j++) {
            long cur = dates[j].getTime();
            long num = ((cur - start) / interval);
            Long anchor = new Long(start + num * interval + interval / 2);
            if (h.get(anchor) == null) {
                Moment mm = new Moment(dates[j], prices[j]);
                h.put(anchor, mm);
                anchors.add(anchor);
            } else {
                Moment mm = (Moment)h.get(anchor);
                mm.update(dates[j], prices[j]);
                h.put(anchor, mm);
            }

        }

        Collections.sort(anchors);

        finalDates = new java.util.Date[anchors.size()];
        opens = new double[anchors.size()];
        highs = new double[anchors.size()];
        lows = new double[anchors.size()];
        closes = new double[anchors.size()];

        for (int j = 0; j < anchors.size(); j++) {
            Long ttime = (Long)anchors.get(j);
            Moment mm = (Moment)h.get(ttime);
            finalDates[j] = new java.util.Date(ttime.longValue());
            opens[j] = mm.getOpen();
            closes[j] = mm.getClose();
            highs[j] = mm.getHigh();
            lows[j] = mm.getLow();

        }

        DefaultHighLowDataset dataset =
            new DefaultHigLowDataset("Series 1", finalDates, highs, lows,
                                     opens, closes);

        return dataset;
    }
}

Open in new window

0
 
gbcbrAuthor Commented:
= new DefaultHigLowDataset("Series 1", finalDates, highs, lows, opens, closes);
Type DefaultHigLowDataset not found
0
 
gbcbrAuthor Commented:
this was mistyping error.
real the same as before
>>DefaultHighLowDataset(Date[], double[], double[], double[], double[] ) cannot invoke DefaultHighLowDataset();
now
>>DefaultHighLowDataset(String, Date[], double[], double[], double[], double[] ) cannot invoke DefaultHighLowDataset();
0
 
for_yanCommented:
Yes, this seems reasonable - now you should put the line  

DefaultHighLowDataset  dataset = OHLCData(myDates, myPrices, myDates[0], interval);

say on line 79
and after that line add the code which would use your dataset for drawing using JFreeChart
0
 
gbcbrAuthor Commented:
Let me open new question for chart construction, because this will be completely different question.
In this question we discuss about data sorting only and dataset preparation.
Second part is haw to display it correctly.
0
 
for_yanCommented:
Do you see a printout of those lines from before calling this method?
Can you post it?
0
 
gbcbrAuthor Commented:
Error(146,13):  cannot find constructor DefaultHighLowDataset(java.lang.String,java.util.Date[],double[],double[],double[],double[])
0
 
gbcbrAuthor Commented:
this what I said before
>>DefaultHighLowDataset  dataset = new DefaultHigLowDataset(finalDates, highs, lows, opens, closes);
this demands: DefaultHighLowDataset(Date[], double[], double[], double[], double[] ) cannot invoke DefaultHighLowDataset();
Maybe we need to change constructor.
0
 
for_yanConnect With a Mentor Commented:
It looks like it always requires also volumes.
We'll assume that they are zeroes for now.
Go ahead and replace the whole method OHLCData with the code below:

public DefaultHighLowDataset  OHLCData(java.util.Date [] dates, double [] prices, java.util.Date startDate, long interval){
 
 
  java.util.Date [] finalDates;
     double [] highs;
     double [] opens;
     double [] closes;
    double [] lows;
   double [] volumes;



     ArrayList anchors = new ArrayList();
     HashMap h = new HashMap();

     long start = startDate.getTime();

     for(int j=0; j<dates.length; j++){
         long cur = dates[j].getTime();
         long num = ((cur-start)/interval);
         Long anchor = new Long(start + num*interval + interval/2);
         if(h.get(anchor) == null){
             Moment mm = new Moment(dates[j],prices[j]);
             h.put(anchor,mm);
             anchors.add(anchor);
         }  else {
             Moment mm = (Moment) h.get(anchor);
             mm.update(dates[j], prices[j]);
             h.put(anchor,mm);
         }




     }

     Collections.sort(anchors);

     finalDates = new java.util.Date[anchors.size()];
     opens = new double[anchors.size()];
         highs = new double[anchors.size()];
         lows = new double[anchors.size()];
         closes = new double[anchors.size()];
   volumes = new double[anchors.size()];



     for(int j=0; j<anchors.size(); j++){
         Long ttime = (Long) anchors.get(j);
         Moment mm = (Moment) h.get(ttime);
         finalDates[j]= new java.util.Date(ttime.longValue());
         opens[j] = mm.getOpen();
         closes[j] = mm.getClose();
         highs[j] = mm.getHigh();
         lows[j] = mm.getLow();
       volumes[j] = 0.0;



     }







DefaultHighLowDataset  dataset =  new DefaultHigLowDataset("Series 1", finalDates, highs, lows, opens, closes, volumes);

return dataset;
}

Open in new window

0
 
gbcbrAuthor Commented:
I suppose that we have to add somewhere constructor
public DefaultHighLowDataset(Comparable key, RegularTimePeriod period, double[] open, double[] high, double[] low, double[] close, double volume)
0
 
for_yanCommented:
No, we cannot add any constructor to this type - this is something JFreeChaert did for us - we need only to comply - we cannot change their rules for their classes  - please replace the method
as above and let me know what you see
0
 
gbcbrAuthor Commented:
I'm already replaced it but nothing changed
0
 
gbcbrAuthor Commented:
I found the error. This is problem of stupid JDeveloper. It's very strict and helpful but sometimes completely donkey.
We need import of
import org.jfree.data.xy.DefaultHighLowDataset;
and everything start work
interval: 10000
CC outY[0]    = -0.16296229
CC outY[0]    = -0.16296315
CC outY[0]    = -0.16296315
CC outY[0]    = -0.16296315
CC outY[0]    = -0.16296315
CC avg[0]    = 1.3908749999999999
CC avg_ts[0]    = Wed Mar 09 21:16:51 EET 2011
Dates: 
Wed Mar 09 21:13:58 EET 2011
Wed Mar 09 21:14:08 EET 2011
Wed Mar 09 21:14:10 EET 2011
Wed Mar 09 21:14:12 EET 2011
Wed Mar 09 21:14:20 EET 2011
Wed Mar 09 21:14:24 EET 2011
Wed Mar 09 21:14:25 EET 2011
Wed Mar 09 21:14:30 EET 2011
Wed Mar 09 21:14:30 EET 2011
Wed Mar 09 21:14:31 EET 2011
Wed Mar 09 21:14:32 EET 2011
Wed Mar 09 21:14:33 EET 2011
Wed Mar 09 21:14:34 EET 2011
Wed Mar 09 21:14:35 EET 2011
Wed Mar 09 21:14:35 EET 2011
Wed Mar 09 21:14:36 EET 2011
Wed Mar 09 21:14:37 EET 2011
Wed Mar 09 21:14:42 EET 2011
Wed Mar 09 21:14:42 EET 2011
Wed Mar 09 21:14:44 EET 2011
Wed Mar 09 21:14:44 EET 2011
Wed Mar 09 21:14:47 EET 2011
Wed Mar 09 21:14:51 EET 2011
Wed Mar 09 21:14:54 EET 2011
Wed Mar 09 21:14:54 EET 2011
Wed Mar 09 21:14:56 EET 2011
Wed Mar 09 21:14:58 EET 2011
Wed Mar 09 21:15:01 EET 2011
Wed Mar 09 21:15:02 EET 2011
Wed Mar 09 21:15:03 EET 2011
Wed Mar 09 21:15:04 EET 2011
Wed Mar 09 21:15:05 EET 2011
Wed Mar 09 21:15:06 EET 2011
Wed Mar 09 21:15:07 EET 2011
Wed Mar 09 21:15:08 EET 2011
Wed Mar 09 21:15:09 EET 2011
Wed Mar 09 21:15:12 EET 2011
Wed Mar 09 21:15:12 EET 2011
Wed Mar 09 21:15:14 EET 2011
Wed Mar 09 21:15:15 EET 2011
Wed Mar 09 21:15:15 EET 2011
Wed Mar 09 21:15:16 EET 2011
Wed Mar 09 21:15:20 EET 2011
Wed Mar 09 21:15:20 EET 2011
Wed Mar 09 21:15:23 EET 2011
Wed Mar 09 21:15:23 EET 2011
Wed Mar 09 21:15:24 EET 2011
Wed Mar 09 21:15:25 EET 2011
Wed Mar 09 21:15:26 EET 2011
Wed Mar 09 21:15:26 EET 2011
Wed Mar 09 21:15:27 EET 2011
Wed Mar 09 21:15:27 EET 2011
Wed Mar 09 21:15:28 EET 2011
Wed Mar 09 21:15:31 EET 2011
Wed Mar 09 21:15:32 EET 2011
Wed Mar 09 21:15:33 EET 2011
Wed Mar 09 21:15:34 EET 2011
Wed Mar 09 21:15:35 EET 2011
Wed Mar 09 21:15:36 EET 2011
Wed Mar 09 21:15:37 EET 2011
Wed Mar 09 21:15:38 EET 2011
Wed Mar 09 21:15:39 EET 2011
Wed Mar 09 21:15:40 EET 2011
Wed Mar 09 21:15:41 EET 2011
Wed Mar 09 21:15:45 EET 2011
Wed Mar 09 21:15:46 EET 2011
Wed Mar 09 21:15:47 EET 2011
Wed Mar 09 21:15:49 EET 2011
Wed Mar 09 21:15:50 EET 2011
Wed Mar 09 21:15:50 EET 2011
Wed Mar 09 21:15:51 EET 2011
Wed Mar 09 21:15:53 EET 2011
Wed Mar 09 21:15:56 EET 2011
Wed Mar 09 21:15:59 EET 2011
Wed Mar 09 21:16:01 EET 2011
Wed Mar 09 21:16:04 EET 2011
Wed Mar 09 21:16:05 EET 2011
Wed Mar 09 21:16:06 EET 2011
Wed Mar 09 21:16:08 EET 2011
Wed Mar 09 21:16:09 EET 2011
Wed Mar 09 21:16:13 EET 2011
Wed Mar 09 21:16:14 EET 2011
Wed Mar 09 21:16:15 EET 2011
Wed Mar 09 21:16:19 EET 2011
Wed Mar 09 21:16:20 EET 2011
Wed Mar 09 21:16:22 EET 2011
Wed Mar 09 21:16:22 EET 2011
Wed Mar 09 21:16:24 EET 2011
Wed Mar 09 21:16:31 EET 2011
Wed Mar 09 21:16:31 EET 2011
Wed Mar 09 21:16:32 EET 2011
Wed Mar 09 21:16:33 EET 2011
Wed Mar 09 21:16:38 EET 2011
Wed Mar 09 21:16:39 EET 2011
Wed Mar 09 21:16:39 EET 2011
Wed Mar 09 21:16:40 EET 2011
Wed Mar 09 21:16:40 EET 2011
Wed Mar 09 21:16:43 EET 2011
Wed Mar 09 21:16:45 EET 2011
Wed Mar 09 21:16:51 EET 2011
Prices: 
1.3905949999999998
1.3906749999999999
1.390685
1.390695
1.390695
1.390685
1.390695
1.3907349999999998
1.3907250000000002
1.3907349999999998
1.390775
1.390745
1.390755
1.390745
1.3907349999999998
1.390745
1.3907250000000002
1.3907949999999998
1.3908049999999998
1.390825
1.390815
1.3907850000000002
1.3907949999999998
1.3907949999999998
1.3908049999999998
1.3907850000000002
1.3908049999999998
1.390835
1.390885
1.390895
1.3908749999999999
1.390895
1.390885
1.390905
1.390895
1.390905
1.390895
1.390905
1.390895
1.390885
1.390895
1.390905
1.390895
1.390905
1.390895
1.390905
1.390905
1.3909349999999998
1.390975
1.3909950000000002
1.390975
1.3909850000000001
1.3909850000000001
1.390975
1.3909950000000002
1.391025
1.391035
1.391015
1.391015
1.391045
1.391045
1.391035
1.3910049999999998
1.391025
1.391035
1.3909850000000001
1.3909950000000002
1.3910049999999998
1.3909950000000002
1.390975
1.390965
1.390975
1.390975
1.3909950000000002
1.3909950000000002
1.3909850000000001
1.390975
1.3909850000000001
1.390965
1.3909850000000001
1.390975
1.3909250000000002
1.3909150000000001
1.3908649999999998
1.3908749999999999
1.3908749999999999
1.3908749999999999
1.3908749999999999
1.3908649999999998
1.3908649999999998
1.3908749999999999
1.3908649999999998
1.3908649999999998
1.3908749999999999
1.3908649999999998
1.3908749999999999
1.3908649999999998
1.3908649999999998
1.3908649999999998
1.3908749999999999
interval: 10000

Open in new window

0
 
gbcbrAuthor Commented:
So, let's now to build the chart!
0
 
for_yanCommented:
I see a misprint there. Change the line:

DefaultHighLowDataset  dataset =  new DefaultHigLowDataset("Series 1", finalDates, highs, lows, opens, closes, volumes);

to line:

DefaultHighLowDataset  dataset =  new DefaultHighLowDataset("Series 1", finalDates, highs, lows, opens, closes, volumes);

(letter "h" was missing in High)


0
 
gbcbrAuthor Commented:
I've already correct it far before.
Let's go to new question OHLC chart.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.