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.

How to trap JFexceptions ?
 Post subject: How to trap JFexceptions ? Post rating: 0   New post Posted: Wed 24 Dec, 2008, 05:23 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
Hi! This is a request to the mods. Can you please provide a few examples on how to effectively trap JFExceptions and to deal with common errors without the exception causing the Strategy to stop? In my code, whenever an exception occurs, onStop is called and the Strategy stops every time (which is quite annoying). Any information about bypassing this would be most appreciated.


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Wed 24 Dec, 2008, 09:55 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi, I suggest you to fix all the situations, that lead to this exception. If it's not suitable for you, then try {...} catch them in every method:
public void onTick (Instrument instrument, ITick tick) throws JFException {
    try {
        //your code here
    } catch (JFException e) {
        console.getErr().println(e.getMessage());
    }
}


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Tue 13 Jan, 2009, 16:01 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
Hi Dmitry, I used the above error trap handler you posted. It works well to prevent errors when submitting orders but the Strategy still halts for other errors such as "Orders data unavailable" or "Thread queue overflow". Where else should i place the error handler in my Strategy code order to prevent it from being terminated?


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Tue 13 Jan, 2009, 17:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can't for now, there will be a fix that will reduce or maybe eliminate at all "Thread queue overflow" problem. Same with "Orders data unavailable", we are going to change the logic in that place, can't give you the estimates though.


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Thu 15 Jan, 2009, 12:02 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
But if this is the case then, it makes your platform kinda unreliable simply because I will have to monitor the script every now and then just to make sure that it hasn't been terminated due to either of these errors. Sigh! I thought things would be easier with JForex...

By the way, I'm still having problems even though I included the error exception handler you posted above. Here's the other error that caused the script to terminate-> BUY ERROR: AMOUNT TOO SMALL (this happened when the script attempted to send an order with 0.01 lots). I can certainly set the lots to a minimum of 0.1 but I don't see why the script should be stopped for such an error. Initially, when I used your error exception handler, it trapped such errors without stopping the Strategy... but now, it doesn't work as well as it used to. I haven't changed any code in the error handler. Please see below. I can't figure out what the problem could be:

try {
    IOrder buyorder  = engine.submitOrder(ticket, instrument, IEngine.OrderCommand.BUY, lot, 0, 0, stopLoss, takeProfit);
    buyorder.waitForUpdate(5000);
 } catch (JFException e) {
    printerr("BUY ERROR: " + e.getMessage());
}                

printerr is a function that does the same thing as console.getErr().println...


Here's a question for ya: is the onStop function executed just before the script is terminated? If so, is there a way to prevent onStop from executing so that the script can continue to run even if such errors occur? If we put in a return(1) in onStop, does it prevent the script from terminating?


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Thu 15 Jan, 2009, 13:53 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
"Thread queue overflow" happens when onTick method is too slow to process all ticks. The ticks are being gathered in the queue. When a limit is reached, the platform stops the strategy. There is no problem in JForex platform, but in the strategy. We are going to change this by dropping old unprocessed the ticks.
"Orders data unavailable" problem is something new. We don't realy know why it happens. But, most likely, there must be some specific conditions.

The stopping of strategy on every JFException helps users to find all possible errors. It allows to fix the erros while testing on demo.
We will think about changing this behavior for the real trading system. Maybe we will put this in settings.


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Fri 16 Jan, 2009, 05:00 

User rating: 0
Joined: Mon 22 Dec, 2008, 13:00
Posts: 17
Thank you for explaining that error, Dmitry. I shall modify my strategy accordingly. In the meantime, here is another error i received and the strategy just stopped without any further description:

06:32:10 java.lang.NumberFormatException: null @ jforex.Strategy1.onTick(Strategy1.java:133)

I know this might seem like a total newbie question, but how can i prevent the above error from occurring? And is there a webpage you can recommend that describes such errors?


 
 Post subject: Re: How to trap JFexceptions ? Post rating: 0   New post Posted: Fri 16 Jan, 2009, 08:58 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
That means you are trying to parse number and pass null variable as a parameter. It's easy to find the cause after you read when that exception is thrown. Read Java API - https://java.sun.com/javase/6/docs/api/index.html or use google :)


 

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