Hi, all. I'm having trouble doing something that should be very simple, which is to set up and use arrays other than the inputs and outputs. I'd like to perform calculations on the underlying inputs and store the calculations in arrays and perform a regression on the calculated values. The problem is that I'm new to programming.
I realize that there is code on the Wiki page which utilizes outputs from other indicators, but it will be much easier for me to use my own arrays because this could get pretty complicated.
I'm trying to do something very simple and I've gotten it to work other than the fact that, once the indicator is run in the chart, the last output and all following outputs (once new bars are created) are 0. I'm not sure why that might be. Here's the code which aims to store the price of each bar in the holders[][] array and then shift the prices forward 3 periods (so call the price 3 periods ago) between the holders[][] and outputs[][] arrays.
package jforex;
import com.dukascopy.api.indicators.*;
public class HolderTest2 implements IIndicator {
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private double[][][] inputs = new double[1][][];
private int timePeriod = 3;
private double[][] outputs = new double[1][];
public void onStart(IIndicatorContext context) {
indicatorInfo = new IndicatorInfo("Holder Test2", "Holder Test2", "My indicators",
false, false, false, 1, 1, 1);
inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Input data", InputParameterInfo.Type.PRICE)};
optInputParameterInfos = new OptInputParameterInfo[] {new OptInputParameterInfo("Time period", OptInputParameterInfo.Type.OTHER,
new IntegerRangeDescription(3, 2, 100, 1))};
outputParameterInfos = new OutputParameterInfo[] {new OutputParameterInfo("out", OutputParameterInfo.Type.DOUBLE,
OutputParameterInfo.DrawingStyle.LINE)};
}
public IndicatorResult calculate(int startIndex, int endIndex) {
//calculating startIndex taking into account lookback value
if (startIndex - getLookback() < 0) {
startIndex -= startIndex - getLookback();
}
int length = endIndex - startIndex + 1;
double[][] holder = new double[1][length];
int i, j;
for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
holder[0][j] = inputs[0][2][i];
}
int y, z;
for (y = startIndex + 3, z = 3; y <= endIndex; y++, z++) {
outputs[0][z] = holder[0][z - 3];
}
return new IndicatorResult(startIndex, j);
}
public IndicatorInfo getIndicatorInfo() {
return indicatorInfo;
}
public InputParameterInfo getInputParameterInfo(int index) {
if (index <= inputParameterInfos.length) {
return inputParameterInfos[index];
}
return null;
}
public int getLookback() {
return timePeriod;
}
public int getLookforward() {
return 0;
}
public OptInputParameterInfo getOptInputParameterInfo(int index) {
if (index <= optInputParameterInfos.length) {
return optInputParameterInfos[index];
}
return null;
}
public OutputParameterInfo getOutputParameterInfo(int index) {
if (index <= outputParameterInfos.length) {
return outputParameterInfos[index];
}
return null;
}
public void setInputParameter(int index, Object array) {
inputs[index] = (double[][]) array;
}
public void setOptInputParameter(int index, Object value) {
timePeriod = (Integer) value;
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
}
The top indicator in the two pictures simply pulls the price for the current bar. The code above is for the bottom indicator. The first picture is what the indicator looks like when showing the last few bars. As you can see, the indicator returns 0 for several periods. The second picture is what it looks like before that, when I scroll backwards in time - it appears to be working exactly like I had hoped.
Any help?

