Consider the following indicator:
package jforex.indicators;
import com.dukascopy.api.*;
import com.dukascopy.api.indicators.*;
public class FractalSimple implements IIndicator{
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private double[][][] inputs = new double[2][][];
private double[][] outputs = new double[2][];
//private int barsOnSides = 2;
private IConsole console;
public void onStart(IIndicatorContext context) {
console = context.getConsole();
indicatorInfo = new IndicatorInfo("FRACTAL SIMPLE", "Fractal indicator simple", "Custom Indicators", true, false, false, 1, 0, 2);
inputParameterInfos = new InputParameterInfo[] {
new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("Maximums", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_DOWN),
new OutputParameterInfo("Minimums", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.ARROW_SYMBOL_UP)
};
}
public IndicatorResult calculate(int startIndex, int endIndex) {
//calculating startIndex taking into account lookback value
if (startIndex - getLookback() < 0) {
startIndex -= startIndex - getLookback();
}
//calculating endIndex taking into account lookforward value
if (endIndex + getLookforward() >= inputs[0][0].length) {
endIndex = inputs[0][0].length - 1 - getLookforward();
}
if (startIndex > endIndex) {
return new IndicatorResult(0, 0);
}
//inputs[0 = InputParameterInfo.Type.PRICE][0 = open, 1 = close, 2 = high, 3 = low, 4 = volume][0 = previous bar, 1 = current bar]
//up arrow
outputs[1][0] = inputs[0][2][1] > inputs[0][2][0] ? inputs[0][2][1] : Double.NaN;
//down arrow
outputs[0][0] = inputs[0][3][1] < inputs[0][3][0] ? inputs[0][3][1] : Double.NaN;
return new IndicatorResult(startIndex, endIndex - startIndex + 1, endIndex);
}
public IndicatorInfo getIndicatorInfo() {
return indicatorInfo;
}
public InputParameterInfo getInputParameterInfo(int index) {
if (index <= inputParameterInfos.length) {
return inputParameterInfos[index];
}
return null;
}
//we are only interested in values of the previous bar
public int getLookback() {
return 1;
}
//we are not interested in any of next bars
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) {
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
private void print(Object o){
this.console.getOut().println(o);
}
}