Good day!
I'm currently trying to call Ichimoku indicator from within another indicator to get its values, manipulate them
and get some other lines. I searched through this forum, found solution posted by Dukascopy Support,
used it and... got exception:
Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to [[D
at com.dukascopy.indicators.IchimokuIndicator.setInputParameter(IchimokuIndicator.java:188)
at jforex.Indicator.setOptInputParameter(Indicator.java:102)
at com.dukascopy.charts.math.dataprovider.AbstractDataProvider.b(L:677)
at com.dukascopy.charts.math.dataprovider.AbstractDataProvider.i(L:479)
at com.dukascopy.charts.data.a.i(L:538)
at com.dukascopy.charts.chartbuilder.ah.a(L:79)
... 41 more
The code looks like this:
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 Indicator 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 ichiIndicator;
public void onStart(IIndicatorContext context) {
IIndicatorsProvider provider = context.getIndicatorsProvider();
ichiIndicator = context.getIndicatorsProvider().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];
ichiIndicator.setInputParameter(0, inputs[0]);
ichiIndicator.setOutputParameter(0, tenkanOutput);
ichiIndicator.setOutputParameter(1, new double[endIndex - startIndex + 1]);
ichiIndicator.setOutputParameter(2, new double[endIndex - startIndex + 1]);
ichiIndicator.setOutputParameter(3, new double[endIndex - startIndex + 1]);
ichiIndicator.setOutputParameter(4, new double[endIndex - startIndex + 1]);
ichiIndicator.setOutputParameter(5 , new Object[endIndex - startIndex + 1]);
IndicatorResult res = ichiIndicator.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 ichiIndicator.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:
ichiIndicator.setInputParameter(0, value); \\<= line 102
break;
case 1:
ichiIndicator.setOptInputParameter(1, value);
break;
case 2:
ichiIndicator.setOptInputParameter(2, value);
break;
default:
throw new ArrayIndexOutOfBoundsException(index);
}
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
}
Regards
Marcin