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();
}
}