Hi, support,
In my Indicators, can get basis value, but can't get the average value.
For example, the following codes. The Messages show:"14:16:19 Error in indicator: java.lang.ArrayIndexOutOfBoundsException: -1 @ jforex.BarFour2.calculate(BarFour2.java:66)".
If the output "outputs[1][resIndex] = 2*AB[i];", can get the right result.
If the output "outputs[1][resIndex] = x3/3;", will an error has occurred.
would you please tell me how to get the correct "x3 += AB[j]" ?
Thank you very much.
package jforex;
import com.dukascopy.api.indicators.*;
//+===================================================================================+
public class BarFour2 implements IIndicator
{
public static final int OPEN = 0;
public static final int CLOSE = 1;
public static final int MIN = 2;
public static final int MAX = 3;
public static final int AVE = 4;
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private double[][][] inputs = new double[1][][];
private double[][] outputs = new double[2][];
//+---------------------------------------------------------------------------------+
public void onStart(IIndicatorContext context)
{
indicatorInfo = new IndicatorInfo("ABsum", "ABsum", "Custom", false, true, false, 1, 0, 2);
inputParameterInfos = new InputParameterInfo[]
{
new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)
};
outputParameterInfos = new OutputParameterInfo[]
{
new OutputParameterInfo("Line1", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE),
new OutputParameterInfo("Line2", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)
};
}
//+--------------------------------------------------------------------------------+
public IndicatorResult calculate(int startIndex, int endIndex)
{
if (startIndex - getLookback() < 0)
{
startIndex -= startIndex - getLookback();
}
if (startIndex > endIndex)
{
return new IndicatorResult(0, 0);
}
double[] AB = new double[endIndex - startIndex + 1];
int resIndex = 0;
for (int i = startIndex; i <= endIndex; i++, resIndex++)
{
double[] candle = new double[4];
candle[OPEN] = inputs[0][0][i];
candle[CLOSE] = inputs[0][1][i] ;
candle[MAX] = inputs[0][2][i];
candle[MIN] = inputs[0][3][i];
AB[i] = (inputs[0][2][i] - inputs[0][3][i])/2;
outputs[0][resIndex] = AB[i];
double x3 = 0;
for(int j=i; j>=i-2; j--)
{
x3 += AB[j];
}
outputs[1][resIndex] = x3/3; //2*AB[i];
}
return new IndicatorResult(startIndex, resIndex);
}
//+--------------------------------------------------------------------------------+
public IndicatorInfo getIndicatorInfo()
{
return indicatorInfo;
}
//+--------------------------------------------------------------------------------+
public InputParameterInfo getInputParameterInfo(int index)
{
if (index <= inputParameterInfos.length)
{
return inputParameterInfos[index];
}
return null;
}
//+--------------------------------------------------------------------------------+
public int getLookback()
{
return 0;
}
//+--------------------------------------------------------------------------------+
public OutputParameterInfo getOutputParameterInfo(int index)
{
if (index <= outputParameterInfos.length)
{
return outputParameterInfos[index];
}
return null;
}
//+--------------------------------------------------------------------------------+
public void setInputParameter(int index, Object array)
{
inputs[0] = (double[][]) array;
}
//+--------------------------------------------------------------------------------+
public OptInputParameterInfo getOptInputParameterInfo(int index)
{
return null;
}
//+--------------------------------------------------------------------------------+
public void setOptInputParameter(int index, Object value)
{
}
//+--------------------------------------------------------------------------------+
public void setOutputParameter(int index, Object array)
{
outputs[index] = (double[]) array;
}
//+--------------------------------------------------------------------------------+
public int getLookforward()
{
return 0;
}
}
//+////////////////////////////////////////////////////////////////////////////+