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.

Working with Fibo Retracement Chart Object
 Post subject: Working with Fibo Retracement Chart Object Post rating: 0   New post Posted: Wed 25 May, 2011, 19:39 

User rating: -
Hello,

Could you show some examples on how to work with fibo retracements objects real time on tick? (object: IFiboRetracementChartObject)
I would like to see it working, as the levels are not shown on the chart if the object it's coded to show automatically from the strategy, updating on each new tick for example.

Thank you.


 
 Post subject: Re: Working with Fibo Retracement Chart Object Post rating: 0   New post Posted: Tue 07 Jun, 2011, 12:34 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
See JForex wiki (Drawing type FIBO):
https://www.dukascopy.com/wiki/index.php ... wing_types:
You can then use similar code to redraw the fibo lines on every onTick. Note that there are custom fibo levels used in the following strategy example:

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;

   public Instrument instrument = Instrument.EURUSD;
   public Period selectedPeriod = Period.TEN_SECS;

   private IFiboRetracementChartObject fiboObj;

   public void onStart(IContext context) throws JFException {
      this.chart = context.getChart(instrument);
   }

   public void onAccount(IAccount account) throws JFException {
   }

   public void onMessage(IMessage message) throws JFException {
   }

   public void onStop() throws JFException {
      if(fiboObj != null)
         chart.remove(fiboObj);
   }

   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 factory = chart.getChartObjectFactory();

      // there is max 1 fibo retracement at a time
      if (fiboObj == null) {
         fiboObj = factory.createFiboRetracement();
      }

      fiboObj.setPrice(0, priceMin);
      fiboObj.setTime(0, (new Date()).getTime() - 5000);
      fiboObj.setPrice(1, priceMax);
      fiboObj.setTime(1, (new Date()).getTime());

        // remove the standard levels
        for (int i = fiboObj.getLevelsCount() - 1; i >= 0 ; i--) {
            fiboObj.removeLevel(i);
        }
       
      // add customized levels
      Color color = Color.BLACK;
      fiboObj.addLevel("level 1", 0.10, color);
      fiboObj.addLevel("level 2", 0.30, color);
      fiboObj.addLevel("level 3", 0.50, color);
      fiboObj.addLevel("level 4", 0.70, color);
      fiboObj.addLevel("level 5", 0.90, color);

      chart.addToMainChart(fiboObj);
      chart.repaint();
   }

}


 

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