Dukascopy
 
 
Wiki JStore Search Login

context.getFeedDescriptor() bug?
 Post subject: context.getFeedDescriptor() bug? Post rating: 0   New post Posted: Thu 08 Aug, 2013, 08:17 

User rating: 0
Joined: Tue 18 Jun, 2013, 21:55
Posts: 14
Location: Slovakia, Nitra
Hello,

I have a problem with custom indicator and maybe that's a bug...

I have MY first custom indicator e.g.:

public class FirstIndicator implements IIndicator {
  private IIndicatorContext context;
  private Period period;
  // ...

  public IndicatorResult calculate(...) {
      period = context.getFeedDescriptor().getPeriod();
// ...
   }
}


and MY second custom indicator call the first one...

public class SecondIndicator implements IIndicator {
  private IIndicatorContext context;

  // ...

  public IndicatorResult calculate(...) {
      context.getIndicatorsProvider().getIndicator("First" [, context ]).calculate(...);

   }
}


Compiling is without error...

But when I launch the second indicator, there is a NullPointerException ...

And when I looked nearly where it occurs, as a result of it is in FirstIndicator when calculate method calls getFeedDescriptor(), so probably it is a null (alternatively getPeriod()).

And when I launch independently the first indicator, it all works correctly...

Regards
bojno


 
 Post subject: Re: context.getFeedDescriptor() bug? Post rating: 0   New post Posted: Tue 20 Aug, 2013, 20:39 

User rating: 1
Joined: Tue 12 Jul, 2011, 20:43
Posts: 51
Location: Germany,
Hello Support,

I have the same problem.

I created a custom indicator wich calls IIndicatorContext.getFeedDescriptor().getPeriod().getInterval() in it's getLookback() method.
Also I have a second custom indicator which uses the first one.
When I'm calling IIndicatorContext.getIndicatorsProvider().getIndicator("First").getLookback() inside the getLookback() method of the second indicator, a NullPointerException is thrown.

Can you please provide a solution for this issue?

Regards
AbsoluteReturner


 
 Post subject: Re: context.getFeedDescriptor() bug? Post rating: 0   New post Posted: Wed 21 Aug, 2013, 08:59 

User rating: 0
Joined: Tue 18 Jun, 2013, 21:55
Posts: 14
Location: Slovakia, Nitra
Hello bro,

I found a little work-around for this...

In the first indicator add an optional parameter e.g. "Period Interval" to the end of array of OptInputParameterInfo and in IndicatorInfo set parameter numberOfOptionalInputs = Optional Input Count - 1 (-1 hide the Period Interval (because of last), so you can't set it manually)...

And in the first indicator you must add some condition like:

int interval = 0;
if (IIndicatorContext.getFeedDescriptor() == null) {
    interval = optionalInputPeriodInterval;
} else {
    interval = IIndicatorContext.getFeedDescriptor().getPeriod().getInterval();
}


In the second indicator you must set firstIndicator.setOptInputParameter(Number of Period Interval, IIndicatorContext.getFeedDescriptor().getPeriod().getInterval()).

I hope this help you...

Regards
bojno


 
The Best Answer  Post subject: Re: context.getFeedDescriptor() bug? Post rating: 1   New post Posted: Fri 23 Aug, 2013, 07:53 
JForex Master
User avatar

User rating:
Joined: Wed 16 Sep, 2009, 18:23
Posts: 1054
Location: Geneva, Switzerland
You have to provide those inner indicators you use with the IIndicatorContext object from the main indicator you add on chart - there's a method for this IIndicatorContext.getIndicator(String name, IIndicatorContext context).
e.g.
IIndicator first = context.getIndicator("First", context);
... //set optional input, input,output, then call first.calculate(startIndex, endIndex);


 

Jump to:  

cron
  © 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