Hello,
Here is very simple example of program using IIndicators.ma(...) method. If you run this program in HISTORICAL TESTER of JForex DEMO you will receive following exception:
java.lang.ArrayIndexOutOfBoundsException: 0 @ example.Example.getLastEMA14(Example.java:29)
It seems that the received array of results is empty because the program is trying to take value with index 0 but because of ArrayIndexOutOfBoundsException it seems that there is no value with index 0. And because 0 is the first index in java arrays it means that the array is empty.
Here is the example code:
package example;
import com.dukascopy.api.*;
public class Example implements IStrategy {
private IContext context;
private IIndicators indicators;
@Override
public void onStart(IContext context) throws JFException {
this.context = context;
this.indicators = context.getIndicators();
}
@Override public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override public void onMessage(IMessage message) throws JFException {}
@Override public void onAccount(IAccount account) throws JFException {}
@Override public void onStop() throws JFException {}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (instrument.equals(Instrument.EURUSD) && period.equals(Period.ONE_HOUR)) {
double lastEMA14 = getLastEMA14(instrument, period, bidBar.getTime());
context.getConsole().getOut().println("Last EMA 14 = "+lastEMA14);
}
}
private double getLastEMA14(Instrument instrument, Period period, long currentTime) throws JFException {
return indicators.ma(instrument, period, OfferSide.BID, IIndicators.AppliedPrice.CLOSE, 14, IIndicators.MaType.EMA, Filter.WEEKENDS, 1, currentTime, 0)[0];
}
}
this is happening only in the JForex DEMO backtester.
In JForex LIVE backtester it is working properly.Please fix this bug of the JForex asap.Thank you
Have a nice day
Marek Lorenc