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.

Null pointer
 Post subject: Null pointer Post rating: 0   New post Posted: Tue 06 Aug, 2013, 13:51 
User avatar

User rating: 1
Joined: Sun 18 Dec, 2011, 04:05
Posts: 36
Location: Spain, Madrid
Hi, sometimes Jforex show an Exception (java.lang.NullException) on the following line:

Void buyUSD() throws JFException{
.......
......
double precio = history.getLastTick(instrument).getBid(); <----- here
......
......
}

this happend just sometimes. can anyone knows why?

Best Regards


 
 Post subject: Re: Null pointer Post rating: 0   New post Posted: Thu 08 Aug, 2013, 15:12 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If the instrument just has been subscribed, there may not have been any ticks for the instrument.


 
 Post subject: Re: Null pointer Post rating: 0   New post Posted: Wed 21 Aug, 2013, 19:46 
User avatar

User rating: 1
Joined: Sun 18 Dec, 2011, 04:05
Posts: 36
Location: Spain, Madrid
Hi,

The problem remains

void buyGBP()throws JFException{

Instrument instrument = Instrument.EURGBP;
.....
.....
double price = history.getLastTick(instrument).getBid();

}

So, should i add Thread.sleep(XXXX);....before getLastTick??

Best Regards


 
 Post subject: Re: Null pointer Post rating: 0   New post Posted: Thu 22 Aug, 2013, 09:20 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You should call sleep while the history.getLastTick(instrument)=null, e.g.:
//wait max 10 secs
while(history.getLastTick(instrument) == null && i < 10){
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
    console.getOut().println("Last tick for " + instrument + " at " + DateUtils.format(System.currentTimeMillis())+ " is null");
    i++;
}
Or alternatively you can do you processing as soon as you receive the first tick in the onTick of the respective instrument - this will not hold up your other strategy executions.


 

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