I created a custom indicator, which works without problem when applied directly to a chart in JForex. I am now trying to use the indicator in a strategy like this:
//...
IFeedDescriptor feedDescriptor = chart != null
? chart.getFeedDescriptor()
: new TimePeriodAggregationFeedDescriptor(instrument, period, OfferSide.BID, Filter.WEEKENDS);
IIndicators indicators = context.getIndicators();
String indPath = getClass().getAnnotation(CustomIndicators.class).value();
IIndicator customIndicator = indicators.getIndicatorByPath(indPath);
String indName = mtIndicator.getIndicatorInfo().getName();
Object[] results = indicators.calculateIndicator(feedDescriptor, new OfferSide[] {OfferSide.BID}, indName, new AppliedPrice[]{AppliedPrice.CLOSE}, new Object[]{mtPercentThreshold}, 1);
//...
When the strategy calls my custom indicator I get a NullPointerException when the indicator tries to get the instrument from the feed descriptor. Specifically:
public class CustomIndicator implements IIndicator {
private IFeedDescriptor feedDescriptor;
public void onStart(IIndicatorContext context) {
//...
feedDescriptor = context.getFeedDescriptor();
//...
}
public IndicatorResult calculate(int startIndex, int endIndex) {
//...
Instrument instrument = feedDescriptor.getInstrument(); //NullPointerException here
//...
}
}
Again, the custom indicator works without error when run directly on an active chart. Why is a NullPointerException thrown when the indicator is used in my strategy? How do I properly use a custom indicator? Thank you very much for any assistance you can provide.