Dukascopy
 
 
Wiki JStore Search Login

JFOREX-2762 Constructors for all inherited IChartObject
 Post subject: JFOREX-2762 Constructors for all inherited IChartObject Post rating: 0   New post Posted: Wed 02 Feb, 2011, 10:01 

User rating: 0
Joined: Fri 20 Aug, 2010, 14:09
Posts: 20
The following stopped working, the line does not get redrawn anymore

package jforex;

import java.util.*;

import com.dukascopy.api.*;

public class Strategy implements IStrategy {
   private IEngine engine;
   private IConsole console;
   private IHistory history;
   private IContext context;
   private IIndicators indicators;
   private IUserInterface userInterface;
   
   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();
       
        IChart chart = context.getChart(Instrument.EURUSD);
        this.console.getOut().println(chart);
        Calendar cale = Calendar.getInstance();
        IChartObject price = chart.draw("price", IChart.Type.PRICEMARKER, cale.getTimeInMillis(), 1.38);

   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
        IChart chart = context.getChart(Instrument.EURUSD);
        chart.remove("price");
   }

   public void onTick(Instrument instrument, ITick tick) throws JFException {
        IChart chart = context.getChart(Instrument.EURUSD);
        if ( instrument == Instrument.EURUSD )
        {
           IChartObject price = chart.get("price");
           price.setAttrDouble(IChartObject.ATTR_DOUBLE.PRICE1, tick.getBid());
           this.console.getOut().println("bid: " + tick.getBid());
        }
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


 
 Post subject: Re: IChartObject broken? Post rating: 0   New post Posted: Fri 04 Feb, 2011, 10:27 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
The IChart.draw() method is deprecated. Please use IChartObjectFactory methods to draw on a chart. Please consider the following code:
   private IHorizontalLineChartObject line = null;
   private IChart chart;

   public void onTick(Instrument instrument, ITick tick) throws JFException {
        if ( instrument == Instrument.EURUSD ) {
           if (line != null) {
              chart.remove(line.getKey());
           }
           line = chart.getChartObjectFactory().createHorizontalLine("objectId", tick.getBid());
           line.setPrice(0, tick.getBid());
           chart.addToMainChart(line);
           this.console.getOut().println("bid: " + tick.getBid());
        }
   }


 
 Post subject: Re: IChartObject broken? Post rating: 0   New post Posted: Fri 04 Feb, 2011, 12:33 

User rating: 0
Joined: Fri 20 Aug, 2010, 14:09
Posts: 20
So you can't assign them a name anymore and call them by that name?

(I have many lines on different instruments so I will have to keep track on it in a list if that's not possible anymore)


 
 Post subject: Re: IChartObject broken? Post rating: 0   New post Posted: Fri 04 Feb, 2011, 12:52 

User rating: 0
Joined: Fri 20 Aug, 2010, 14:09
Posts: 20
I tried to use the example but it shows nothing
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);
   }

   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 {
        if ( instrument == Instrument.EURUSD ) {
           if (line != null) {
              chart.remove(line.getKey());
           }
           line = chart.getChartObjectFactory().createHorizontalLine();
           line.setPrice(0, tick.getBid());
           chart.addToMainChart(line);
           this.console.getOut().println("bid: " + tick.getBid());
        }
   }
   
    public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
    }
}


 
 Post subject: Re: IChartObject broken? Post rating: 0   New post Posted: Fri 04 Feb, 2011, 14:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Sorry bet setPrice method will be available in the next release, currently you can pass the price to the constructor:
line = chart.getChartObjectFactory().createHorizontalLine("objectname", tick.getBid());

As you can see object still have name (id).


 
 Post subject: Re: IChartObject broken? Post rating: 0   New post Posted: Thu 10 Feb, 2011, 14:00 
User avatar

User rating: 21
Joined: Thu 19 May, 2011, 20:50
Posts: 413
Location: Germany, Munich
Please support the constructors for all inherited IChartObject items in the java docs, e.g. createHorizontalLine(Object...) is not very helpful....


Also the setPrice method is very important. Otherwise one has to delete the IChartObject and paint it again. If you have to do this every tick, JForex freezes sometimes.

Please fix this problem and support us with functionating methods.


 
 Post subject: Re: JFOREX-2762 Constructors for all inherited IChartObject Post rating: 0   New post Posted: Thu 17 Mar, 2011, 23:56 

User rating: -
I tried to get the createShortLine to work
int pivlevellength = 20;
long timeInterval = chart.getSelectedPeriod().getInterval();
IShortLineChartObject pivotLine = null;

      
Instrument instrument = chart.getInstrument();
ITick lastTick = history.getLastTick(instrument);

      Calendar startOfDay = Calendar.getInstance();
      startOfDay.setTimeZone(TimeZone.getTimeZone("GMT"));
      startOfDay.setTimeInMillis(lastTick.getTime());
      startOfDay.set(Calendar.HOUR_OF_DAY, 0);
      startOfDay.set(Calendar.MINUTE, 0);
      startOfDay.set(Calendar.SECOND, 0);
      startOfDay.set(Calendar.MILLISECOND, 0);

      pivlevellength = Math.abs(Support.Round((startOfDay.getTimeInMillis()-lastTick.getTime())/timeInterval));
      
      pivotLine = chart.getChartObjectFactory().createShortLine(labelLine, price);
      pivotLine.setTime(0, lastTick.getTime() - pivlevellength * timeInterval);
      pivotLine.setTime(1,  lastTick.getTime());
      pivotLine.setPrice(0, price);
      pivotLine.setPrice(1, price);
      pivotLine.setAttrColor(IChartObject.ATTR_COLOR.COLOR, color);
      chart.addToMainChart(pivotLine);

Any ideas


 

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