Hi
I am struggling with a simple indicator using 2 inputs, which gives the following error when I change instrument or time period:

I have studied the Wiki example with multiple inputs, but checking for null array does not solve the problem.
I assumed there would always be one array element for every candle that the indicator is calculated for, but are the input arrays supposed to be the same length?
My onStart() & calculate() code is below.
I would appreciate any advice.
Cheers
Tony
public void onStart(IIndicatorContext context) {
indicatorInfo = new IndicatorInfo("Spread", "Plots the bid-ask spread", "My indicators", false, false, false, 2, 0, 1)
{{ setRecalculateOnNewCandleOnly( true ); }};
inputParameterInfos = new InputParameterInfo[] {
new InputParameterInfo("Bid bar data", InputParameterInfo.Type.BAR) {{ setOfferSide(OfferSide.BID); }},
new InputParameterInfo("Ask bar data", InputParameterInfo.Type.BAR) {{ setOfferSide(OfferSide.ASK); }}
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
};
this.console = context.getConsole();
}
public IndicatorResult calculate(int startIndex, int endIndex) {
if (startIndex < 0) { // not sure if this is necesary
startIndex = 0;
}
console.getOut().println( String.format( "inputs[0].length = " + inputs[0].length + ", inputs[1].length = " + inputs[1].length ) );
int i, j;
for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
if ( inputs[1] != null ) { // check that 2nd input (ask bars) is fully loaded
outputs[0][j] = inputs[1][i].getClose() - inputs[0][i].getClose(); // ask close - bid close
}
else { // not fully loaded yet
outputs[0][j] = Double.NaN;
console.getOut().println( "2nd input array is not fully loaded." );
}
}
return new IndicatorResult(startIndex, j);
}