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.

How to use the registerCustomIndicator() method?
 Post subject: How to use the registerCustomIndicator() method? Post rating: 0   New post Posted: Mon 11 Apr, 2011, 14:19 

User rating: 0
Joined: Sun 22 May, 2011, 23:43
Posts: 12
Location: Italy, Roma
Hi everybody,
can anyone show me an example of how to use the registerCustomIndicator() method available in the IIndicators interface?
I'm referring to the

registerCustomIndicator(java.lang.Class<? extends IIndicator> indicatorClass)


method that was recently added to the JForex API.

Thanks in advance for any suggestions.
Regards,
Paolo


 
 Post subject: Re: How to use the registerCustomIndicator() method? Post rating: 0   New post Posted: Tue 12 Apr, 2011, 12:32 

User rating: 0
Joined: Sun 22 May, 2011, 23:43
Posts: 12
Location: Italy, Roma
This is what I'm doing now in the onStart() method of my IStrategy:

Class c;
try {
   c = Class.forName("myPackage.myCustomIndicator");
   context.getIndicators().registerCustomIndicator(c);
} catch (ClassNotFoundException ex) {
    context.getConsole().getOut().println("IStrategy_onStart(): Exception: registerCustomIndicator() failed");
}


The registerCustomIndicator() method seems to work ok because the ClassNotFoundException is not triggered; however I get the following run-time exception:

com.dukascopy.api.JFException: Indicator info is null @ com.dukascopy.api.impl.ab.a(Unknown Source)

I can compile and use "myCustomIndicator" in JForex without problems, and its getIndicatorInfo() method is properly implemented.
I cannot sort out the above exception.
Any help is appreciated.
Kind regards,
Paolo


 
 Post subject: Re: How to use the registerCustomIndicator() method? Post rating: 0   New post Posted: Tue 12 Apr, 2011, 13:00 

User rating: 0
Joined: Sun 22 May, 2011, 23:43
Posts: 12
Location: Italy, Roma
I fixed the issue by initializing the "indicatorInfo" variable in the variable declaration itself.

This is an excerpt of my original code:

public class myCustomIndicator implements IIndicator {
   
    // other variables...
    public IndicatorInfo indicatorInfo;

    public void onStart(IIndicatorContext context) {
        indicatorInfo = new IndicatorInfo("MYCUST", "myCustomIndicator", "myIndicators", true, false, true, NUMBER_INPUTS, NUMBER_OPTIONAL_INPUTS, NUMBER_OUTPUTS);
   // other code...
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    // other IIndicator methods
}


And this is the fixed code I'm using now:

public class myCustomIndicator implements IIndicator {
 
    // other variables...
    public IndicatorInfo indicatorInfo = new IndicatorInfo("MYCUST", "myCustomIndicator", "myIndicators", true, false, true, NUMBER_INPUTS, NUMBER_OPTIONAL_INPUTS, NUMBER_OUTPUTS);

    public void onStart(IIndicatorContext context) {
        //indicatorInfo not initialized dnaymore here...
   // other code...
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    // other IIndicator methods
}


The problem was not so difficult after all! :D

Regards,
Paolo


 

Jump to:  

  © 1998-2026 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