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.

Polygone, best practice
 Post subject: Polygone, best practice Post rating: 0   New post Posted: Thu 15 Sep, 2011, 21:42 

User rating: 0
Joined: Tue 06 Sep, 2011, 06:12
Posts: 5
Location: DE
I want to draw a Bollinger Band on my own (that is, NOT via adding BB to a chart).

What is the best practice for that? Currently I'm doing this:

  IPolyLineChartObject upper;
  IPolyLineChartObject middle;
  IPolyLineChartObject lower;

  public void onStart(IContext ctx) throws JFException
  {
    this.ctx = ctx;
    engine = ctx.getEngine();
    this.console = ctx.getConsole();
    indicators = ctx.getIndicators();
    chart = ctx.getChart(Instrument.EURUSD);
    upper = chart.getChartObjectFactory().createPolyLine();
    upper.setColor(Color.ORANGE);
    middle = chart.getChartObjectFactory().createPolyLine();
    middle.setColor(Color.RED);
    lower = chart.getChartObjectFactory().createPolyLine();
    lower.setColor(Color.ORANGE);
    chart.addToMainChart(upper);
    chart.addToMainChart(middle);
    chart.addToMainChart(lower);
    console.getOut().println("Started");
  }

  public void onTick(Instrument instrument, ITick tick) throws JFException
  {
  }


  public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
  {
    if (!instrument.equals(Instrument.EURUSD) || !period.equals(Period.FIFTEEN_MINS))
      return;
    double[] currentValues = indicators.bbands(instrument, period, OfferSide.ASK, IIndicators.AppliedPrice.CLOSE, timePeriod, nbDevUp, nbDevDn, maType, 1);
    long time = askBar.getTime();
    System.out.println(time+"/0: "+currentValues[0]+", 1: "+currentValues[1]+", 2: "+currentValues[2]);
    upper.addNewPoint(time, currentValues[0]);
    middle.addNewPoint(time, currentValues[1]);
    lower.addNewPoint(time, currentValues[2]);
  }



But the PolyLines grow and will certainly lead to an out of memory at some time, I don't find a way to remove points (e.g. the oldest). So what is the best practice to do that?

Thanks!


 
 Post subject: Re: Polygone, best practice Post rating: 0   New post Posted: Fri 16 Sep, 2011, 10:11 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Currently it is not possible to remove points from a PolyLine. What you can consider is doing something similar to this:
        int pointCount = polyLine.getPointsCount();
        if (pointCount > 1000){
           IPolyLineChartObject polyLineNew = chart.getChartObjectFactory().createPolyLine();
           //copy last 500 points from polyline the old polyline
           for (int i = 500; i< pointCount; i++){
              polyLineNew.addNewPoint(polyLine.getTime(i), polyLine.getPrice(i));
           }
           chart.remove(polyLine);
           chart.addToMainChart(polyLineNew);
        }


 
 Post subject: Re: Polygone, best practice Post rating: 0   New post Posted: Fri 16 Sep, 2011, 20:23 

User rating: 0
Joined: Tue 06 Sep, 2011, 06:12
Posts: 5
Location: DE
Thanks. There seems to be an error with polylines. I'm getting this from time to time. Seems the last point will be connected to a point far in the past. This continues until I stop the app so every new point is connect to the past one.

Screenshot attached 3 polylines).


Attachments:
Bildschirmfoto 2011-09-16 um 21.18.50.png [85.94 KiB]
Downloaded 338 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Polygone, best practice Post rating: 0   New post Posted: Fri 16 Sep, 2011, 20:54 

User rating: 0
Joined: Tue 06 Sep, 2011, 06:12
Posts: 5
Location: DE
Just found this is a bug in your API:

https://www.dukascopy.com/swiss/english/forex/jforex/forum/viewtopic.php?f=16&t=42255

Is it already fixed or, if not, when will it be fixed?


 
 Post subject: Re: Polygone, best practice Post rating: 0   New post Posted: Mon 19 Sep, 2011, 07:48 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
This is a consequence of a fact, that currently a poly line is limited to 100 points, so as a temporary workaround please consider making a new poly line after each 100 points.
This will be fixed with the next release, follow the release information here:
viewtopic.php?f=71&t=28934


 

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