Hi,
Please have a look at the following code:
package jforex;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IIndicatorContext;
import com.dukascopy.api.indicators.IIndicatorsProvider;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.IndicatorResult;
import com.dukascopy.api.indicators.InputParameterInfo;
import com.dukascopy.api.indicators.IntegerRangeDescription;
import com.dukascopy.api.indicators.OptInputParameterInfo;
import com.dukascopy.api.indicators.OutputParameterInfo;
public class IchimokuTenkanIndicator implements IIndicator{
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private double[][][] inputs = new double[1][][];
private double[][] outputs = new double[1][];
private IIndicator ichimoku;
public void onStart(IIndicatorContext context) {
IIndicatorsProvider provider = context.getIndicatorsProvider();
ichimoku = provider.getIndicator("ICHIMOKU");
indicatorInfo = new IndicatorInfo("ICHIMOKUTENKAN", "Ichimoku tenkan", "", true, false, true, 1, 3, 1);
inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)};
optInputParameterInfos = new OptInputParameterInfo[] {
new OptInputParameterInfo("Tenkan", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(9, 2, 400, 1)),
new OptInputParameterInfo("Kijun", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(26, 2, 400, 1)),
new OptInputParameterInfo("Senkou", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(52, 2, 400, 1))
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("Tenkan Sen", 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[] tenkanOutput = new double[endIndex - startIndex + 1];
ichimoku.setInputParameter(0, inputs[0]);
ichimoku.setOutputParameter(0, tenkanOutput);
ichimoku.setOutputParameter(1, new double[endIndex - startIndex + 1]);
ichimoku.setOutputParameter(2, new double[endIndex - startIndex + 1]);
ichimoku.setOutputParameter(3, new double[endIndex - startIndex + 1]);
ichimoku.setOutputParameter(4, new double[endIndex - startIndex + 1]);
ichimoku.setOutputParameter(5 , new Object[endIndex - startIndex + 1]);
IndicatorResult res = ichimoku.calculate(startIndex, endIndex);
for (int i = 0; i < res.getNumberOfElements(); i++){
outputs[0][i] = tenkanOutput[i];
}
return res;
}
public IndicatorInfo getIndicatorInfo() {
return indicatorInfo;
}
public InputParameterInfo getInputParameterInfo(int index) {
if (index <= inputParameterInfos.length) {
return inputParameterInfos[index];
}
return null;
}
public int getLookback() {
return ichimoku.getLookback();
}
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) {
switch (index) {
case 0:
ichimoku.setOptInputParameter(0, value);
break;
case 1:
ichimoku.setOptInputParameter(1, value);
break;
case 2:
ichimoku.setOptInputParameter(2, value);
break;
default:
throw new ArrayIndexOutOfBoundsException(index);
}
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
}