Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Strategy tester: java.lang.ArrayIndexOutOfBoundsException
 Post subject: Strategy tester: java.lang.ArrayIndexOutOfBoundsException Post rating: 0   New post Posted: Mon 08 Sep, 2014, 19:47 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
I've started to see these messages while I am try to calculate stochRSI in the Historical Tester. These exceptions only appearing during the first couple of calls of onBar().
When running the test on last year's data, the exceptions appearing till the bar 21:00 is being processed. After that everything runs normal, without the exceptions.

I think I am doing exactly the same things I've used to do in the past (around February). Was anything changed in the way the Historical Tester must be used?

A simple strategy that replicates the issues:
package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IIndicators.MaType;

public class Strategy1 implements IStrategy {
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;

    @Configurable("Instrument")
    public Instrument selectedInstrument = Instrument.EURUSD;
    @Configurable("Period")
    public Period selectedPeriod = Period.THIRTY_MINS;
    @Configurable("sRSI Time Period")
    public int timePeriod  = 14;
    @Configurable("sRSI Fast K Period")
    public int fastKPeriod = 5 ;
    @Configurable("sRSI Fast D Period")
    public int fastDPeriod = 3;
    @Configurable("Applied Price")
    public AppliedPrice appliedPrice = AppliedPrice.CLOSE;
    @Configurable("Indicator Filter")
    public Filter indicatorFilter = Filter.WEEKENDS;   

    public void onStart(IContext context) throws JFException {
        this.engine = context.getEngine();
        this.console = context.getConsole();
        this.history = context.getHistory();
        this.context = context;
        this.indicators = context.getIndicators();
        this.userInterface = context.getUserInterface();
    }

    public void onAccount(IAccount account) throws JFException {
    }

    public void onMessage(IMessage message) throws JFException {
    }

    public void onStop() throws JFException {
    }

    public void onTick(Instrument instrument, ITick tick) throws JFException {
    }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        IBar       prevBar;
        double[][] stochRSI;

        if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod))) {
            prevBar = history.getBar(instrument, selectedPeriod, OfferSide.BID, 1);
            console.getOut().println("prevBar:" + prevBar);
            stochRSI = indicators.stochRsi(instrument, selectedPeriod, OfferSide.BID, appliedPrice, timePeriod, fastKPeriod, fastDPeriod, MaType.SMA, indicatorFilter, 1, prevBar.getTime(), 1);
        }
    }
}


A sample of the output messages:
Note: the last messages were printed first. So till I start processing bar 21:00 on a 30M chart, these exceptions are present.
2014-09-08 18:39:27   prevBar:1378108800000[2013-09-02 08:00:00.000+0000] O: 1.32103 C: 1.3211 H: 1.32176 L: 1.32069 V: 5945.57
2014-09-08 18:39:27   prevBar:1378107000000[2013-09-02 07:30:00.000+0000] O: 1.32223 C: 1.32103 H: 1.32241 L: 1.32093 V: 6907.73
2014-09-08 18:39:27   prevBar:1378105200000[2013-09-02 07:00:00.000+0000] O: 1.32165 C: 1.32223 H: 1.3227 L: 1.32163 V: 6648.08
2014-09-08 18:39:27   prevBar:1378103400000[2013-09-02 06:30:00.000+0000] O: 1.32167 C: 1.32165 H: 1.32243 L: 1.32142 V: 4461.0
2014-09-08 18:39:27   prevBar:1378101600000[2013-09-02 06:00:00.000+0000] O: 1.32103 C: 1.32168 H: 1.32213 L: 1.32102 V: 4240.31
2014-09-08 18:39:27   prevBar:1378099800000[2013-09-02 05:30:00.000+0000] O: 1.32058 C: 1.32104 H: 1.3214 L: 1.32058 V: 1969.74
2014-09-08 18:39:27   prevBar:1378098000000[2013-09-02 05:00:00.000+0000] O: 1.32013 C: 1.32058 H: 1.32058 L: 1.32009 V: 1460.54
2014-09-08 18:39:27   prevBar:1378096200000[2013-09-02 04:30:00.000+0000] O: 1.32056 C: 1.32013 H: 1.3207 L: 1.31965 V: 2179.25
2014-09-08 18:39:27   prevBar:1378094400000[2013-09-02 04:00:00.000+0000] O: 1.32071 C: 1.32057 H: 1.32108 L: 1.32057 V: 979.73
2014-09-08 18:39:27   prevBar:1378092600000[2013-09-02 03:30:00.000+0000] O: 1.32061 C: 1.32071 H: 1.321 L: 1.32039 V: 1750.3
2014-09-08 18:39:27   prevBar:1378090800000[2013-09-02 03:00:00.000+0000] O: 1.32034 C: 1.32061 H: 1.32077 L: 1.32025 V: 1928.56
2014-09-08 18:39:27   prevBar:1378089000000[2013-09-02 02:30:00.000+0000] O: 1.32037 C: 1.32034 H: 1.32039 L: 1.32006 V: 1025.01
2014-09-08 18:39:26   prevBar:1378087200000[2013-09-02 02:00:00.000+0000] O: 1.3209 C: 1.32035 H: 1.32091 L: 1.32009 V: 1374.53
2014-09-08 18:39:26   prevBar:1378085400000[2013-09-02 01:30:00.000+0000] O: 1.32051 C: 1.32091 H: 1.32104 L: 1.32027 V: 1788.86
2014-09-08 18:39:26   prevBar:1378083600000[2013-09-02 01:00:00.000+0000] O: 1.31971 C: 1.32052 H: 1.32062 L: 1.31971 V: 1900.89
2014-09-08 18:39:26   prevBar:1378081800000[2013-09-02 00:30:00.000+0000] O: 1.31955 C: 1.31972 H: 1.31973 L: 1.31914 V: 1902.82
2014-09-08 18:39:26   prevBar:1378080000000[2013-09-02 00:00:00.000+0000] O: 1.32067 C: 1.31954 H: 1.32081 L: 1.31929 V: 1848.96
2014-09-08 18:39:26   prevBar:1378078200000[2013-09-01 23:30:00.000+0000] O: 1.32064 C: 1.32067 H: 1.32101 L: 1.32052 V: 831.95
2014-09-08 18:39:26   prevBar:1378076400000[2013-09-01 23:00:00.000+0000] O: 1.3201 C: 1.32065 H: 1.32065 L: 1.31965 V: 682.6
2014-09-08 18:39:26   prevBar:1378074600000[2013-09-01 22:30:00.000+0000] O: 1.32124 C: 1.3201 H: 1.32133 L: 1.31998 V: 1317.49
2014-09-08 18:39:26   prevBar:1378072800000[2013-09-01 22:00:00.000+0000] O: 1.32127 C: 1.32123 H: 1.32141 L: 1.3208 V: 668.78
2014-09-08 18:39:26   prevBar:1378071000000[2013-09-01 21:30:00.000+0000] O: 1.32073 C: 1.32131 H: 1.32146 L: 1.32065 V: 212.77
2014-09-08 18:39:26   prevBar:1378069200000[2013-09-01 21:00:00.000+0000] O: 1.32108 C: 1.32073 H: 1.3215 L: 1.3203 V: 300.84
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378067400000(2013-09-01 20:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378065600000(2013-09-01 20:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378063800000(2013-09-01 19:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378062000000(2013-09-01 19:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378060200000(2013-09-01 18:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378058400000(2013-09-01 18:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378056600000(2013-09-01 17:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378054800000(2013-09-01 17:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378053000000(2013-09-01 16:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378051200000(2013-09-01 16:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378049400000(2013-09-01 15:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378047600000(2013-09-01 15:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378045800000(2013-09-01 14:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378044000000(2013-09-01 14:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378042200000(2013-09-01 13:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378040400000(2013-09-01 13:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378038600000(2013-09-01 12:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378036800000(2013-09-01 12:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378035000000(2013-09-01 11:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378033200000(2013-09-01 11:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378031400000(2013-09-01 10:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378029600000(2013-09-01 10:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378027800000(2013-09-01 09:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378026000000(2013-09-01 09:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378024200000(2013-09-01 08:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378022400000(2013-09-01 08:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378020600000(2013-09-01 07:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378018800000(2013-09-01 07:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378017000000(2013-09-01 06:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378015200000(2013-09-01 06:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378013400000(2013-09-01 05:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378011600000(2013-09-01 05:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378009800000(2013-09-01 04:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378008000000(2013-09-01 04:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378006200000(2013-09-01 03:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378004400000(2013-09-01 03:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:26   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:26   prevBar:{T:1378002600000(2013-09-01 02:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:25   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:25   prevBar:{T:1378000800000(2013-09-01 02:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:25   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:25   prevBar:{T:1377999000000(2013-09-01 01:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:25   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:25   prevBar:{T:1377997200000(2013-09-01 01:00:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:25   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:25   prevBar:{T:1377995400000(2013-09-01 00:30:00.000+0000) E:false O:1.32208 C:1.32208 L:1.32208 H:1.32208 V:0.0}
2014-09-08 18:39:25   Strategy tester: java.lang.ArrayIndexOutOfBoundsException
2014-09-08 18:39:25   prevBar:1377993600000[2013-09-01 00:00:00.000+0000] O: 1.32208 C: 1.32208 H: 1.32208 L: 1.32208 V: 0.0



Please give me a hint about what to do.


 
 Post subject: Re: Strategy tester: java.lang.ArrayIndexOutOfBoundsException Post rating: 0   New post Posted: Wed 10 Sep, 2014, 13:18 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
Hint 1:
Image

Hint 2:
Image

Hint 3:
Image

Note: But, these hints can't explains about line 24's error of "a sample of the output messages" :lol:


Attachments:
hint3.png [29.81 KiB]
Downloaded 244 times
hint2.jpg [23.37 KiB]
Downloaded 287 times
hint1.gif [28.33 KiB]
Downloaded 333 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Strategy tester: java.lang.ArrayIndexOutOfBoundsException Post rating: 0   New post Posted: Thu 11 Sep, 2014, 09:41 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Hint1 is good.
Market opens on Sunday 21:00 (if I am not mistaken), so this could be the case. I will test with another testing period (starting on a weekday).
But even if that is the case, why does the Filter.WEEKEND not handle this properly?

Anyway, thanks for the hint, I will look into it.


 
 Post subject: Re: Strategy tester: java.lang.ArrayIndexOutOfBoundsException Post rating: 0   New post Posted: Thu 11 Sep, 2014, 17:28 
User avatar

User rating: 7
Joined: Tue 28 Feb, 2012, 09:45
Posts: 45
Location: JapanJapan
Hint 3.1: stochRSI = indicators.stochRsi(..., :D , prevBar.getTime(), :o) :
Image

Hint 4: Can You get him when you use the WEEKENDS_FILTER?
Image
If current manager van Gaal is Saturday 23:00(BST), Can You get someone who is a one of the managers after the Ryan Giggs(=prevBar)?
Even if You use a weekends filter?

Anyway: Sorry, This hypothesis can't explain about Error at Sun. 21:00GMT(prevBar time is Sun. 20:30GMT) :?


Attachments:
hint3_fix.png [33.84 KiB]
Downloaded 276 times
hint4.jpg [14.97 KiB]
Downloaded 248 times
hint3_fix.png [33.31 KiB]
Downloaded 208 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

  © 1998-2025 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