@Override public String getLabel() { return properties.getLabel() + " (" + properties.getPeriod() + ", " + properties.getPeriodK() + ", " + properties.getPeriodD() + ")"; }
@Override public void calculate() { Dataset initial = getDataset(); int count = 0; if (initial != null && !initial.isEmpty()) count = initial.getItemsCount(); /** ******************************************************************* */ // This entire method is basically a copy/paste action into your own // code. The only thing you have to change is the next few lines of code. // Choose the 'lookback' method and appropriate 'calculation function' // from TA-Lib for your needs. Everything else should stay basically the // same // prepare ta-lib variables outputFastD = new double[count]; outputFastK = new double[count]; outBegIdx = new MInteger(); outNbElement = new MInteger(); core = TaLibInit.getCore(); // needs to be here for serialization issues // [your specific indicator variables need to be set first] periodK = properties.getPeriodK(); periodD = properties.getPeriodD(); period = properties.getPeriod(); // now do the calculation over the entire dataset // [First, perform the lookback call if one exists] // [Second, do the calculation call from TA-lib] lookback = core.stochRsiLookback(period, periodK, periodD, MAType.Sma); core.stochRsi( 0, count - 1, initial.getCloseValues(), period, periodK, periodD, MAType.Sma, outBegIdx, outNbElement, outputFastK, outputFastD); // Everything between the /***/ lines is what needs to be changed. // Everything else remains the same. You are done with your part now. /** ******************************************************************* */ // fix the output array's structure. TA-Lib does NOT match // indicator index and dataset index automatically. That's what // this function does for us. outputFastD = TaLibUtilities.fixOutputArray(outputFastD, lookback); outputFastK = TaLibUtilities.fixOutputArray(outputFastK, lookback); calculatedDatasetFastD = Dataset.EMPTY(initial.getItemsCount()); for (int i = 0; i < outputFastD.length; i++) calculatedDatasetFastD.setDataItem(i, new DataItem(initial.getTimeAt(i), outputFastD[i])); calculatedDatasetFastK = Dataset.EMPTY(initial.getItemsCount()); for (int i = 0; i < outputFastK.length; i++) calculatedDatasetFastK.setDataItem(i, new DataItem(initial.getTimeAt(i), outputFastK[i])); addDataset(FASTD, calculatedDatasetFastD); addDataset(FASTK, calculatedDatasetFastK); }