The Java code in indicators should be optimized for memory allocation and computing speed. This will increase the automated strategies backtests and efficiency.
For example, I think the code for Alligator indicator and maybe others should be like below:
public IndicatorResult calculate(int startIndex, int endIndex) {
//calculating startIndex taking into account lookback value
if (startIndex - getLookback() < 0) {
startIndex -= startIndex - getLookback();
}
if (startIndex > endIndex) {
return new IndicatorResult(0, 0);
}
/* no need - save memory allocation space and computing time
double[] jawSma = new double[endIndex - startIndex + 2 + getLookback()];
double[] teethSma = new double[endIndex - startIndex + 2 + getLookback()];
double[] lipsSma = new double[endIndex - startIndex + 2 + getLookback()];
*/
int aOutLen = endIndex - startIndex + 1;
jawSmmaIndicator.setInputParameter(0, inputs[0]);
teethSmmaIndicator.setInputParameter(0, inputs[0]);
lipsSmmaIndicator.setInputParameter(0, inputs[0]);
// we already have output buffers; no need jawSma,etc
jawSmmaIndicator.setOutputParameter(0, outputs[0]);//jawSma);
teethSmmaIndicator.setOutputParameter(0, outputs[1]);//teethSma);
lipsSmmaIndicator.setOutputParameter(0, outputs[2]); //lipsSma);
IndicatorResult dJawSmaResult = jawSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);
IndicatorResult dTeethSmaResult = teethSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);
IndicatorResult dLipsSmaResult = lipsSmmaIndicator.calculate(startIndex/* - 1*/, endIndex);
// checks
if(!(dJawSmaResult.getNumberOfElements() == aOutLen && dTeethSmaResult.getNumberOfElements() == aOutLen &&
dLipsSmaResult.getNumberOfElements() == aOutLen))
throw new ArrayStoreException("Better Alligator : number of elements in outputs buffers do not match.");
/* save computing time; outputs already computed above
int i, k;
for (i = 1, k = dJawSmaResult.getNumberOfElements(); i < k; i++) {
outputs[0][i - 1] = jawSma[i];
}
for (i = 1, k = dTeethSmaResult.getNumberOfElements(); i < k; i++) {
outputs[1][i - 1] = teethSma[i];
}
for (i = 1, k = dLipsSmaResult.getNumberOfElements(); i < k; i++) {
outputs[2][i - 1] = lipsSma[i];
}
return new IndicatorResult(startIndex, i - 1);
*/
return new IndicatorResult(startIndex, aOutLen);
}