ccadar wrote:
but how can I get the "IFeedDescriptor feedDescriptor" and feedData.getTime() variables from within the context.subscribeToTickBarFeed function?
You need to use
IContext.subscribeToFeed, consider modifying our given wiki example to use the heikin ashi indicator:
public class TickBarsHeikinAshi implements IStrategy, IFeedListener {
private IConsole console;
private IIndicators indicators;
@Configurable(value = "feed type", description = "choose any type of feed (except ticks) in the strategy parameters dialog")
public IFeedDescriptor feedDescriptor = new TickBarFeedDescriptor(Instrument.EURUSD, TickBarSize.valueOf(70), OfferSide.BID);
@Override
public void onStart(IContext context) throws JFException {
console = context.getConsole();
indicators = context.getIndicators();
if (feedDescriptor.getDataType() == DataType.TICKS) {
console.getErr().println("IFeedListener does not work with ticks yet!");
context.stop();
}
context.setSubscribedInstruments(new HashSet<Instrument>(Arrays.asList(new Instrument[] { feedDescriptor.getInstrument() })), true);
console.getOut().println("subscribe to feed=" + feedDescriptor);
context.subscribeToFeed(feedDescriptor, this);
}
@Override
public void onFeedData(IFeedDescriptor feedDescriptor, ITimedData feedData) {
console.getInfo().println(feedData + " of feed: " + feedDescriptor);
try {
double[] c = (double[]) indicators.calculateIndicator(feedDescriptor, new OfferSide[] { OfferSide.BID }, "HeikinAshi",
new AppliedPrice[] { AppliedPrice.CLOSE }, null, 1)[0];
console.getOut().format("%s ha O: %.5f H: %.5f L: %.5f C: %.5f ", DateUtils.format(feedData.getTime()), c[OPEN], c[HIGH], c[LOW], c[CLOSE]).println();
} catch (JFException e) {
console.getErr().println(e);
e.printStackTrace();
}
}
ccadar wrote:
I don't really understand the connection between ITickBarFeedListener and IFeedDescriptor here.
There is no connection between those two rather IFeedListener is a generalization of ITickBarFeedListener and IFeedDescriptor correspondingly of TickBarFeedDescriptor. Using more general methods gives you more flexibility in adjusting the strategy when the business logic changes - for instance, in the given example you may switch to using 1-minute candles or, say, renko bricks simply by changing the feed descriptor parameter in the strategy dialog, without any additional coding required.