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.

Testing question
 Post subject: Testing question Post rating: 0   New post Posted: Mon 23 Aug, 2010, 09:44 

User rating: 0
Joined: Wed 18 May, 2011, 11:25
Posts: 60
Location: DE
Hi,

at the weekend, i created some strategies and used the Tester to show the results. i used 1min, and depending on the time interval,
the testing chart showed 10min and 30min charts. i was not sure if i can test 1min invervals or so.

then i printed out the periods of the onBar event, and i saw, that there are all time periods available. i think now, if i want to use the
Test with e.g. 1min bars, i have to add following code:

    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
        // check the instrument, e.g. EURUSD
        if (instrument.name() != recentInstrument.name()) {
            return;
        }
        // check the time period
        if (Period.ONE_MIN.name() != period.name()) {
            return;
        }
   ....
   }


is this ok?


 
 Post subject: Re: Testing question Post rating: 0   New post Posted: Mon 23 Aug, 2010, 16:42 

User rating: 1
Joined: Fri 26 Mar, 2010, 19:19
Posts: 116
Location: Canada
looks fine
you can simplify it slightly by truncating the .names() for both enums

as in:

recentInstrument = Instrument.EURUSD;

...

if (instrument != recentInstrument)
...


 
 Post subject: Re: Testing question Post rating: 0   New post Posted: Mon 23 Aug, 2010, 23:27 

User rating: 0
Joined: Mon 07 Dec, 2009, 20:14
Posts: 14
No not ok.

In your code you are not comparing the values of the strings but the references to the string objects. Since your Java VM tries to save memory by storing identical strings only once in the string pool your program might work as expected but this is not guaranteed! Identical strings might reside twice on the heap and as a result have different reference values.

You should use the equals() method if you really need to compare the values of strings:

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
       // check the instrument, e.g. EURUSD
        if (!instrument.name().equals(recentInstrument.name())) {
            return;
        }
        // check the time period
        if (!Period.ONE_MIN.name().equals(period.name())) {
            return;
        }
   ....
   }


It's much better and faster however to compare the reference values of the ENUM objects directly.

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
       // check the instrument, e.g. EURUSD
        if (instrument != recentInstrument) {
            return;
        }
        // check the time period
        if (Period.ONE_MIN != period) {
            return;
        }
    }


 

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