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.

Calling Ichimoku from within a custom indicator
 Post subject: Calling Ichimoku from within a custom indicator Post rating: 0   New post Posted: Wed 10 Nov, 2010, 09:06 

User rating: 0
Joined: Wed 10 Nov, 2010, 00:56
Posts: 16
Using the examples listed on the wiki + in various post i have not been able to call the ichimoku indicator from within an indicator using the IIndicatorsProvider + .calculate. I only managed to do it from a strategy with indicators.calculateIndicator.

Could someone please provide an example to call the ichimoku indicator from within another indicator? e.g. Extract specific return values like the TenkanSen or KijunSen from the result.

Thank you very much


 
 Post subject: Re: Calling Ichimoku from within a custom indicator Post rating: 0   New post Posted: Fri 07 Jan, 2011, 13:14 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Hi,
Please have a look at the following code:
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 IchimokuTenkanIndicator 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 ichimoku;    

   public void onStart(IIndicatorContext context) {
      IIndicatorsProvider provider = context.getIndicatorsProvider();
      ichimoku = provider.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];
      ichimoku.setInputParameter(0, inputs[0]);      
      ichimoku.setOutputParameter(0, tenkanOutput);
        ichimoku.setOutputParameter(1, new double[endIndex - startIndex + 1]);
        ichimoku.setOutputParameter(2, new double[endIndex - startIndex + 1]);
        ichimoku.setOutputParameter(3, new double[endIndex - startIndex + 1]);
        ichimoku.setOutputParameter(4, new double[endIndex - startIndex + 1]);
        ichimoku.setOutputParameter(5 , new Object[endIndex - startIndex + 1]);

      IndicatorResult res = ichimoku.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 ichimoku.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:
                ichimoku.setOptInputParameter(0, value);
                break;
            case 1:
               ichimoku.setOptInputParameter(1, value);
                break;
            case 2:
               ichimoku.setOptInputParameter(2, value);
                break;
            default:
                throw new ArrayIndexOutOfBoundsException(index);
       }     
   }

   public void setOutputParameter(int index, Object array) {
      outputs[index] = (double[]) array;
   }
}


 

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