Dukascopy Support Board
http://www.dukascopy.com/swiss/english/forex/jforex/forum/

Strategy for Specific UserName
http://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=83&t=51070
Page 1 of 1

Author:  hargun [ Mon 14 Apr, 2014, 05:17 ]
Post subject:  Strategy for Specific UserName

Hello. I am trying to make strategy that only run on specific username. I try this code :
package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IIndicators.AppliedPrice;
import com.dukascopy.api.IBar;
import com.dukascopy.api.IAccount;
import com.dukascopy.api.IAccount.AccountState;

public class Tes2 implements IStrategy {
    private IAccount account;
    private IEngine engine;
    private IConsole console;
    private IHistory history;
    private IContext context;
    private IIndicators indicators;
    private IUserInterface userInterface;
   
    private String User;
   
    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();
    }

    public void onAccount(IAccount account) throws JFException {
        account = context.getAccount();
        User = "DEMO10037gQxAbEU";
        if (account.getUserName() == User) {
            console.getOut().println("Strategy Run");
        } else {
            console.getOut().println("This Strategy doesn't belong to this account");
            context.stop();
        }
    }

    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 {
    }
}


But the strategy stops although User == account.getUserName(). Can anyone help me?
Thank you

Author:  API Support [ Mon 14 Apr, 2014, 07:19 ]
Post subject:  Re: Strategy for Specific UserName

Use equals method.

Author:  hargun [ Mon 14 Apr, 2014, 08:28 ]
Post subject:  Re: Strategy for Specific UserName

API Support wrote:
Use equals method.


Thank you,Sir for your help. :D

Author:  hargun [ Mon 14 Apr, 2014, 14:50 ]
Post subject:  Re: Strategy for Specific UserName

Dear Sir,

I change : account.getUserName() == User
to : account.getUserName().equals(User)

I try to local run, there is no error message.

But when I try in historical tester, it keeps showing an error message:
java.lang.NullPointerException @ jforex.Tes2.onAccount(Tes2.java:37)
Show full exception :
java.lang.NullPointerException
at jforex.Tes2.onAccount(Tes2.java:37)
at com.dukascopy.dds2.greed.agent.strategy.tester.aq.GB(Unknown Source)
at com.dukascopy.dds2.greed.agent.strategy.tester.aq.aR(Unknown Source)
at com.dukascopy.dds2.greed.agent.strategy.tester.v.run(Unknown Source)
at com.dukascopy.dds2.greed.agent.strategy.tester.b.a(Unknown Source)
at com.dukascopy.dds2.greed.actions.servicesources.StrategyTesterAction.CI(Unknown Source)
at com.dukascopy.dds2.greed.actions.servicesources.StrategyTesterAction.Cd(Unknown Source)
at com.dukascopy.dds2.greed.actions.c.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

How to fix this error?
Thank you

Author:  API Support [ Tue 15 Apr, 2014, 13:21 ]
Post subject:  Re: Strategy for Specific UserName

tester does not know about your username, it only works while forward-testing, you can detect if it is Historical Tester by checking IEngine.getType(). See example here:
https://www.dukascopy.com/wiki/#Account_Type,_Login,_Run_Mode

Author:  hargun [ Fri 18 Apr, 2014, 03:54 ]
Post subject:  Re: Strategy for Specific UserName

Thank you, Sir :D

  Page 1 of 1