|
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.
Achieving Consistency for execution ? |
skt77
|
Post subject: Achieving Consistency for execution ? |
Post rating: 0
|
Posted: Mon 10 Aug, 2015, 07:38
|
|
User rating: 0
Joined: Mon 11 May, 2015, 23:19 Posts: 12 Location: United Kingdom, London
|
myLastTick = ahistory.getLastTick(myInstrument); System.out.println("going to perform if check WAITING Check "); if((rl[arraycounter].signalVALUE==20) && (myLastTick.getBid()>rl[arraycounter].myPRICE))
On one occasion, the above piece of code threw a null pointer exception and the next run, it went fine. What could be the reason and if it is a very comon phenomenon for code to throw exceptions, how do I prevent this ? Should every other piece of code go into a try catch block ?
SKT
|
|
|
|
 |
mcs
|
Post subject: Re: Achieving Consistency for execution ? |
Post rating: 0
|
Posted: Mon 10 Aug, 2015, 12:33
|
|
User rating: 4
Joined: Sat 12 May, 2012, 00:28 Posts: 21 Location: New Zealand, Auckland
|
Hi SKT,
getLastTick() and all other history-related methods in JForex are very unreliable and it is definitely better to wrap them into try/catch blocks.
In your case, however, that wouldn't have helped because it looks like getLastTick() returned null. It is known undocumented behaviour of getLastTick(). It returns null when there is no connection to the server (as far as I remember). There was a thread somewhere on this forum where this bug was reported, but the developers insisted that it is a feature, reasoning that if we are offline then we couldn't know the last tick. It is a pity that this bug/feature is still not documented.
Personally, I almost never use getLastTick(). In practice, it is much more reliable (and much faster) to process arriving ticks in onTick() method and store the relevant information in local variables. When you need last tick's data, just read it from local variables then.
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|