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.

Use of CCI indicator in custom indicator
 Post subject: Use of CCI indicator in custom indicator Post rating: 0   New post Posted: Thu 14 Jul, 2011, 14:53 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:47
Posts: 5
Location: DE
I try to use the CCI indicator in my custom indicator.
IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
      cci = indicatorsProvider.getIndicator("CCI");

....

cci.setInputParameter(0, inputs[0]);


But I only get a "13:44:32 Error in indicator: java.lang.ClassCastException" message. What I am doing wrong? Where is the CCI indicator defined?

Thanks for your support.


 
 Post subject: Re: Use of CCI indicator in custom indicator Post rating: 0   New post Posted: Fri 15 Jul, 2011, 10:29 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
forexhero wrote:
What I am doing wrong?
You are passing a wrong input type.
forexhero wrote:
Where is the CCI indicator defined?
The indicator is not published in the API, meaning that its source is not accessible. However, you can find out its inputs and outputs in the following way:
    public void onStart(IIndicatorContext context) {  
        //(..)
        IIndicator cci = context.getIndicatorsProvider().getIndicator("CCI");
        printIndicatorInfos(cci);
    }
    private void print(Object o){
       console.getOut().println(o);
    }
   
    private void printIndicatorInfos(IIndicator ind){
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfInputs(); i++){
           print(ind.getIndicatorInfo().getName() +" Input " + ind.getInputParameterInfo(i).getName() +" " + ind.getInputParameterInfo(i).getType());
        }
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOptionalInputs(); i++){
           print(ind.getIndicatorInfo().getName() +" Opt Input " + ind.getOptInputParameterInfo(i).getName() +" " + ind.getOptInputParameterInfo(i).getType());
        }
        for (int i = 0; i < ind.getIndicatorInfo().getNumberOfOutputs(); i++){
           print(ind.getIndicatorInfo().getName() +" Output " + ind.getOutputParameterInfo(i).getName() +" " + ind.getOutputParameterInfo(i).getType());
        }
    }


 
 Post subject: Re: Use of CCI indicator in custom indicator Post rating: 0   New post Posted: Mon 18 Jul, 2011, 09:56 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:47
Posts: 5
Location: DE
Thanks for your help. Will try this later.


 
 Post subject: Re: Use of CCI indicator in custom indicator Post rating: 0   New post Posted: Thu 21 Jul, 2011, 12:16 

User rating: 0
Joined: Thu 30 Jun, 2011, 20:47
Posts: 5
Location: DE
Ok. Fixed it ... :D The input parameters were wrong. CCI expects a HLC price instead of a double array.


private double[][][] inputs = new double[1][][]; // HLC price


public void onStart(IIndicatorContext context) {           
   
      
      IIndicatorsProvider indicatorsProvider = context.getIndicatorsProvider();
      cci = indicatorsProvider.getIndicator("CCI");
      printIndicatorInfos(cci);
   
...

      inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)};

      .....
   }


public IndicatorResult calculate(int startIndex, int endIndex) {       
   if (startIndex - getLookback() < 0) {
           startIndex -= startIndex - getLookback();
        }
        if (startIndex > endIndex) {
            return new IndicatorResult(0, 0);
        }
       
        double[] dcci = new double[endIndex - startIndex + cci.getLookback()+1];

      cci.setInputParameter(0, inputs[0]);
      cci.setOutputParameter(0, dcci);
      IndicatorResult rsiResult = cci.calculate(startIndex-filter.getLookback(), endIndex);
      

   }

...


Thanks again for your quick response.

Yours
forexhero


 

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