I'm looking for a way to add data to OHLC series without specifying date values of the point.
So let's assume that I have a List<Candle>
where Candle
object contain values for high
, low
, open
and close
, but not the date
.
I'd like to add values to series in such a way that they will be regularly distributed on the chart, I mean, there will be equal distance between all candles.
Is there any convenient options to add point to the end and to the beginning of the series' data list?
There's an override of the add() method accepting open
, high
, low
and close
values:
public int add(double open, double high, double low, double close)
And another accepting index
, open
, high
, low
and close
values:
public int add(int index, double open, double high, double low, double close)
UPDATE:
In the project you sent, I see you are removing the first point of the series after a few iterations:
candleSeries.delete(0);
Note the first add() override mentioned above internally calls the second:
public int add(double open, double high, double low, double close) {
return add(getCount(), open, high, low, close);
}
So, the Count of the series is being used as XValue for the point being added. But removing the first point you are loosing the sync of Count and XValues, and this makes the first override of the add() method not to be the appropriate in this situation.
In your case, you could still use a third override of the add() method, accepting index
, open
, high
, low
and close
values:
public int add(double index, double open, double high, double low, double close)
Note the first parameter of is override is named "index" but it's actually a double so you can consider it a XValue/Date.
This is, in your test application, change this:
candleSeries.add(point.getOpen(), point.getHigh(), point.getLow(), point.getClose());
For this:
candleSeries.add(candleSeries.getXValues().getValue(candleSeries.getCount()-1) + 1, point.getOpen(), point.getHigh(), point.getLow(), point.getClose());