Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

How to trap JFexceptions ?
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=65&t=245
Page 1 of 1

Author:  [teknomage] [ Wed 24 Dec, 2008, 05:23 ]
Post subject:  How to trap JFexceptions ?

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.

Author:  API Support [ Wed 24 Dec, 2008, 09:55 ]
Post subject:  Re: How to trap JFexceptions ?

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());
    }
}

Author:  [teknomage] [ Tue 13 Jan, 2009, 16:01 ]
Post subject:  Re: How to trap JFexceptions ?

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?

Author:  API Support [ Tue 13 Jan, 2009, 17:04 ]
Post subject:  Re: How to trap JFexceptions ?

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.

Author:  [teknomage] [ Thu 15 Jan, 2009, 12:02 ]
Post subject:  Re: How to trap JFexceptions ?

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?

Author:  API Support [ Thu 15 Jan, 2009, 13:53 ]
Post subject:  Re: How to trap JFexceptions ?

"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.

Author:  [teknomage] [ Fri 16 Jan, 2009, 05:00 ]
Post subject:  Re: How to trap JFexceptions ?

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?

Author:  API Support [ Fri 16 Jan, 2009, 08:58 ]
Post subject:  Re: How to trap JFexceptions ?

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 :)

  Page 1 of 1