Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API function requests in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Strategy for Specific UserName
 Post subject: Strategy for Specific UserName Post rating: 0   New post Posted: Mon 14 Apr, 2014, 05:17 
User avatar

User rating: 1
Joined: Sun 09 Feb, 2014, 14:42
Posts: 15
Location: Indonesia, Bandung
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


 
 Post subject: Re: Strategy for Specific UserName Post rating: 0   New post Posted: Mon 14 Apr, 2014, 07:19 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Use equals method.


 
 Post subject: Re: Strategy for Specific UserName Post rating: 0   New post Posted: Mon 14 Apr, 2014, 08:28 
User avatar

User rating: 1
Joined: Sun 09 Feb, 2014, 14:42
Posts: 15
Location: Indonesia, Bandung
API Support wrote:
Use equals method.


Thank you,Sir for your help. :D


 
 Post subject: Re: Strategy for Specific UserName Post rating: 0   New post Posted: Mon 14 Apr, 2014, 14:50 
User avatar

User rating: 1
Joined: Sun 09 Feb, 2014, 14:42
Posts: 15
Location: Indonesia, Bandung
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


 
 Post subject: Re: Strategy for Specific UserName Post rating: 0   New post Posted: Tue 15 Apr, 2014, 13:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
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


 
 Post subject: Re: Strategy for Specific UserName Post rating: 0   New post Posted: Fri 18 Apr, 2014, 03:54 
User avatar

User rating: 1
Joined: Sun 09 Feb, 2014, 14:42
Posts: 15
Location: Indonesia, Bandung
Thank you, Sir :D


 

Jump to:  

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