Hi, Support,
Through the calculation to get outputs[0][resIndex] = AB[i],
the AB[i] is not a standard indicator. How to get the average value of the AB[i] (That is outputs[1][resIndex] )?
Why now the outputs[1][resIndex] are all zero?
Can you help me?
Thank you.
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];
if(i >=1 )
{
AB[i] = inputs[0][2][i] + inputs[0][2][i-1] + inputs[0][0][i] + inputs[0][0][i-1] + inputs[0][3][i] + inputs[0][3][i-1] + inputs[0][2][i] + inputs[0][2][i-1];
}
else
{
AB[i] = 0;
}
outputs[0][resIndex] = AB[i];
//???????????????????????????????????????????????????????????+
double x3 = 0;
for(int j =i; j<=i-2; j--)
{
x3 += outputs[0][j];
}
outputs[1][resIndex] = x3/3;
//???????????????????????????????????????????????????????????+
}
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;
}
}
//+////////////////////////////////////////////////////////////////////////////+