You need to subscribe to each indicator separately using different FeedDescriptor instances.
import com.dukascopy.api.*;
import com.dukascopy.api.feed.FeedDescriptor;
import com.dukascopy.api.feed.IFeedDescriptor;
import com.dukascopy.api.feed.IFeedListener;
import com.dukascopy.api.feed.IRenkoBar;
import java.util.HashSet;
public class StrategyFeeds implements IStrategy, IFeedListener {
private IEngine engine;
private IConsole console;
private IHistory _history;
private IContext context;
private IIndicators _indicators;
private IUserInterface userInterface;
private IContext _context;
int _renkoBrickSize = 0;
int _emaPeriod = 5;
private HashSet<Instrument> _instSet;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this._history = context.getHistory();
this.context = context;
this._indicators = context.getIndicators();
this.userInterface = context.getUserInterface();
this._context = context;
//subscribe to instruments
_instSet = new HashSet<Instrument>();
_instSet.add(Instrument.GBPUSD);
_instSet.add(Instrument.EURUSD);
context.setSubscribedInstruments(_instSet);
// create feed
for(Instrument instr : _instSet) {
FeedDescriptor _feed = new FeedDescriptor();
_feed.setInstrument(instr); // TODO: How to create multiple instruments for a feed?
_feed.setDataType(DataType.RENKO);
_feed.setFilter(Filter.WEEKENDS);
_feed.setOfferSide(OfferSide.BID);
_feed.setPriceRange(PriceRange.valueOf(_renkoBrickSize));
//debugPrint (INFO, "Feed = " + _feed.toString());
//subscribing to custom Period
_context.subscribeToFeed(_feed, this);
}
}
@Override
public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData)
{
Instrument instrument = feedDescriptor.getInstrument();
IRenkoBar renkoBar = (IRenkoBar) feedData;
int numberBars = 2;
if (_instSet.contains(instrument))
{
try
{
// update indicator values
IRenkoBar lastRenkoBar = _history.getRenkoBar(instrument, OfferSide.BID, PriceRange.valueOf(_renkoBrickSize), 0);
//debugPrint(INFO, "LastRenkoBar start time: " + sdf.format(lastRenkoBar.getTime()));
//debugPrint(INFO, "feedData: RenkBar start time: " + sdf.format(renkoBar.getTime()));
long currentBarTime = lastRenkoBar.getTime();
// ema indicator
Object[] Values = _indicators.calculateIndicator(feedDescriptor,
new OfferSide[] {OfferSide.BID},
"EMA",
new IIndicators.AppliedPrice[] { IIndicators.AppliedPrice.CLOSE },
new Object[] { _emaPeriod },
numberBars,
currentBarTime,
0);
double[] emaValues = (double[]) Values[0];
//ema = emaValues[0];
}
catch (JFException e)
{
console.getOut().println(instrument.toString() + " " + "Exception: " + e.toString());
e.printStackTrace();
}
}
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
}
}