DEMA & TEMA Ta-lib Java Implementation

795 views Asked by At

I am currently working with Ta-lib Java implementations. I can run properly MA & SUM. But having problem while try to run DEMA, TEMA. The output is all zeros. I am calling the DEMA & TEMA method of Ta-lib as follows

import com.tictactec.ta.lib.Core;
import com.tictactec.ta.lib.MInteger;


public class TALibJava {
    double[] array = {207.650, 205.160, 210.870, 209.350, 207.250, 209.960, 207.650, 205.160, 188.170, 186.020};
    double[] output = new double[array.length];
    int period = 5;
    Core core = new Core();
    int lookback = 0;
    MInteger begin = new MInteger();
    MInteger length = new MInteger();

    public void callDEMA() {
        lookback = core.demaLookback(period);
        core.dema(0, array.length - 1, array, 0, begin, length, output);
        System.out.println("DEMA Output: ");
        print();
    }

    public void callTEMA() {
        lookback = core.temaLookback(period);
        core.tema(0, array.length - 1, array, 0, begin, length, output);
        System.out.println("TEMA Output: ");
        print();
    }

    public void print() {
        for(int i=0;i<array.length;i++) {
            System.out.print(output[i] + "\t ");
        }
        System.out.println("");
    }

    public static void main(String args[]) {
        TALibJava obj = new TALibJava();
        obj.callDEMA();
        obj.callTEMA();
    }

}

Perhaps the input parameters are not properly set. Please suggest me what I'm doing wrong.

1

There are 1 answers

2
AudioBubble On BEST ANSWER

According to the source code of dema(), optInTimePeriod cannot be 0:

else if( ((int)optInTimePeriod < 2) || ((int)optInTimePeriod > 100000) )
     return RetCode.BadParam ;

That's why your current code returns "BadParam" and not "Success" when you call dema().

(Same thing goes for tema())