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.

delay strategy on autologin
 Post subject: delay strategy on autologin Post rating: 0   New post Posted: Tue 01 Feb, 2011, 14:53 

User rating: 0
Joined: Fri 20 Aug, 2010, 14:09
Posts: 20
When I login automatically with a strategy I get a NullPointerException because the strategy is trying to get to a chart object which does not seem to be initialized yet.

How to make sure that the strategy starts after the platform has been totally initialized?


 
 Post subject: Re: delay strategy on autologin Post rating: 0   New post Posted: Mon 07 Feb, 2011, 14:23 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Could you please describe steps to reproduce the problem? Because after you start the platform you have to manually start a strategy.


 
 Post subject: Re: delay strategy on autologin Post rating: 0   New post Posted: Thu 10 Feb, 2011, 08:42 

User rating: 0
Joined: Fri 20 Aug, 2010, 14:09
Posts: 20
Following works fine when started inside JForex because then the charts and data is already initialized

/usr/lib/jvm/jre1.6.0_21/bin/javaws -J-Djnlp.client.username=name -J-Djnlp.client.password=pass    -J-Djnlp.strategy.path="/home/name/JForex/Strategies/Line.jfx;" https://www.dukascopy.com/client/live/jclient/jforex.jnlp

package jforex;

import java.util.*;

import com.dukascopy.api.*;
import com.dukascopy.api.drawings.*;

public class Line implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
   
    private IHorizontalLineChartObject line = null;
    private IChart chart;
   
   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();
       
        chart = context.getChart(Instrument.EURUSD);
        long currBarTime = history.getStartTimeOfCurrentBar(Instrument.EURUSD, Period.DAILY);
        java.util.List<IBar> bars = history.getBars(Instrument.EURUSD,
                                                    Period.DAILY,
                                                    OfferSide.BID,
                                                    history.getTimeForNBarsBack(Period.DAILY,
                                                                                currBarTime,
                                                                                10),
                                                    currBarTime);
        IBar todaysBar = bars.get(bars.size()-1);
        line = chart.getChartObjectFactory().createHorizontalLine("line", todaysBar.getLow());
        chart.addToMainChart(line);
   }

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


 

Jump to:  

  © 1998-2026 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