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.

Information about strategy parameters
 Post subject: Information about strategy parameters Post rating: 0   Post Posted: Mon 28 Nov, 2011, 19:34 

User rating: 0
Joined: Wed 18 May, 2011, 08:40
Posts: 43
Location: RU
Is there any method which returns some information about strategy parameters like name and value? Thanks in advance.


 
 Post subject: Re: Information about strategy parameters Post rating: 0   Post Posted: Wed 30 Nov, 2011, 10:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider the following example program:
package jforex.strategies.oneorder;

import java.lang.reflect.Field;

import com.dukascopy.api.IStrategy;
import com.dukascopy.api.Configurable;

/**
 * The example program prints out strategy parameter names and default values
 *
 */

public class StrategyParamPrinter {
   
   public static void main(String[] args){
      
      EmptyStrategyWithParams strategy = new EmptyStrategyWithParams();
      printParamData(strategy);
      
   }
   
   public static void printParamData(IStrategy strategyInstance) {

      Field[] fields = strategyInstance.getClass().getFields();
      for (Field field : fields) {
         Configurable configurable = field.getAnnotation(Configurable.class);
         if (configurable != null) {            
            Object fieldValue = null;
            try {
               fieldValue = field.get(strategyInstance);
            } catch (IllegalArgumentException e) {
               e.printStackTrace(System.err);
            } catch (IllegalAccessException e) {
               e.printStackTrace(System.err);
            }            
            System.out.println("name: " + configurable.value() + " value: " + fieldValue);
         }
      }
   }

}
And the example strategy:
package jforex.strategies.oneorder;

import java.io.File;
import com.dukascopy.api.*;

public class EmptyStrategyWithParams implements IStrategy {

   @Configurable("Period")
   public Period period = Period.TEN_SECS;
   @Configurable("Instrument")
   public Instrument instrument = Instrument.EURUSD;
   @Configurable("Order count")
   public int orderCount = 10;
   @Configurable("File Path")
   public File file = new File("C:/temp/textFile.txt");
   
   public void onStart(IContext context) throws JFException {}
   public void onTick(Instrument instrument, ITick tick) throws JFException {}
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}
   public void onMessage(IMessage message) throws JFException {}
   public void onAccount(IAccount account) throws JFException {}
   public void onStop() throws JFException {}
}


Attachments:
EmptyStrategyWithParams.java [877 Bytes]
Downloaded 281 times
StrategyParamPrinter.java [1.05 KiB]
Downloaded 283 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.
 
 Post subject: Re: Information about strategy parameters Post rating: 0   Post Posted: Sat 03 Dec, 2011, 10:43 

User rating: 0
Joined: Wed 18 May, 2011, 08:40
Posts: 43
Location: RU
Thanks!


 

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