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.

Strategy stopped for no apparent reason
 Post subject: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Tue 12 Jul, 2011, 07:09 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
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);
    }
}


 
 Post subject: Re: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Tue 12 Jul, 2011, 11:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Did you check what was on java console when your strategy stopped unexpectedly?


 
 Post subject: Re: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Tue 12 Jul, 2011, 15:14 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
I am running the strategy in the JForex client platform. I checked only the strategy's console (MyStrategy tab, in this case) and the Messages tab. Please advise on how to check the Java console.


 
 Post subject: Re: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Tue 12 Jul, 2011, 15:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Try the following:
https://www.java.com/en/download/help/javaconsole.xml
Once the strategy stops when you think it is not supposed to, please check if there had not been some exception thrown to the java console.


 
 Post subject: Re: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Tue 12 Jul, 2011, 15:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=81&t=39073&p=50123#p50123


 
 Post subject: Re: Strategy stopped for no apparent reason Post rating: 0   New post Posted: Thu 14 Jul, 2011, 09:09 
User avatar

User rating: 6
Joined: Thu 19 May, 2011, 11:14
Posts: 235
Location: South Africa,
My bad. The exception was being thrown in code (not included in the example) playing an alert sound in the beginning of fatal(). So the platform was receiving a runtime exception, which is why it stopped the strategy.

I still don't understand why the platform sometimes doesn't give any error message when it stops the strategy due to an exception, but at least it doesn't stop the strategy for no reason.

Thanks for the Java Console hint.


 

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