Hello support,
Im in a process of coding SWFX Sentiment indicator (couldnt find one on wiki or on forums)
I've noticed that each time I call
getFXSentimentIndex(Instrument instrument, long time)
JForex client hangs (has to kill jvm in task manager and restart client).
After changing to
getFXSentimentIndex(Instrument instrument)
indicator works fine but its not what I need.
Another thing is following call:
this.ds = context.getDataService();
It crashes with java.lang.SecurityException unless indicator class is decorated with @RequiresFullAccess
Please provide more information on this, why getDataService() call requires this.
Am I doing something wrong?
I will appreciate any help.
My code:
import com.dukascopy.api.IBar;
import com.dukascopy.api.IFXSentimentIndex;
import com.dukascopy.api.IDataService;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IIndicatorContext;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.IndicatorResult;
import com.dukascopy.api.indicators.InputParameterInfo;
import com.dukascopy.api.indicators.OptInputParameterInfo;
import com.dukascopy.api.indicators.OutputParameterInfo;
import com.dukascopy.api.Instrument;
import com.dukascopy.api.RequiresFullAccess;
@RequiresFullAccess
public class SSI_Indicator implements IIndicator {
private IndicatorInfo indicatorInfo;
private InputParameterInfo[] inputParameterInfos;
private OutputParameterInfo[] outputParameterInfos;
private IBar[][] inputs = new IBar[1][];
private IDataService ds;
private Instrument instrument;
public void onStart(IIndicatorContext context) {
this.ds = context.getDataService();
this.instrument = Instrument.USDJPY;
indicatorInfo = new IndicatorInfo("SWFX_SSI", "Sentiment index", "", false, false, false, 1, 0, 1);
inputParameterInfos = new InputParameterInfo[] {
new InputParameterInfo("Price", InputParameterInfo.Type.BAR)
};
outputParameterInfos = new OutputParameterInfo[] {
new OutputParameterInfo("SSI", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.HISTOGRAM)
};
}
public IndicatorResult calculate(int startIndex, int endIndex) {
IFXSentimentIndex ssi = null;
int i, j;
for (i = startIndex, j = 0; i <= endIndex; i++, j++) {
if (this.ds == null) outputs[0][j] = Double.NaN; else {
ssi = this.ds.getFXSentimentIndex(this.instrument, inputs[0][i].getTime()); // this one hangs JForex client
ssi = this.ds.getFXSentimentIndex(this.instrument); // this one works
if (ssi == null) {
outputs[0][j] = Double.NaN;
} else {
outputs[0][j] = ssi.getIndexValue();
}
}
}
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) {
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;
}
}