Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

Custom indicator giving NullPointerException on feedDescriptor when used in strategy
 Post subject: Custom indicator giving NullPointerException on feedDescriptor when used in strategy Post rating: 0   New post Posted: Thu 12 Apr, 2018, 17:31 

User rating: 0
Joined: Thu 11 Jan, 2018, 17:52
Posts: 5
Location: CanadaCanada
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.


 
 Post subject: Re: Custom indicator giving NullPointerException on feedDescriptor when used in strategy Post rating: 0   New post Posted: Wed 18 Apr, 2018, 09:50 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
We cannot reproduce this issue, but it looks like a error with incorrect FeedDescriptor initialization in your strategy. Please, provide strategy example.


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com