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.

Indicator from indicator
 Post subject: Indicator from indicator Post rating: 0   New post Posted: Fri 27 Nov, 2015, 15:21 
User avatar

User rating: 0
Joined: Fri 13 Dec, 2013, 17:53
Posts: 5
Location: PolandPoland
Good day!

I'm currently trying to call Ichimoku indicator from within another indicator to get its values, manipulate them
and get some other lines. I searched through this forum, found solution posted by Dukascopy Support,
used it and... got exception:

Caused by: java.lang.ClassCastException: java.lang.Integer cannot be cast to [[D
at com.dukascopy.indicators.IchimokuIndicator.setInputParameter(IchimokuIndicator.java:188)
at jforex.Indicator.setOptInputParameter(Indicator.java:102)
at com.dukascopy.charts.math.dataprovider.AbstractDataProvider.b(L:677)
at com.dukascopy.charts.math.dataprovider.AbstractDataProvider.i(L:479)
at com.dukascopy.charts.data.a.i(L:538)
at com.dukascopy.charts.chartbuilder.ah.a(L:79)
... 41 more

The code looks like this:
package jforex;
 
import com.dukascopy.api.indicators.IIndicator;
import com.dukascopy.api.indicators.IIndicatorContext;
import com.dukascopy.api.indicators.IIndicatorsProvider;
import com.dukascopy.api.indicators.IndicatorInfo;
import com.dukascopy.api.indicators.IndicatorResult;
import com.dukascopy.api.indicators.InputParameterInfo;
import com.dukascopy.api.indicators.IntegerRangeDescription;
import com.dukascopy.api.indicators.OptInputParameterInfo;
import com.dukascopy.api.indicators.OutputParameterInfo;
 
public class Indicator implements IIndicator{     
   private IndicatorInfo indicatorInfo;
   private InputParameterInfo[] inputParameterInfos;
   private OptInputParameterInfo[] optInputParameterInfos;
   private OutputParameterInfo[] outputParameterInfos;
   private double[][][] inputs = new double[1][][];     
   private double[][] outputs = new double[1][];   
   private IIndicator ichiIndicator;   
 
   public void onStart(IIndicatorContext context) {
      IIndicatorsProvider provider = context.getIndicatorsProvider();
      ichiIndicator = context.getIndicatorsProvider().getIndicator("ICHIMOKU");
        indicatorInfo = new IndicatorInfo("ICHIMOKUTENKAN", "Ichimoku tenkan", "", true, false, true, 1, 3, 1);
        inputParameterInfos = new InputParameterInfo[] {new InputParameterInfo("Price", InputParameterInfo.Type.PRICE)};
       optInputParameterInfos = new OptInputParameterInfo[] {
             new OptInputParameterInfo("Tenkan", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(9, 2, 400, 1)),
             new OptInputParameterInfo("Kijun", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(26, 2, 400, 1)),
             new OptInputParameterInfo("Senkou", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(52, 2, 400, 1))
      };
       outputParameterInfos = new OutputParameterInfo[] {
          new OutputParameterInfo("Tenkan Sen", OutputParameterInfo.Type.DOUBLE, OutputParameterInfo.DrawingStyle.LINE)                                         
       };
   }
 
   public IndicatorResult calculate(int startIndex, int endIndex) {         
      if (startIndex - getLookback() < 0) {
         startIndex -= startIndex - getLookback();
      }
      if (startIndex > endIndex) {
         return new IndicatorResult(0, 0);
       }                     
       
      double[] tenkanOutput = new double[endIndex - startIndex + 1];
      ichiIndicator.setInputParameter(0, inputs[0]);     
      ichiIndicator.setOutputParameter(0, tenkanOutput);
        ichiIndicator.setOutputParameter(1, new double[endIndex - startIndex + 1]);
        ichiIndicator.setOutputParameter(2, new double[endIndex - startIndex + 1]);
        ichiIndicator.setOutputParameter(3, new double[endIndex - startIndex + 1]);
        ichiIndicator.setOutputParameter(4, new double[endIndex - startIndex + 1]);
        ichiIndicator.setOutputParameter(5 , new Object[endIndex - startIndex + 1]);
 
      IndicatorResult res = ichiIndicator.calculate(startIndex, endIndex);
       
      for (int i = 0; i < res.getNumberOfElements(); i++){
         outputs[0][i] = tenkanOutput[i];
      }
      return res;     
   }
 
   public IndicatorInfo getIndicatorInfo() {
      return indicatorInfo;
   }
 
   public InputParameterInfo getInputParameterInfo(int index) {
      if (index <= inputParameterInfos.length) {
         return inputParameterInfos[index];
      }
      return null;
   }
 
   public int getLookback() {             
      return ichiIndicator.getLookback();
   }
 
   public int getLookforward() {
      return 0;
   }
 
   public OptInputParameterInfo getOptInputParameterInfo(int index) {
      if (index <= optInputParameterInfos.length) {
            return optInputParameterInfos[index];
        }
        return null;
   }
 
   public OutputParameterInfo getOutputParameterInfo(int index) {
      if (index <= outputParameterInfos.length) {
         return outputParameterInfos[index];
      }
      return null;
   }
 
   public void setInputParameter(int index, Object array) {
      inputs[index] = (double[][]) array;
   }
 
   public void setOptInputParameter(int index, Object value) {
       switch (index) {
            case 0:
                ichiIndicator.setInputParameter(0, value); \\<= line 102
                break;
            case 1:
               ichiIndicator.setOptInputParameter(1,  value);
                break;
            case 2:
               ichiIndicator.setOptInputParameter(2, value);
                break;
            default:
                throw new ArrayIndexOutOfBoundsException(index);
       }     
   }
 
   public void setOutputParameter(int index, Object array) {
      outputs[index] = (double[]) array;
   }
}




Regards

Marcin


 
 Post subject: Re: Indicator from indicator Post rating: 0   New post Posted: Mon 30 Nov, 2015, 10:04 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You should call IIndicator.setOptInputParameter() method in line 102, instead of setInputParameter().
ichiIndicator.setOptInputParameter(0, value);


 

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