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.

Stop strategy after exception
 Post subject: Stop strategy after exception Post rating: 0   New post Posted: Fri 22 Oct, 2010, 00:06 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello I would like to stop strategy after exception thrown in the code.
I have enabled "stop strategies on exception" in Tools-Preferences-Advanced
and when there is exception thrown by code of my strategy the strategy is stopped. Thats correct.

But I am using my custom libraries with my custom methods, and I am importing these .jar files into my strategies.
In this libraries is few methods with the definition "throws JFException"
but when the method throw any JFException exception, its just written into output messages in JForex but the strategy keep running.
It will not interupt the strategy, and that is wrong.

Do you have any idea how to fix that?
Thank you


 
 Post subject: Re: Stop strategy after exception Post rating: 0   New post Posted: Fri 22 Oct, 2010, 00:08 

User rating: 0
Joined: Wed 18 May, 2011, 11:25
Posts: 60
Location: DE
https://www.dukascopy.com/client/javadoc/com/dukascopy/api/IContext.html#stop%28%29


 
 Post subject: Re: Stop strategy after exception Post rating: 0   New post Posted: Fri 22 Oct, 2010, 01:01 

User rating: 0
Joined: Tue 28 Sep, 2010, 09:41
Posts: 18
Hello

thank you for advice. I know about this option.. I can create try catch block arround the code and invoke stop() method in catch.

But I still dont understand why the strategy is stopped automaticaly when there is exception thrown from the strategy code
and why is the strategy not stopped automaticaly when there is JFException thrown by my custom method defined in my custom library used inside the strategy code.

Imagine I have my custom library and in this library is class Test with following method
public void nothing() throws JFException {
    throw new JFException("hello");
}



and then in strategy code I will write something like this:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    Test.nothing();
}


It will not interupt the strategy. And thats the problem. It should interupt the strategy.
I dont want to write try catch block arround the code and call the stop() method.

Thank you for your response


 
 Post subject: Re: Stop strategy after exception Post rating: 0   New post Posted: Tue 26 Oct, 2010, 07:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hello,
please consider our sample:
package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.strategies.testjar.TestJar;

@Library("TestException.jar")
public class Strategy implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
   
   public void onStart(IContext context) throws JFException {
      this.engine = context.getEngine();
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.context = context;
      this.indicators = context.getIndicators();
      this.userInterface = context.getUserInterface();
        TestJar.throwEXception();
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}

You must place the TestException.jar in to your ..\JForex\Strategies\file directory.


Attachments:
TestException.rar [841 Bytes]
Downloaded 362 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 

Jump to:  

cron
  © 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