Can you help me figure this out? I am running my strategy in the client platform, and occasionally it is stopped for no apparent reason. To make sure that exceptions are not the cause, I wrapped all platform calls with handlers, which make sure that an error message is printed out before letting the platform even see the exception, as you can see in the code below. Still, however, it just suddenly stops (i.e. onStop gets called, and the strategy stops receiving other calls), but no error message is displayed in the strategy console, and no exception in the 'Messages' tab.
Are there other reasons the platform may stop a strategy, besides uncaught exceptions and a stop instruction from the user?
package isak.jforex.jfs;
import com.dukascopy.api.*;
import java.io.*;
public class MyStrategy implements IStrategy {
private IConsole console;
// ... OTHER FIELD DECLARATIONS ...
@Override
public final void onStart(IContext context) {
try {
console = context.getConsole();
trace("onStart() called");
// ... OTHER CODE ...
trace("... onStart() returned normally");
} catch (RuntimeException ex){
throwAfterClosing(ex);
} catch (Error ex){
throwAfterClosing(ex);
}
}
@Override
public final void onTick(Instrument instrument, ITick tick) {
try{
// ... OTHER CODE that throws JFException ...
} catch (JFException ex){
throwAfterClosing(ex);
} catch (Error ex){
throwAfterClosing(ex);
} catch (RuntimeException ex){
throwAfterClosing(ex);
}
}
@Override
public final void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) {
try{
// ... OTHER CODE ...
} catch (Error ex){
throwAfterClosing(ex);
} catch (RuntimeException ex){
throwAfterClosing(ex);
}
}
@Override
public void onMessage(IMessage message) {
try{
// ... OTHER CODE ...
} catch (Error ex){
throwAfterClosing(ex);
} catch (RuntimeException ex){
throwAfterClosing(ex);
}
}
@Override
public void onAccount(IAccount account) {
try{
// ... EMPTY ...
} catch (Error ex){
throwAfterClosing(ex);
} catch (RuntimeException ex){
throwAfterClosing(ex);
}
}
// this mechanism is introduced in all calls from platform to work around bug
// that jforex sometimes stops strategy without displaying exception
// that caused the stop
// EDIT: It now seems not even this works; the strategy sometimes gets stoppped without a call to this method
private void throwAfterClosing(Throwable th){
String msg = th.toString() + " thrown.";
fatal(msg);
// ... OTHER CODE for finalization ...
if(th instanceof Error)
throw (Error) th;
else if(th instanceof RuntimeException)
throw (RuntimeException) th;
else
throw new RuntimeException(th);
}
@Override
public final void onStop() {
trace("onStop() entered...");
// ... OTHER CODE ...
trace("... onStop() returned");
}
private void trace(String s){
PrintStream out = console.getOut();
out.print("TRACE: ");
out.print(": ");
out.println(s);
}
private void fatal(String s){
PrintStream out = console.getErr();
out.print("FATAL: ");
out.print(": ");
out.println(s);
}
}