Here is the code I have so far. It does appear to draw the line on EMA3 for period 5min, BUT the line only flashes extremely briefly and also not on the actual forming of the new 5min bar.
package charts.test;
import com.dukascopy.api.*;
import com.dukascopy.api.drawings.IHorizontalLineChartObject;
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.OutputParameterInfo.DrawingStyle;
import java.awt.Color;
import com.dukascopy.api.IIndicators.AppliedPrice;
@RequiresFullAccess
public class HLineKeyRemove implements IStrategy {
// public double EMA3 = 3;
private IChart chart;
private IHistory history;
private IConsole console;
private IIndicators indicators;
public Filter indicatorFilter = Filter.NO_FILTER;
public int SMA3 = 3;
@Override
public void onStart(IContext context) throws JFException {
this.chart = context.getChart(Instrument.EURUSD);
this.history = context.getHistory();
console = context.getConsole();
this.indicators = context.getIndicators();
}
@Override
public void onTick(Instrument instrument, ITick tick) throws JFException {}
@Override
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
IBar bar = history.getBar(Instrument.EURUSD, Period.FIVE_MINS, OfferSide.BID, 1) ;
double[] EMA3 = indicators.ema(instrument, Period.FIVE_MINS, OfferSide.BID, AppliedPrice.CLOSE, 3,indicatorFilter, 2, bar.getTime(), 0);
String key = "EMALine";
// IHorizontalLineChartObject hLine = chart.getChartObjectFactory().createHorizontalLine(key, tick.getBid());
IHorizontalLineChartObject Line = chart.getChartObjectFactory().createHorizontalLine(key, EMA3[1]);
Line.setColor(Color.WHITE);
chart.addToMainChartUnlocked(Line);
}
@Override
public void onMessage(IMessage message) throws JFException {}
@Override
public void onAccount(IAccount account) throws JFException {}
@Override
public void onStop() throws JFException {}
}