gbcbr
asked on
OHLC chart
Please advice how to create OHLC chart from this dataset:
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);
DefaultHighLowDataset dataset =
OHLCData(myDates, myPrices, myDates[0], interval);
lineEURUSD.doEvent_avg(avg);
}
if (outY[0] != 0) {
System.out.println("CC outY[0] = " + outY[0]);
lineEURUSD.doEvent_outY(outY);
}
}
So it still complains when running this constructor?
ASKER
no, now it's OK
Well, that's great!
You mentioned that you were printing graphs with JFreeChart before.
Can you post the corresponding code?
I believe it should be similar.
You mentioned that you were printing graphs with JFreeChart before.
Can you post the corresponding code?
I believe it should be similar.
ASKER
This is simple line chart, but I suppose for candlestick chart we have to use something like this
http://www.roseindia.net/chartgraphs/candle-stick-chart.shtml
http://www.roseindia.net/chartgraphs/candle-stick-chart.shtml
package charts;
import java.awt.Color;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.AxisLocation;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYItemRenderer;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.FixedMillisecond;
import org.jfree.data.time.TimeSeries;
import org.jfree.data.time.TimeSeriesCollection;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.RectangleInsets;
public class LineEURUSD extends JFrame {
public LineEURUSD(final String title) {
super(title);
setContentPane(chartPanel);
setSize(800, 600);
setVisible(true);
}
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 > 100) {
s1.delete(0, 0);
}
}
public void doEvent_outY(double[] outX) {
sc++;
s2.addOrUpdate(new FixedMillisecond(new Date().getTime() + 5000),
new Float(outX[0]));
if (sc > 100) {
s2.delete(0, 0);
}
}
private JFreeChart createChart(XYDataset dataset) {
JFreeChart chart =
ChartFactory.createTimeSeriesChart("EUR/USD - 3", // title
"Time", // x-axis label
"inX[0]", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false) // generate URLs?
;
XYPlot plot = (XYPlot)chart.getPlot();
XYDataset dataset2 = createDataset2();
plot.setDataset(0, dataset);
plot.setDataset(1, dataset2);
DateAxis axis = (DateAxis)plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("hh:mm:ss"));
XYItemRenderer r = plot.getRenderer();
XYItemRenderer renderer2 = new XYLineAndShapeRenderer();
r.setSeriesPaint(0, Color.blue);
r.setSeriesPaint(1, Color.red);
renderer2.setSeriesPaint(0, Color.red);
plot.setRenderer(1, renderer2);
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
NumberAxis axis2 = new NumberAxis("outX[0]");
axis2.setAutoRangeIncludesZero(false);
axis2.setLabelPaint(Color.red);
axis2.setTickLabelPaint(Color.green);
plot.setRangeAxis(1, axis2);
plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
plot.mapDatasetToRangeAxis(1, 1);
return chart;
}
private XYDataset createDataset() {
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
return dataset;
}
private XYDataset createDataset2() {
TimeSeriesCollection dataset2 = new TimeSeriesCollection();
dataset2.addSeries(s2);
return dataset2;
}
public JPanel createDemoPanel() {
JFreeChart chart = createChart(createDataset());
ChartPanel panel = new ChartPanel(chart);
panel.setFillZoomRectangle(true);
panel.setMouseWheelEnabled(true);
return panel;
}
ChartPanel chartPanel = (ChartPanel)createDemoPanel();
}
I aslo believe this way - just try use this our new dataset whuich we created
I'll now respond slower for some time, as I have to do some other stuff for a little while
There's an example of a dynamic candlestick here http://technojeeves.com/tech/dynachart-cand-fat.jar
Run as
Run as
java -jar dynachart-cand-fat.jar
ASKER
yes, this is well, just advice how to make CandleStickEURUSD class with this dataset
DefaultHighLowDataset dataset =
OHLCData(myDates, myPrices, myDates[0], interval);
immediately after;
DeafaultHighLowDataset dataset = OHLCD....
try this:
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSiz
ApplicationFrame af = new ApplicationFrame("Chart");
af. setContentPane(chartPanel)
af.setVisible(true);
ASKER
JFreeChart chart = createChart(dataset);
Method 'createChart' not found
Method 'createChart' not found
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
the same Method 'createChart' not found
ASKER
I try to create separate class, but I don't understand how to set there our dataset
package charts;
import java.util.Calendar;
import java.util.Date;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.axis.DateTickMarkPosition;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.StandardXYItemRenderer;
import org.jfree.data.time.RegularTimePeriod;
import org.jfree.data.xy.DefaultHighLowDataset;
import org.jfree.ui.ApplicationFrame;
public class CandleStickEURUSD extends ApplicationFrame {
transient RegularTimePeriod period;
java.util.Date[] dates;
java.util.Date startDate;
long interval;
double[] avg; // = new double[10];
java.util.Date[] avg_ts; // = new java.util.Date[10];
double[] outY; // = new double[10];
java.util.Date[] myDates;
double[] myPrices;
public CandleStickEURUSD() {
ChartCommander.getInstance().chartEURUSD(avg, avg_ts, outY);
final DefaultHighLowDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(800, 600));
setContentPane(chartPanel);
chartPanel.setVisible(true);
}
private DefaultHighLowDataset createDataset() {
DefaultHighLowDataset dataset = OHLCData(myDates, myPrices, myDates[0], interval);
return dataset;
}
private JFreeChart createChart(final DefaultHighLowDataset dataset) {
final JFreeChart chart =
ChartFactory.createHighLowChart("OHLC EURUSD bot", "Time", "Value",
dataset, true);
final DateAxis axis = (DateAxis)chart.getXYPlot().getDomainAxis();
axis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
final XYPlot plot = (XYPlot)chart.getPlot();
plot.setRenderer(1, new StandardXYItemRenderer());
return chart;
}
}
yes, add this method to your class (kjust as it is inside your class - not inside
any methods - in parallel to OHLCData method):
--------------------------
private JFreeChart createChart(final DefaultHighLowDataset dataset) {
final JFreeChart chart = ChartFactory.createCandles
"Candlestick Demo", "Time", "Price", dataset, false);
return chart;
}
--------------------------
and then modify the line from above
replace this:
JFreeChart chart = af.createChart(dataset);
back to this:
JFreeChart chart = createChart(dataset);
Please, don't make any arbitrary changes - please follow instructions
It would also be good if you still find the printout after creation
of mydates and myPrices array and post it - I'm sure we'll need it
of mydates and myPrices array and post it - I'm sure we'll need it
ASKER
It's starts to create for each signal very small chart window and printout is this:
interval: 10000
CC outY[0] = -0.1877336
CC outY[0] = -0.1877336
CC outY[0] = -0.18773669
CC avg[0] = 1.3904550000000002
CC avg_ts[0] = Wed Mar 09 22:57:17 EET 2011
Dates:
Wed Mar 09 22:56:55 EET 2011
Wed Mar 09 22:56:55 EET 2011
Wed Mar 09 22:57:03 EET 2011
Wed Mar 09 22:57:06 EET 2011
Wed Mar 09 22:57:06 EET 2011
Wed Mar 09 22:57:08 EET 2011
Wed Mar 09 22:57:15 EET 2011
Wed Mar 09 22:57:17 EET 2011
Prices:
1.390475
1.390475
1.3904550000000002
1.3904649999999998
1.390485
1.3904550000000002
1.390475
1.3904550000000002
interval: 10000
CC outY[0] = -0.18773669
CC outY[0] = -0.18773669
CC outY[0] = -0.18773669
CC outY[0] = -0.18773669
CC outY[0] = -0.18773669
CC outY[0] = -0.18773682
ASKER
maybe really better to move it to separate class, because when I forgot to comment
lineEURUSD = new LineEURUSD(title);
and it create empty window of LineEURUSD class with proper size, just without chart, because data are commented.
lineEURUSD = new LineEURUSD(title);
and it create empty window of LineEURUSD class with proper size, just without chart, because data are commented.
ASKER
Anyway we will need to do this because:
1. It has to be 10 different charts;
2. In the next step we have to use OHLCSeriesCollection and place in one chart window two charts;
1. It has to be 10 different charts;
2. In the next step we have to use OHLCSeriesCollection and place in one chart window two charts;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I just don't understand how to call our dataset from
private DefaultHighLowDataset createDataset() {
DefaultHighLowDataset dataset = ??????????
return dataset;
}
You don't need that - we already created dataset, so this functionality is already
accomplished - we have data - we need to create chart and all visual stuff around it
accomplished - we have data - we need to create chart and all visual stuff around it
ASKER
We have one very small chart window, after manual expanding looks like this CS1.tiff
I believe it looks good - now it requires adjustment of scale
and other details. I need to learn more about JFreeChart
to advise you about it. I need to do some other stuff for now.
If you can try to read how to change scale etc.
maybe someone else would help you. Otherwise,
I'll need to install JFreeChart and try to run it myself - perhaps
I can do it overnight
and other details. I need to learn more about JFreeChart
to advise you about it. I need to do some other stuff for now.
If you can try to read how to change scale etc.
maybe someone else would help you. Otherwise,
I'll need to install JFreeChart and try to run it myself - perhaps
I can do it overnight
Try replacing the line
final JFreeChart chart = ChartFactory.createCandles tickChart(
"Candlestick Demo", "Time", "Price", dataset, false);
with this line:
final JFreeChart chart = ChartFactory.createHighLow Chart(
"OHLC Demo 2",
"Time",
"Value",
dataset,
true
);
final JFreeChart chart = ChartFactory.createCandles
"Candlestick Demo", "Time", "Price", dataset, false);
with this line:
final JFreeChart chart = ChartFactory.createHighLow
"OHLC Demo 2",
"Time",
"Value",
dataset,
true
);
ASKER
the same
ASKER
maybe this will help
http://www.java2s.com/Code/Java/Chart/JFreeChartCandlestickChartSample.htm
http://www.java2s.com/Code/Java/Chart/JFreeChartCandlestickChartSample.htm
I already used that - I still don't understadn why it does not scale correctly
They always make it all so complex and invent lots of terms
Well, try immeditaley after:
-------------------
final JFreeChart chart = ChartFactory.createHighLow Chart(
"OHLC Demo 2",
"Time",
"Value",
dataset,
true
);
-------------------
add:
-----------------
ValueAxis ax = chart.getXYPlot().getRange Axis();
ax.setRange(1.39, 1.41);
--------
Probably would not work either - it needs to be studied
They always make it all so complex and invent lots of terms
Well, try immeditaley after:
-------------------
final JFreeChart chart = ChartFactory.createHighLow
"OHLC Demo 2",
"Time",
"Value",
dataset,
true
);
-------------------
add:
-----------------
ValueAxis ax = chart.getXYPlot().getRange
ax.setRange(1.39, 1.41);
--------
Probably would not work either - it needs to be studied
ASKER
the same, I can't understand this also, before I make another 10 different changes, no reaction at all, looks like it blind.
I tried to do this in constructor also, the same result:
small, just initial chart window, axis from 0 and some horizontal bars
I tried to do this in constructor also, the same result:
small, just initial chart window, axis from 0 and some horizontal bars
Well, remove these changes which I suggested before - and
mmake sure you remove all yourr ten changes either.
mmake sure you remove all yourr ten changes either.
I think you'll be better off opening new question - write something - "need help in JFReeChart - how to scale the plot" -
and attach the picture
then objects or someone who is or has specialists in JFreeChart -should help with it.
Don't know if anyone follows it now.I didn't use JFreeChart myself,
and I'm too busy today to install all that stuff and try to understand it.
and attach the picture
then objects or someone who is or has specialists in JFreeChart -should help with it.
Don't know if anyone follows it now.I didn't use JFreeChart myself,
and I'm too busy today to install all that stuff and try to understand it.
ASKER
I think that is better to move all graphic into separate class and leave hear only dataset preparation.
But then you'll have to instantiate a new class, and then you'll say that you mind is burning as you don't understand
how to do it; remember, how I wanted to have calculations in a separate class, and that was quite logical.
Frankly, I don't think any of that matters as long as it works. How to scale it and to make it show
reasonable picture - that is important. Anyway all this drawing stuff will be happening in JFreeChart classes.
how to do it; remember, how I wanted to have calculations in a separate class, and that was quite logical.
Frankly, I don't think any of that matters as long as it works. How to scale it and to make it show
reasonable picture - that is important. Anyway all this drawing stuff will be happening in JFreeChart classes.
What is strange is that I see here 22:56 time,
and in the figure I see times around 23:21 -was it at another time?
Maybe there is some place where we still happen to have price equal to zero ?
that would explain why it doesn't want to scale it automatically.
Dates:
Wed Mar 09 22:56:55 EET 2011
Wed Mar 09 22:56:55 EET 2011
Wed Mar 09 22:57:03 EET 2011
Wed Mar 09 22:57:06 EET 2011
Wed Mar 09 22:57:06 EET 2011
Wed Mar 09 22:57:08 EET 2011
Wed Mar 09 22:57:15 EET 2011
Wed Mar 09 22:57:17 EET 2011
Prices:
1.390475
1.390475
1.3904550000000002
1.3904649999999998
1.390485
1.3904550000000002
1.390475
1.3904550000000002
interval: 10000
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I'm already at home, let's speak tomorrow.
Just think how we can get this dataset from specific class CandleStickEURUSD and manage it there, I suppose that they developed this JFreeChart classes especially, because they have some specific properties for charts drawing. But we try to mix standard class with JFreeChart, most probably this is the reason why it doesn't react on any commands.
You already cool my brain when you solve this bloody data sorting, to plot this chart is only 1% of loading, it's hundreds samples published in Internet, so this is easy question.
For me only one action important, how to get this dataset
Just think how we can get this dataset from specific class CandleStickEURUSD and manage it there, I suppose that they developed this JFreeChart classes especially, because they have some specific properties for charts drawing. But we try to mix standard class with JFreeChart, most probably this is the reason why it doesn't react on any commands.
You already cool my brain when you solve this bloody data sorting, to plot this chart is only 1% of loading, it's hundreds samples published in Internet, so this is easy question.
For me only one action important, how to get this dataset
private DefaultHighLowDataset createDataset() {
DefaultHighLowDataset dataset = ??????????OHLCData(myDates, myPrices, myDates[0], interval);
return dataset;
}
No, let's keep it as it is for now.
Return everything to how it was and then add these too lines, which I posted before.
We are not mixing anything - it is just a library with very many options and with those usually come some
complexitities. we do not know the details of its usage, therefore we don't know how to modify it.
Just add these two lines tomorrow and let's see what is going on.
You don't need this method createDataset - we already created dataset. Atleast for now it seems to be reasonable.
We need to know how to manage the drawing, scaling, etc., the inner working of JFreeChart.
We should concentrate on these tasks and minimize any other changes, otherwise the errors get piled one over another.
Return everything to how it was and then add these too lines, which I posted before.
We are not mixing anything - it is just a library with very many options and with those usually come some
complexitities. we do not know the details of its usage, therefore we don't know how to modify it.
Just add these two lines tomorrow and let's see what is going on.
You don't need this method createDataset - we already created dataset. Atleast for now it seems to be reasonable.
We need to know how to manage the drawing, scaling, etc., the inner working of JFreeChart.
We should concentrate on these tasks and minimize any other changes, otherwise the errors get piled one over another.
thsi is the source where I found last recommendation - just not to lose it jsut in case:
http://rishisoftwareblog.wordpress.com/2009/05/13/setting-custom-range-for-your-plot-within-jfreechart/
ASKER
what is the problem happened last week, sometimes I see only message from EE 2-3 hours
ASKER
I put these lines and I see normal chart as a OHLC, as a CandleStick.
Two questions:
Chart window still appear in top-left screen corner and has only initial size, so to see the chart I have to pull corner of chart window and extend it manually.
Another sizing question is to fix width of candle, because fist candle appear on half of screen.
Two questions:
Chart window still appear in top-left screen corner and has only initial size, so to see the chart I have to pull corner of chart window and extend it manually.
Another sizing question is to fix width of candle, because fist candle appear on half of screen.
ASKER
ASKER
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is it about the width of the candle?
I look at the picture you posted - it all looks normal to me?
I look at the picture you posted - it all looks normal to me?
ASKER
Yes, it sets size and position, now we to setCandleWidth and question be solved
ASKER
Because it's late picture, this is start picture
CS3.tiff
CS3.tiff
ASKER
And what is the limit of candles, how I can set as in line chart, only 100 last.
There is simple
There is simple
public void doEvent_outY(double[] outX) {
sc++;
s2.addOrUpdate(new FixedMillisecond(new Date().getTime() + 5000),
new Float(outX[0]));
if (sc > 100) {
s2.delete(0, 0);
}
But in candle maybe another way?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
About one fat candle in the beginnoing - ikm not sure what to do - franlly on tdameritrade software I see the same thing in the beginning of the trading day - I don't think it is a big deal - it scales them to the whole screen. I'll think about it after I come to work in about 4 or 5 hours from now - if we have any ideas, we'll think
ASKER
I just need your advise how to use this class methods in our class
>>method setCandleWidth
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/xy/CandlestickRenderer.html
>>method setCandleWidth
http://www.jfree.org/jfreechart/api/javadoc/org/jfree/chart/renderer/xy/CandlestickRenderer.html
OK, I'll browse through API when I come to work. I think in general you should create CandleStickRenderer(double width) with constructor - providing width - don't know in what units , and then we should find to what class to setCandleStickRenderer - is it CandleStickChart ?
We need to find in API.
We need to find in API.
ASKER
OK, during your way to your work think about third question about OHLC charts.
When we finish with this I'l open new question about OHLCSeriesCollection.
I extract this chapter from Developer Guide.
OHLCSeriesCollection.docx
When we finish with this I'l open new question about OHLCSeriesCollection.
I extract this chapter from Developer Guide.
OHLCSeriesCollection.docx
What is the third question ?
ASKER
How to place in one chart plot two OHLC datasets with different range of axis Y and color them in similar palette (red/green), but little bit different colors, for easy recognizing.
I'll try to create second dataset, similar for yours.
I'll try to create second dataset, similar for yours.
Try first to put them in a straightforward way - just make another label, say "Series 2" - you can
add this as an additional String argument to our same method. And let's see what happens.
Is your difference in Y ranges dramatic - e.g. you have tens and dozens instead of one and two - in the Y range?
add this as an additional String argument to our same method. And let's see what happens.
Is your difference in Y ranges dramatic - e.g. you have tens and dozens instead of one and two - in the Y range?
ASKER
Let's finish with setCandleWidth and close this question.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
it asks about class CandleStickRenderer
ASKER
I found the error:
not CandleStickRenderer
CandlestickRenderer
But anyway it still fat
not CandleStickRenderer
CandlestickRenderer
But anyway it still fat
ASKER
private double width;
private JFreeChart createChart(final DefaultHighLowDataset dataset) {
final JFreeChart chart =
ChartFactory.createCandlestickChart("Candlestick Demo", "Time",
"Price", dataset, false);
width = 10;
NumberAxis yaxis = (NumberAxis)chart.getXYPlot().getRangeAxis();
yaxis.setAutoRangeIncludesZero(false);
CandlestickRenderer csr = new CandlestickRenderer();
csr.setCandleWidth(width);
chart.getXYPlot().setRenderer(csr);
return chart;
}
CS4.tiff
Well, that seems OK.
What happens when you have just one candle?
Is it still fat?
What happens when you have just one candle?
Is it still fat?
ASKER
Very elegant solution without creating additional classes.
Excellent work!!!
Excellent work!!!
ASKER
no, I fix size in 10 pixels, so now all the time they in the same size.
For me it was critical, how to call this class correct. Now I can do all exercises with any methods of it.
Thanks again.
For me it was critical, how to call this class correct. Now I can do all exercises with any methods of it.
Thanks again.
You are welcome.
ASKER
let's start with third question
ASKER
You confuse me with
ArrayList>> datesArrayList1<< = new ArrayList();
ArrayList pricesArrayList1 = new ArrayList();
for (int j=0; j< datesArrayList.size(); j++){
java.util.Date dd = (java.util.Date) datesArrayList.get(j);
Double dpr = (Double) priceArrayList.get(j);
if ((dd.getTime() - avg_ts[0].getTime())<-1000 000L) continue;
datesArrayList1.add(dd);
pricesArrayList1.add(dpr);
}
This has to be another array list or this just mistyping?
ArrayList>> datesArrayList1<< = new ArrayList();
ArrayList pricesArrayList1 = new ArrayList();
for (int j=0; j< datesArrayList.size(); j++){
java.util.Date dd = (java.util.Date) datesArrayList.get(j);
Double dpr = (Double) priceArrayList.get(j);
if ((dd.getTime() - avg_ts[0].getTime())<-1000
datesArrayList1.add(dd);
pricesArrayList1.add(dpr);
}
This has to be another array list or this just mistyping?
No this was not mistyping - I suggested to create at this point another pair of ArrayList's which would contain only the most recent data, and do further manipulatioins with this changed list. This would ensure that number of cndles which we see will grow only to some point and after that point will become constant. This was in reponse to your concern that the number of candles becomes too big
ASKER
In this edition it doesn't control QTY.
I put 1000L for easy control, but it continue work already 5 minutes
I put 1000L for easy control, but it continue work already 5 minutes
public void eurusd_CandleStick_Market(double[] avg,
java.util.Date[] avg_ts) {
if (avg[0] != 0 && mds == true) {
System.out.println("EUR/USD Market avg[0] = " + avg[0]);
System.out.println("EUR/USD Market avg_ts[0] = " + avg_ts[0]);
System.out.println("EUR/USD Market mds = " + mds);
System.out.println("EUR/USD Market mflag0c = " + mflag0c);
datesArrayList.add(avg_ts[0]);
pricesArrayList.add(new Double(avg[0]));
ArrayList datesArrayList1 = new ArrayList();
ArrayList pricesArrayList1 = new ArrayList();
for (int j = 0; j < datesArrayList1.size(); j++) {
java.util.Date dd = (java.util.Date)datesArrayList1.get(j);
Double dpr = (Double)pricesArrayList1.get(j);
if ((dd.getTime() - avg_ts[0].getTime()) < -1000L)
continue;
datesArrayList1.add(dd);
pricesArrayList1.add(dpr);
}
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);
DefaultHighLowDataset dataset =
OHLCData(myDates, myPrices, myDates[0], interval);
JFreeChart chart = createChart(dataset);
ChartPanel chartPanel = new ChartPanel(chart);
af.setContentPane(chartPanel);
af.setSize(800, 500);
af.setLocation(1600, 800);
if (mflag0c == true) {
af.setVisible(true);
chartPanel.repaint();
} else {
af.setVisible(false);
}
}
}
Well, of course it does not - after you creae your lists with "1" in the end - you should use these
new lists in what follows instead of your original lists - these new lists
have lees data in termes of time - and you continue using your old lists in the code below, so
you just created filtered lists but you are not using them to
create dataset; that's waht I had written - create filtered lists and in the code below use them instead of the original lists - then you'll get only
recent candles, and deop the old ones after some time.
Use a little bit longer interval -1000L is just a second - how many candles would you get in that period?
new lists in what follows instead of your original lists - these new lists
have lees data in termes of time - and you continue using your old lists in the code below, so
you just created filtered lists but you are not using them to
create dataset; that's waht I had written - create filtered lists and in the code below use them instead of the original lists - then you'll get only
recent candles, and deop the old ones after some time.
Use a little bit longer interval -1000L is just a second - how many candles would you get in that period?
ASKER
I put 12000L this is two candles exactly.
Please explain more detailed about these two arrays.
ArrayList< let's say zero> get data from external source, convert it into MyDates and MyPrices which after go to the Moment class for calculation and return back as dataset.
I don't understand how works ArrayList1 and how it control number of candles.
For me understadable formula is:
if (sc > 100) {
s1.delete(0, 0);
Why we can't do something like this and be sure that these extra data really deleted and free heap memory?
Please explain more detailed about these two arrays.
ArrayList< let's say zero> get data from external source, convert it into MyDates and MyPrices which after go to the Moment class for calculation and return back as dataset.
I don't understand how works ArrayList1 and how it control number of candles.
For me understadable formula is:
if (sc > 100) {
s1.delete(0, 0);
Why we can't do something like this and be sure that these extra data really deleted and free heap memory?
We just intercept between the lists without onese and myDates and myPrices
and remove the older points before we creayte myDates and myPrices - and in this way
these arrays should contain only limited number of points - most recent ones.
this is not the device to reduce memory - bu this should not affect memory siginfiocantly
Don't understand about these s1.delete, but I suggest to follow these changes
with "1" arrays and see how it waorks.
and remove the older points before we creayte myDates and myPrices - and in this way
these arrays should contain only limited number of points - most recent ones.
this is not the device to reduce memory - bu this should not affect memory siginfiocantly
Don't understand about these s1.delete, but I suggest to follow these changes
with "1" arrays and see how it waorks.
ASKER
This is from line chart:
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);
}
}
Why we can't do like this, it has to be simpler that this interception which I still can't understand.
I don't know about this sc.delete, etc. - if you believe it should work - please go ahead and try - just remember how to retrun back and do
it another way if that does not work.
I usually prefer to do exactly like I know even though it may require a few more lines of code.
It is always faster than to rely more on some API which was cretaed by other people, and they had some
other thaoughts in mind. It is only whan there is no choice, that I use these API's or when I already tried
them in certain way and know they work in this way.
Your issues with memory were most probably related with some graphics situation - it was creating too many windows
in memory or something like that - it is hard to believe that your amount of actual data )in the arryLists etc.)
could be comparable with 1 Gb of memory you are using.
it another way if that does not work.
I usually prefer to do exactly like I know even though it may require a few more lines of code.
It is always faster than to rely more on some API which was cretaed by other people, and they had some
other thaoughts in mind. It is only whan there is no choice, that I use these API's or when I already tried
them in certain way and know they work in this way.
Your issues with memory were most probably related with some graphics situation - it was creating too many windows
in memory or something like that - it is hard to believe that your amount of actual data )in the arryLists etc.)
could be comparable with 1 Gb of memory you are using.
ASKER
>>with 1 Gb of memory you are using.
now 5GB
Ok, let's help me with candle limitation in new question and also I'll open question about memory.
now 5GB
Ok, let's help me with candle limitation in new question and also I'll open question about memory.