Dukascopy
 
 
Wiki JStore Search Login

APICLIENT-136 ArrayIndexOutOfBoundsException in IIndicators.ma(...) during backtest. JForex 2.17.11 JForexAPI 2.6.71
 Post subject: APICLIENT-136 ArrayIndexOutOfBoundsException in IIndicators.ma(...) during backtest. JForex 2.17.11 JForexAPI 2.6.71 Post rating: 0   New post Posted: Tue 19 Jun, 2012, 00:17 
User avatar

User rating: 1
Joined: Wed 18 May, 2011, 16:43
Posts: 10
Location: Czech Republic, Brno
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


 
 Post subject: Re: APICLIENT-136 ArrayIndexOutOfBoundsException in IIndicators.ma(...) during backtest. JForex 2.17.11 JForexAPI 2.6.71 Post rating: 0   New post Posted: Tue 19 Jun, 2012, 15:28 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Fixed in 2.17.11


 

Jump to:  

  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com