Hi,
i want to show the absolute range of the bars as indicators. it works well, if i don't want to show
the absolute values, that means if i only use the difference between the input values.
e.g. 1.3047 - 1.3037 --> 0.0010
but i want to use the absolute value --> 10 pips
this can be done with the instrument.getPipScale() ... but when i try to get the instrument, it is
always null and i don't know why.
my code:
package jforex;
import com.dukascopy.api.IConsole;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.indicators.*;
import java.awt.*;
public class Absolute_Range3 implements IIndicator {
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private OptInputParameterInfo[] optInputParameterInfos;
private double[][][] inputs = new double[1][][];
private double[][] outputs = new double[3][];
private Instrument recentInstrument;
private IConsole console;
public void onStart(IIndicatorContext context) {
recentInstrument = context.getInstrument();
console = context.getConsole();
indicatorInfo = new IndicatorInfo("Absolute_Range3", "Range indicator", "LAB", false, false, true, 1, 0, 3);
inputParameterInfos = new InputParameterInfo[] {
new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("Up", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM)
{{
setColor(Color.GREEN);
}},
new OutputParameterInfo("Down", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM)
{{
setColor(Color.RED);
}},
new OutputParameterInfo("Side", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM)
{{
setColor(Color.BLUE);
}}
};
}
public IndicatorResult calculate(int startIndex, int endIndex) {
//calculating startIndex taking into account lookback value
if (startIndex - getLookback() < 0) {
startIndex -= startIndex - getLookback();
}
if (startIndex > endIndex) {
return new IndicatorResult(0, 0);
}
int i = 0;
Double recentDiff = null;
for(i=startIndex+1; i <= endIndex; i++){
recentDiff = inputs[0][0][i] - inputs[0][1][i];
//recentDiff = recentDiff * Math.pow(10, recentInstrument.getPipScale());
recentDiff = recentDiff * 10000;
console.getOut().println("recentInstrument: " + recentInstrument);
if (recentInstrument != null) {
console.getOut().println("recentInstrument.getPipScale(): " + recentInstrument.getPipScale());
console.getOut().println("Math.pow(10, recentInstrument.getPipScale()): " + Math.pow(10, recentInstrument.getPipScale()));
}
if (recentDiff < 0) {
recentDiff = -recentDiff;
}
if (inputs[0][1][i] > inputs[0][0][i]) {
outputs[0][i] = recentDiff;
}
else if (inputs[0][1][i] < inputs[0][0][i]) {
outputs[1][i] = recentDiff;
}
else {
outputs[2][i] = recentDiff;
}
}
return new IndicatorResult(startIndex, i);
}
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 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 OptInputParameterInfo getOptInputParameterInfo(int index) {
if (index <= optInputParameterInfos.length) {
return optInputParameterInfos[index];
}
return null;
}
public void setOptInputParameter(int index, Object value) {
}
public void setOutputParameter(int index, Object array) {
outputs[index] = (double[]) array;
}
public int getLookforward() {
return 0;
}
}