Dukascopy
 
 
Wiki JStore Search Login

JFOREX-2977 IFiboRetracementChartObject - Levels and Labels
 Post subject: JFOREX-2977 IFiboRetracementChartObject - Levels and Labels Post rating: 0   New post Posted: Sun 24 Apr, 2011, 17:27 

User rating: 0
Joined: Tue 08 Jun, 2010, 16:14
Posts: 4
Demorelease 2.13.10 / API 2.7.38

If you have multiple Fiboretracement Objects or ILeveledChartObjects, the levels are not attached to the Object and the Levellabels are not attached to the levels.

i.e.

FiboRetracement 1 has 5 Levels
FiboRetracement 2 has 10 Levels

Problem 1: getLevelsCount will provide for each FiboRetracement 15 Levels.
Problem 2: The Label in addLevel or setLevelLabel is related to the Levelvalue (i.e. 50 %) not to the Level (i.e. Level 10). getLevelLabel provide correct Labels for each level, but the chart shows the Labels related to the values (i.e. all 50 % levels show the same label).

Maybe this will help your debugging: If you try to set a levellabel for a level that does not exist, the error-message shows an array of two values where the first value is always 0. I guess the first value should be related to the FiboRectracement Object and is not linked.

A solution would be very appreciated.

Thank you in advance and best regards

BM


 
 Post subject: Re: IFiboRetracementChartObject - Levels and Labels Post rating: 0   New post Posted: Thu 28 Apr, 2011, 05:38 

User rating: 0
Joined: Tue 08 Jun, 2010, 16:14
Posts: 4
A little extension: Define a FiboRetracement Object A with 5 Levels and a FiboRetracement Object B with 10 Levels. As soon as B is created, A will be extended to 10 Levels.

A solution would be welcome.

Thank you in advance and best regards

BM


 
 Post subject: Re: JFOREX-2977 IFiboRetracementChartObject - Levels and Lab Post rating: 0   New post Posted: Wed 15 Jun, 2011, 09:41 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Problem 1: Is not reproducible, please, provide your strategy code to find out what's the problem.
Problem 2: and.... where is the problem actually?

About "debugging" - this error message appears due to you try to work with not existed level. There will be no problem if you specify correct indexes.


 
 Post subject: Re: JFOREX-2977 IFiboRetracementChartObject - Levels and Lab Post rating: 0   New post Posted: Wed 20 Jul, 2011, 11:14 

User rating: -
Ok - here is a code to test that produce exactly the results as described in the first posting. There is no difference between Fiboobject1 and FiboObject2.

package charts.test;
 
import java.awt.Color;
import java.util.Date;
 
import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IChartObjectFactory;
import com.dukascopy.api.drawings.IFiboRetracementChartObject;
 
public class FiboRetracementsCustom implements IStrategy {
   private IChart chart;
   private IConsole console;
 
   public Instrument instrument = Instrument.EURUSD;
   public Period selectedPeriod = Period.TEN_SECS;
 
   private IFiboRetracementChartObject fiboObj1;
  private IFiboRetracementChartObject fiboObj2;
 
   public void onStart(IContext context) throws JFException {
      this.chart = context.getChart(instrument);
      this.console = context.getConsole();
   }
 
   public void onAccount(IAccount account) throws JFException {
   }
 
   public void onMessage(IMessage message) throws JFException {
   }
 
   public void onStop() throws JFException {
      if(fiboObj1 != null) {
         chart.remove(fiboObj1);
       }
       if(fiboObj2 != null) {
         chart.remove(fiboObj2);
       }
   }
   
 
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      if (!instrument.equals(instrument))
         return;
      drawFiboWithLevels(tick.getBid(), tick.getBid() + 0.0010);
   }
 
   public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
      // if (!instrument.equals(instrument) || !period.equals(selectedPeriod)) return;
      // drawFiboWithLevels(bidBar.getClose(), bidBar.getClose() + 0.0010);
   }
 
   private void drawFiboWithLevels(double priceMin, double priceMax) {
 
      if (chart == null)
         return;
 
      IChartObjectFactory factory1 = chart.getChartObjectFactory();
      IChartObjectFactory factory2 = chart.getChartObjectFactory();
 
     
      if (fiboObj1 == null) {
         fiboObj1 = factory1.createFiboRetracement();
      }
      if (fiboObj2 == null) {
         fiboObj2 = factory2.createFiboRetracement();
      }
 
      fiboObj1.setPrice(0, priceMin);
      fiboObj1.setTime(0, (new Date()).getTime() - 5000);
      fiboObj1.setPrice(1, priceMax);
      fiboObj1.setTime(1, (new Date()).getTime());
     
      fiboObj2.setPrice(0, priceMin);
      fiboObj2.setTime(0, (new Date()).getTime() - 5000);
      fiboObj2.setPrice(1, priceMax + 0.0050);
      fiboObj2.setTime(1, (new Date()).getTime());
 
        // remove the standard levels
        for (int i = fiboObj1.getLevelsCount() - 1; i >= 0 ; i--) {
            fiboObj1.removeLevel(i);
        }
        for (int i = fiboObj2.getLevelsCount() - 1; i >= 0 ; i--) {
            fiboObj2.removeLevel(i);
        }
         
      // add customized levels
      Color color = Color.BLACK;
      fiboObj1.addLevel("level 1", 0.10, color);
      fiboObj1.addLevel("level 2", 0.30, color);
      fiboObj1.addLevel("level 3", 0.50, color);
      fiboObj1.addLevel("level 4", 0.70, color);
      fiboObj1.addLevel("level 5", 0.90, color);
     
      color = Color.YELLOW;
      fiboObj2.addLevel("Test 1", 0.10, color);
      fiboObj2.addLevel("Test 2", 0.30, color);
      fiboObj2.addLevel("Test 3", 0.50, color);
      fiboObj2.addLevel("Test 4", 0.70, color);
      fiboObj2.addLevel("Test 5", 0.90, color);
 
     chart.addToMainChart(fiboObj1);
      chart.addToMainChart(fiboObj2);
      chart.repaint();
     
                  console.getOut().println("-----------------------");
                console.getOut().println("Fibo Key 1 = "+ fiboObj1.getKey());
                 console.getOut().println("Fibo Key 2 = "+ fiboObj2.getKey());
   }
 
}


 
 Post subject: Re: JFOREX-2977 IFiboRetracementChartObject - Levels and Lab Post rating: 0   New post Posted: Wed 20 Jul, 2011, 12:41 

User rating: -
Here is a sample code. There is no way to handle the levels of two Fiboretracement Object separately:


package charts.test;
 
import java.awt.Color;
import java.util.Date;
 
import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IChartObjectFactory;
import com.dukascopy.api.drawings.IFiboRetracementChartObject;
 
public class FiboRetracementsCustom implements IStrategy {
   private IChart chart;
   private IConsole console;
 
   public Instrument instrument = Instrument.EURUSD;
   public Period selectedPeriod = Period.TEN_SECS;
 
   private IFiboRetracementChartObject fiboObj1;
  private IFiboRetracementChartObject fiboObj2;
  private boolean firstRun;
 
   public void onStart(IContext context) throws JFException {
      this.chart = context.getChart(instrument);
      this.console = context.getConsole();
      IChartObjectFactory factory = chart.getChartObjectFactory();
         fiboObj1 = factory.createFiboRetracement();
         
         fiboObj2 = factory.createFiboRetracement();
         firstRun = true;
   }
 
   public void onAccount(IAccount account) throws JFException {
   }
 
   public void onMessage(IMessage message) throws JFException {
   }
 
   public void onStop() throws JFException {
      if(fiboObj1 != null) {
         chart.remove(fiboObj1);
       }
       if(fiboObj2 != null) {
         chart.remove(fiboObj2);
       }
   }
   
 
   public void onTick(Instrument instrument, ITick tick) throws JFException {
      if (!instrument.equals(instrument))
         return;
      //drawFiboWithLevels(tick.getBid(), tick.getBid() + 0.0010);
   }
 
   public void onBar(Instrument _instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
       if ((_instrument == instrument) && (period == selectedPeriod)) {
       drawFiboWithLevels(bidBar.getClose(), bidBar.getClose() + 0.0010);
       }
   }
 
   private void drawFiboWithLevels(double priceMin, double priceMax) {
 
     if (firstRun == true) {
      fiboObj1.setPrice(0, priceMin);
      fiboObj1.setTime(0, (new Date()).getTime() - 5000);
      fiboObj1.setPrice(1, priceMax);
      fiboObj1.setTime(1, (new Date()).getTime());
      fiboObj1.setColor(Color.BLACK);
      }
     
      fiboObj2.setPrice(0, priceMin);
      fiboObj2.setTime(0, (new Date()).getTime() - 5000);
      fiboObj2.setPrice(1, priceMax + 0.0020);
      fiboObj2.setTime(1, (new Date()).getTime());
      fiboObj2.setColor(Color.YELLOW);
 
 
        // remove the standard levels
        if (firstRun == true) {
           for (int i = fiboObj1.getLevelsCount() - 1; i >= 0 ; i--) {
               fiboObj1.removeLevel(i);
                console.getOut().println("Object 1 Levels will be removed");
           }
        }
        for (int i = fiboObj2.getLevelsCount() - 1; i >= 0 ; i--) {
            fiboObj2.removeLevel(i);
        }
         
      // add customized levels
      if (firstRun == true) {
     
         fiboObj1.addLevel("level 1", 0.10, Color.BLACK);
         fiboObj1.addLevel("level 2", 0.30, Color.BLACK);
         fiboObj1.addLevel("level 3", 0.50, Color.BLACK);
         fiboObj1.addLevel("level 4", 0.70, Color.BLACK);
         fiboObj1.addLevel("level 5", 0.90, Color.BLACK);
          console.getOut().println("Object 1 Levels will be added");
      }
      int x = fiboObj1.getLevelsCount();
      console.getOut().println("levelsCount = "+ fiboObj1.getLevelsCount());
     
     
     
     
      if (x > 0) {
         
          fiboObj1.setLevelLabel(0,"Level 1");
          }
     
      fiboObj2.addLevel("Test 1", 0.10, Color.BLUE);
      fiboObj2.addLevel("Test 2", 0.30, Color.BLUE);
      fiboObj2.addLevel("Test 3", 0.50, Color.BLUE);
      fiboObj2.addLevel("Test 4", 0.70, Color.BLUE);
      fiboObj2.addLevel("Test 5", 0.90, Color.BLUE);
 
     if (firstRun == true) {
         chart.addToMainChart(fiboObj1);
      }
      chart.addToMainChart(fiboObj2);
      chart.repaint();
      firstRun = false;
     
                  console.getOut().println("-----------------------");
                console.getOut().println("Fibo Key 1 = "+ fiboObj1.getKey());
                 console.getOut().println("Fibo Key 2 = "+ fiboObj2.getKey());
   }
 
}


 

Jump to:  

  © 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