I want to draw a Bollinger Band on my own (that is, NOT via adding BB to a chart).
What is the best practice for that? Currently I'm doing this:
IPolyLineChartObject upper;
IPolyLineChartObject middle;
IPolyLineChartObject lower;
public void onStart(IContext ctx) throws JFException
{
this.ctx = ctx;
engine = ctx.getEngine();
this.console = ctx.getConsole();
indicators = ctx.getIndicators();
chart = ctx.getChart(Instrument.EURUSD);
upper = chart.getChartObjectFactory().createPolyLine();
upper.setColor(Color.ORANGE);
middle = chart.getChartObjectFactory().createPolyLine();
middle.setColor(Color.RED);
lower = chart.getChartObjectFactory().createPolyLine();
lower.setColor(Color.ORANGE);
chart.addToMainChart(upper);
chart.addToMainChart(middle);
chart.addToMainChart(lower);
console.getOut().println("Started");
}
public void onTick(Instrument instrument, ITick tick) throws JFException
{
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
{
if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.FIFTEEN_MINS))
return;
double[] currentValues = indicators.bbands(instrument, period, OfferSide.ASK, IIndicators.AppliedPrice.CLOSE, timePeriod, nbDevUp, nbDevDn, maType, 1);
long time = askBar.getTime();
System.out.println(time+"/0: "+currentValues[0]+", 1: "+currentValues[1]+", 2: "+currentValues[2]);
upper.addNewPoint(time, currentValues[0]);
middle.addNewPoint(time, currentValues[1]);
lower.addNewPoint(time, currentValues[2]);
}
But the PolyLines grow and will certainly lead to an out of memory at some time, I don't find a way to remove points (e.g. the oldest). So what is the best practice to do that?
Thanks!