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.

class not found in strategy
 Post subject: class not found in strategy Post rating: 0   New post Posted: Tue 20 Mar, 2012, 18:35 

User rating: 0
Joined: Tue 20 Mar, 2012, 18:26
Posts: 6
Location: Russian Federation, Moscow
Dear Sirs,

I'm starting to write a strategy, which, after adding a little class parsing string to hash, compiles without errors, but the strategy says "class not found".

I am new to Java and Jforex, so any link to manual will be greately appreciated.

Here is the class I added:

private class ServerInfo {
    private HashMap indexValues;
    private HashMap indexColors;

    public String fill(String desc) { // Создаёт класс из описателя
   String rv;

   rv = "";
   Pattern pattern = Pattern.compile("\\s*([\\d\\w]+)\\s*=\\s*([^;]+);");
   Matcher matcher = pattern.matcher(desc);
   while (matcher.find()) {
       String par = matcher.group(1);
       if(par == "CMD") {
      rv = matcher.group(2);
       }
       else {
      indexValues.put(par,new String(matcher.group(2)));
       }
   }
   return rv;
    }

    public ServerInfo(String desc) { // Заполняет значения из описателя
   Pattern pattern = Pattern.compile("\\s*([\\d\\w]+)\\s*=\\s*([^;]+);");
   Matcher matcher = pattern.matcher(desc);
   while (matcher.find()) {
       indexColors.put(matcher.group(1),new String(matcher.group(2)));
   }
    }

    public String get(String index) {
   return (String) indexValues.get(index);
    }
}


 
 Post subject: Re: class not found in strategy Post rating: 0   New post Posted: Wed 21 Mar, 2012, 09:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Consider trying something like this:
package jforex.test;

import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.dukascopy.api.*;

public class StratWithClass implements IStrategy {
   
    @Override
    public void onStart(IContext context) throws JFException {
        ServerInfo serverInfo = new ServerInfo("some string");
    }

    @Override
    public void onTick(Instrument instrument, ITick tick) throws JFException {}

    @Override
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {}

    @Override
    public void onMessage(IMessage message) throws JFException {}

    @Override
    public void onAccount(IAccount account) throws JFException {}

    @Override
    public void onStop() throws JFException {}

    private class ServerInfo {
        private HashMap indexValues;
        private HashMap indexColors;

        public String fill(String desc) {
            String rv;

            rv = "";
            Pattern pattern = Pattern.compile("\\s*([\\d\\w]+)\\s*=\\s*([^;]+);");
            Matcher matcher = pattern.matcher(desc);
            while (matcher.find()) {
                String par = matcher.group(1);
                if (par == "CMD") {
                    rv = matcher.group(2);
                } else {
                    indexValues.put(par, new String(matcher.group(2)));
                }
            }
            return rv;
        }

        public ServerInfo(String desc) {
            Pattern pattern = Pattern.compile("\\s*([\\d\\w]+)\\s*=\\s*([^;]+);");
            Matcher matcher = pattern.matcher(desc);
            while (matcher.find()) {
                indexColors.put(matcher.group(1), new String(matcher.group(2)));
            }
        }

        public String get(String index) {
            return (String) indexValues.get(index);
        }
    }

}



 
 Post subject: Re: class not found in strategy Post rating: 0   New post Posted: Sat 24 Mar, 2012, 15:53 

User rating: 0
Joined: Tue 20 Mar, 2012, 18:26
Posts: 6
Location: Russian Federation, Moscow
Thank you, this worked, but I think I need this class to be external to use it in an indicator as well as in strategy. Is it possible?
Or, alternatively, is it possible for strategy to draw not in the chart window, but in a separate one, as index does?


 
 Post subject: Re: class not found in strategy Post rating: 0   New post Posted: Mon 26 Mar, 2012, 15:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
VGT wrote:
Thank you, this worked, but I think I need this class to be external to use it in an indicator as well as in strategy. Is it possible?
Yes, you can either load the class file:
https://www.dukascopy.com/wiki/#Load_java_class
Or a jar file:
https://www.dukascopy.com/wiki/#Include_libraries
VGT wrote:
Or, alternatively, is it possible for strategy to draw not in the chart window, but in a separate one, as index does?
Currently from strategy it is only possible to draw only on the main chart window.


 

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