I coded indicator which use CSS (CurrencySlopeStrength indicator).
I want get array of double[8] and make some calculation with this.
My code give null pointer exception - in log file error is outside my indicator - in CSS indicator code:
context.getFeedDescriptor() == null.
I probably wrong initialize CSS indicator. Can you help me with this?
This is my code:
package jforex3;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.indicators.*;
public class paramCSSind implements IIndicator {
private IIndicatorContext context;
private IConsole console;
private IIndicator css;
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private IBar[][] inputs = new IBar[1][];
private double[][] outputs = new double[1][];
private double[][] outCSS;
int inpNr, inpOptNr, outNr;
public void onStart(IIndicatorContext context) {
this.context = context;
this.console = context.getConsole();
IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
css = indicatorsProvider.getIndicator("CSS");
IndicatorInfo infoCSS = css.getIndicatorInfo();
inpNr = infoCSS.getNumberOfInputs();
inpOptNr = infoCSS.getNumberOfOptionalInputs();
outNr = infoCSS.getNumberOfOutputs();
indicatorInfo = new IndicatorInfo("paramCSSind", "raw CSS for pair", "My indicators",
false, false, false, 1, 0, 1);
inputParameterInfos = new InputParameterInfo[] {
new InputParameterInfo("Bars", InputParameterInfo.Type.BAR)
};
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 = getLookback();
}
if (startIndex > endIndex) {
return new IndicatorResult(0, 0);
}
css.setInputParameter(0, inputs[0]);
double[][] outCSS = new double[outNr][endIndex - startIndex + 1];
for (int i = 0; i < outNr; i++) {
css.setOutputParameter(i, outCSS[i]);
}
console.getOut().format("%d %d %d %d %d %d \n", startIndex, endIndex, inputs.length, inputs[0].length, outCSS.length, outCSS[0].length );
css.calculate(0, inputs[0].length -1 );
int i, j;
for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
outputs[0][j] = outCSS[0][j];
console.getOut().format("%.3f ", outCSS[0][j] );
}
console.getOut().println();
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 0;
}
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] = (IBar[]) array;
}
public void setOptInputParameter(int index, Object value) {
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
}
Error in lines:
// my indicator
css.calculate(0, inputs[0].length -1 );
// css indicator
DataType dataType = context.getFeedDescriptor().getDataType();