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.

missing PolyLine constructors
 Post subject: missing PolyLine constructors Post rating: 0   New post Posted: Mon 11 Jul, 2011, 22:02 

User rating: -
Hello,

runtime exception:
java.lang.NoSuchMethodException: com.dukascopy.charts.drawings.PolyLineChartObject.<init>(java.lang.String)

It seems that:

PolyLineChartObject has just IPolyLineChartObject createPolyLine(); constructor (= constructor without any argument)

while the following 2 are described in docs:
IPolyLineChartObject createPolyLine(String key);
IPolyLineChartObject createPolyLine(Object... params); (deprecated)

These 2 seems not implemented: please check it out in jForex-2.14.4.jar: com.dukascopy.charts.drawings.PolyLineChartObject.class
you'll find that there is just one constructor: PolyLineChartObject()

on the contrary, for instance ShortLineChartObject.class has:
ShortLineChartObject()
ShortLineChartObject(String, long, double, long, double) (that should be deprecated)

At least a String argument is really needed, as in the form <whatever>ChartObject(String),
where the String arg is an handle necessary for any later manipulations of that object, like modifications, moving or deletion.

Any help would be appreciated, thanks in advance.


 
 Post subject: Re: missing PolyLine constructors Post rating: 0   New post Posted: Tue 12 Jul, 2011, 08:44 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
ZeroBug wrote:
It seems that:

PolyLineChartObject has just IPolyLineChartObject createPolyLine(); constructor (= constructor without any argument)

while the following 2 are described in docs:
IPolyLineChartObject createPolyLine(String key);
IPolyLineChartObject createPolyLine(Object... params); (deprecated)
The latter two methods will be provided with the next release.
If you wish to manage multiple IPolyLineChartObject objects. consider the following example strategy:
package charts.test;

import java.util.ArrayList;
import java.util.List;

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

/**
 * The strategy on every 10 second bar draws a zigzag style poly line between the ticks
 * of the the previous 10 sec bar. The strategy maintains the last three poly lines.
 *
 */

public class PolyLine implements IStrategy {
   private IConsole console;
   private IHistory history;
   private IChart chart;
   
   public Instrument instrument = Instrument.EURUSD;
   public Period selectedPeriod = Period.TEN_SECS;
   public Filter indicatorFilter = Filter.NO_FILTER;
   
   private List<IPolyLineChartObject> polyLines = new ArrayList<IPolyLineChartObject>();

   public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.history = context.getHistory();
      this.chart = context.getChart(instrument);
   }
   
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      if (!instrument.equals(this.instrument) || !period.equals(this.selectedPeriod))
         return;

      drawPoly(bidBar.getTime());
   }
   private void drawPoly(long time) throws JFException{

        List<ITick> ticks = history.getTicks(instrument, time, time + 10000);
        IPolyLineChartObject polyLine = chart.getChartObjectFactory().createPolyLine();
        print("add poly line with key: " + polyLine.getKey() + ", tick count: " + ticks.size());
       
        boolean isAsk = false;
        for(ITick t : ticks){
           //make a zigzag
           polyLine.addNewPoint(t.getTime(), isAsk ? t.getAsk() : t.getBid());
           isAsk = isAsk ? false : true;
        }
        chart.addToMainChart(polyLine);
       
        //maintain 3 last poly lines
        polyLines.add(polyLine);
        if(polyLines.size() > 3){
           chart.remove(polyLines.get(0));
           polyLines.remove(0);
        }
       
   }

   private void print(String message) {
      console.getOut().println(message);
   }
   
   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 {   }
}


 
 Post subject: Re: missing PolyLine constructors Post rating: 0   New post Posted: Wed 31 Aug, 2011, 15:55 

User rating: 0
Joined: Tue 12 Jul, 2011, 01:17
Posts: 3
Location: Israel,
This strategy produces an error:

14:51:14 The method remove(String) in the type IChart is not applicable for the arguments (IPolyLineChartObject)
14:51:14 ^^^^^^
14:51:14 chart.remove(polyLines.get(0));
14:51:14 1. ERROR in C:\Users\Shahar\AppData\Local\Temp\jfxide\tmp\PolyLineForum.java (at line 55)

Please advise.
Thanks!


 
 Post subject: Re: missing PolyLine constructors Post rating: 0   New post Posted: Wed 31 Aug, 2011, 16:08 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The following example is usable from JForex API version 2.6.38. Could you please check what JForex API version is your JForex client platform using. You can do this by selecting Help -> About...


 

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