EzDevInfo.com

ta-lib

Python wrapper for TA-Lib (<a href="http://ta-lib.org/">http://ta-lib.org/</a>). TA-Lib ta-lib : python wrapper for ta-lib (http://ta-lib.org/).

building the ta-lib library fails with undefined references from libm.so

Trying to make the ta-lib library (ta-lib-0.4.0-src.tar.gz) I get the following error:

/home/me/ta-lib/src/.libs/libta_lib.so: undefined reference to `sinh'
/home/me/ta-lib/src/.libs/libta_lib.so: undefined reference to `sincos'
/home/me/ta-lib/src/.libs/libta_lib.so: undefined reference to `ceil'
...

for a large number of maths functions.

The failing command looks like this:

gcc -g -O2 -o .libs/ta_regtest (... .o files) -L/home/me/ta-lib/src \
    /home/me/ta-lib/src/.libs/libta_lib.so -lm -lpthread -ldl

The offending library (ta_lib) looks like this:

objdump -TC libta_lib.so | grep "    D  \*UND\*"
0000000000000000      D  *UND*  0000000000000000              sinh
0000000000000000      D  *UND*  0000000000000000              sincos
0000000000000000      D  *UND*  0000000000000000              ceil
...

For the same maths functions (the grep excludes defined functions and those that have a "w" (presumably weak) flag)

A map lists the libraries included, among them:

LOAD /usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libm.so

and a list of the symbols (objdump -TC) defined in libm.so includes:

000000000001a320  w  iD  .text  0000000000000020  GLIBC_2.2.5 ceil

which was one of the undefined references (they are all there). I cannot determine the meaning of GLIBC_2.2.5.

Why is the loader not finding these functions?

My system looks like this:

$ uname -a
Linux mynode 3.5.0-17-generic #28-Ubuntu SMP Tue Oct 9 19:31:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

Source: (StackOverflow)

C++ & ta_lib - cannot work out how to use TA_MACD function

This is my first c++ program and I'm not very familar with c either so please be gentle with me!

I'm trying to call the TA_MACD function from the ta_lib library and having no success. Could someone help me out please.

My code is this:

#include <iostream>
#include "ta_libc.h"

using namespace std;

void go(const TA_Real *array[], TA_Integer fastPeriod, TA_Integer slowPeriod, TA_Integer signalPeriod);

struct Struct_Macd
{
    double Macd;
    double Signal;
    double Histogram;
} MacdResult;

int main(int argc, char**argv) 
{
    TA_Real close_data[]={1.09999000,1.09995000,1.09996000,1.09995000,1.09994000,1.09993000,1.09994000,1.09996000,
                        1.09997000,1.09999000,1.10000000,1.09999000,1.10000000,1.09998000,1.09999000,1.09998000,
                        1.09999000,1.10000000,1.10001000,1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10005000,1.10006000,1.10007000,1.10008000,
                        1.10012000,1.10011000,1.10012000,1.10011000,1.10013000,1.10014000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10017000,1.10018000,1.10019000,1.10018000,1.10017000,
                        1.10018000,1.10017000,1.10018000,1.10017000,1.10016000,1.10014000,1.10013000,1.10015000,
                        1.10014000,1.10015000,1.10014000,1.10013000,1.10012000,1.10011000,1.10010000,1.10011000,
                        1.10010000,1.10011000,1.10010000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,
                        1.10008000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,1.10004000,
                        1.10003000,1.10002000,1.10007000,1.10008000,1.10007000,1.10008000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10009000,1.10008000,1.10009000,1.10008000,1.10007000,1.10008000,
                        1.10007000,1.10006000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,
                        1.10012000,1.10013000,1.10014000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10017000,
                        1.10018000,1.10019000,1.10020000,1.10019000,1.10020000,1.10019000,1.10018000,1.10019000,
                        1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10019000,
                        1.10018000,1.10019000,1.10018000,1.10019000,1.10018000,1.10019000,1.10017000,1.10018000,
                        1.10016000,1.10017000,1.10016000,1.10015000,1.10011000,1.10013000,1.10014000,1.10013000,
                        1.10014000,1.10013000,1.10015000,1.10014000,1.10015000,1.10016000,1.10015000,1.10014000,
                        1.10013000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,
                        1.10011000,1.10012000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,1.10006000,
                        1.10007000,1.10006000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,
                        1.10005000,1.10004000,1.10003000,1.10002000,1.10001000,1.10002000,1.10001000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10005000,1.10006000,1.10014000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10007000,1.10006000,1.10005000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,
                        1.10001000,1.10000000,1.09999000,1.09998000,1.09997000,1.09998000,1.09997000,1.09999000,
                        1.09998000,1.10000000,1.09999000,1.10000000,1.09999000,1.10000000,1.09999000,1.09998000,
                        1.09999000,1.09998000,1.09999000,1.10000000,1.10001000,1.10002000,1.10006000,1.10004000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10001000,1.10000000,1.09998000,1.09999000,
                        1.09998000,1.09999000,1.09997000};

    go(close_data,12,26,9);
    return 0;
}

void go(const TA_Real *array[], TA_Integer fastPeriod, TA_Integer slowPeriod, TA_Integer signalPeriod) {
    TA_Integer outBegin = 0, outElements = 0;
    TA_Real outMacd[];
    TA_Real outSignal[];
    TA_Real outHistogram[];

    TA_RetCode retCode = TA_MACD( (sizeof(array)/sizeof(*array))-1-slowPeriod, (sizeof(array)/sizeof(*array))-1, array, fastPeriod, slowPeriod, signalPeriod, &outBegin, &outElements, outMacd, outSignal, outHistogram );    

    if(retCode == TA_SUCCESS) 
    {
        int lastElement = outElements-1;
        MacdResult.Macd = outMacd[lastElement];
        MacdResult.Signal = outSignal[lastElement];
        MacdResult.Histogram = outHistogram[lastElement];

        cout << "Macd = " << MacdResult.Macd << " Signal = " << MacdResult.Signal << " Histograme = " << MacdResult.Histogram << endl;
    }
}

When I compile using MinGW I get the following errors:

"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/ypx7647/Documents/NetBeansProjects/TA_MACD Example'
"/C/MinGW/msys/1.0/bin/make.exe"  -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/ta_macd_example.exe
make.exe[2]: Entering directory `/c/Users/ypx7647/Documents/NetBeansProjects/TA_MACD Example'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/io.o.d"
g++    -c -g -I/C/ta-lib-0.4.0-msvc/ta-lib/c/include -MMD -MP -MF "build/Debug/MinGW-Windows/io.o.d" -o build/Debug/MinGW-Windows/io.o io.cpp
io.cpp: In function `int main(int, char**)':
io.cpp:51: error: cannot convert `TA_Real*' to `const TA_Real**' for argument `1' to `void go(const TA_Real**, TA_Integer, TA_Integer, TA_Integer)'
io.cpp: In function `void go(const TA_Real**, TA_Integer, TA_Integer, TA_Integer)':
io.cpp:57: error: storage size of `outMacd' isn't known
io.cpp:58: error: storage size of `outSignal' isn't known
io.cpp:59: error: storage size of `outHistogram' isn't known
io.cpp:61: error: cannot convert `const TA_Real**' to `const double*' for argument `3' to `TA_RetCode TA_MACD(int, int, const double*, int, int, int, int*, int*, double*, double*, double*)'
make.exe[2]: *** [build/Debug/MinGW-Windows/io.o] Error 1
make.exe[2]: Leaving directory `/c/Users/ypx7647/Documents/NetBeansProjects/TA_MACD Example'
make.exe[1]: *** [.build-conf] Error 2
make.exe[1]: Leaving directory `/c/Users/ypx7647/Documents/NetBeansProjects/TA_MACD Example'
make.exe": *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 10s)

I'll be the first to admit that I don't know what I'm doing so any help will be appreciated.

Also, how do I set the size of the out variables when I don't know how many the TA_MACD function is returning?

Thanks in advance.

After modification using the C++11 Std I'm here now, still with problems.

#include <iostream>
#include <array>
#include "ta_libc.h"

using namespace std;

struct Struct_Macd
{
    double Macd;
    double Signal;
    double Histogram;
} MacdResult;

void go(TA_Real *close, const int array_size, TA_Integer fastPeriod, TA_Integer slowPeriod, TA_Integer signalPeriod)
{
    TA_Integer outBegin = 0, outElements = 0;
    array<TA_Real, array_size-1> outMacd;
    array<TA_Real, array_size-1> outSignal;
    array<TA_Real, array_size-1> outHistogram;

    TA_RetCode retCode = TA_MACD( array_size-1-slowPeriod, array_size-1, close, fastPeriod, slowPeriod, signalPeriod, &outBegin, &outElements, outMacd, outSignal, outHistogram );

    if(retCode == TA_SUCCESS)
    {
        int lastElement = outElements-1;
        MacdResult.Macd = outMacd[lastElement];
        MacdResult.Signal = outSignal[lastElement];
        MacdResult.Histogram = outHistogram[lastElement];

        cout << "Macd = " << MacdResult.Macd << " Signal = " << MacdResult.Signal << " Histograme = " << MacdResult.Histogram << endl;
    }
}

int main(int argc, char**argv)
{
    array<TA_Real,259> close_data={1.09999000,1.09995000,1.09996000,1.09995000,1.09994000,1.09993000,1.09994000,1.09996000,
                        1.09997000,1.09999000,1.10000000,1.09999000,1.10000000,1.09998000,1.09999000,1.09998000,
                        1.09999000,1.10000000,1.10001000,1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10005000,1.10006000,1.10007000,1.10008000,
                        1.10012000,1.10011000,1.10012000,1.10011000,1.10013000,1.10014000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10017000,1.10018000,1.10019000,1.10018000,1.10017000,
                        1.10018000,1.10017000,1.10018000,1.10017000,1.10016000,1.10014000,1.10013000,1.10015000,
                        1.10014000,1.10015000,1.10014000,1.10013000,1.10012000,1.10011000,1.10010000,1.10011000,
                        1.10010000,1.10011000,1.10010000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,
                        1.10008000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,1.10004000,
                        1.10003000,1.10002000,1.10007000,1.10008000,1.10007000,1.10008000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10009000,1.10008000,1.10009000,1.10008000,1.10007000,1.10008000,
                        1.10007000,1.10006000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,
                        1.10012000,1.10013000,1.10014000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10017000,
                        1.10018000,1.10019000,1.10020000,1.10019000,1.10020000,1.10019000,1.10018000,1.10019000,
                        1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10019000,
                        1.10018000,1.10019000,1.10018000,1.10019000,1.10018000,1.10019000,1.10017000,1.10018000,
                        1.10016000,1.10017000,1.10016000,1.10015000,1.10011000,1.10013000,1.10014000,1.10013000,
                        1.10014000,1.10013000,1.10015000,1.10014000,1.10015000,1.10016000,1.10015000,1.10014000,
                        1.10013000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,
                        1.10011000,1.10012000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,1.10006000,
                        1.10007000,1.10006000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,
                        1.10005000,1.10004000,1.10003000,1.10002000,1.10001000,1.10002000,1.10001000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10005000,1.10006000,1.10014000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10007000,1.10006000,1.10005000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,
                        1.10001000,1.10000000,1.09999000,1.09998000,1.09997000,1.09998000,1.09997000,1.09999000,
                        1.09998000,1.10000000,1.09999000,1.10000000,1.09999000,1.10000000,1.09999000,1.09998000,
                        1.09999000,1.09998000,1.09999000,1.10000000,1.10001000,1.10002000,1.10006000,1.10004000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10001000,1.10000000,1.09998000,1.09999000,
                        1.09998000,1.09999000,1.09997000};

    go(close_data,close_data.size(),12,26,9);
    return 0;
}

This is the output:

||=== Build: Debug in Test (compiler: GNU GCC Compiler) ===|
C:\Users\ypx7647\Documents\C++\Test\main.cpp||In function 'void go(TA_Real*, int, TA_Integer, TA_Integer, TA_Integer)':|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|17|error: 'array_size' is not a constant expression|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|17|note: in template argument for type 'unsigned int' |
C:\Users\ypx7647\Documents\C++\Test\main.cpp|17|error: invalid type in declaration before ';' token|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|18|error: 'array_size' is not a constant expression|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|18|note: in template argument for type 'unsigned int' |
C:\Users\ypx7647\Documents\C++\Test\main.cpp|18|error: invalid type in declaration before ';' token|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|19|error: 'array_size' is not a constant expression|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|19|note: in template argument for type 'unsigned int' |
C:\Users\ypx7647\Documents\C++\Test\main.cpp|19|error: invalid type in declaration before ';' token|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|21|error: invalid conversion from 'int' to 'double*' [-fpermissive]|
..\..\..\..\..\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_func.h|3242|error:   initializing argument 9 of 'TA_RetCode TA_MACD(int, int, const double*, int, int, int, int*, int*, double*, double*, double*)' [-fpermissive]|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|21|error: invalid conversion from 'int' to 'double*' [-fpermissive]|
..\..\..\..\..\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_func.h|3242|error:   initializing argument 10 of 'TA_RetCode TA_MACD(int, int, const double*, int, int, int, int*, int*, double*, double*, double*)' [-fpermissive]|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|21|error: invalid conversion from 'int' to 'double*' [-fpermissive]|
..\..\..\..\..\ta-lib-0.4.0-msvc\ta-lib\c\include\ta_func.h|3242|error:   initializing argument 11 of 'TA_RetCode TA_MACD(int, int, const double*, int, int, int, int*, int*, double*, double*, double*)' [-fpermissive]|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|26|error: invalid types 'int[int]' for array subscript|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|27|error: invalid types 'int[int]' for array subscript|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|28|error: invalid types 'int[int]' for array subscript|
C:\Users\ypx7647\Documents\C++\Test\main.cpp||In function 'int main(int, char**)':|
C:\Users\ypx7647\Documents\C++\Test\main.cpp|70|error: cannot convert 'std::array<double, 259u>' to 'TA_Real* {aka double*}' for argument '1' to 'void go(TA_Real*, int, TA_Integer, TA_Integer, TA_Integer)'|
||=== Build failed: 16 error(s), 0 warning(s) (0 minute(s), 1 second(s)) ===|

Having made the modifications and adaptations suggested my code is now:

#include <iostream>
#include <vector>
#include "ta_libc.h"

using namespace std;

struct Struct_Macd
{
    double Macd;
    double Signal;
    double Histogram;
} MacdResult;

void go(const vector<TA_Real> &close, TA_Integer fastPeriod, TA_Integer slowPeriod, TA_Integer signalPeriod)
{
    TA_Integer outBegin = 0, outElements = 0;

    int beginIndx = close.size()-1-slowPeriod;
    int endIndx = close.size()-1;
    int array_size = endIndx - beginIndx + 1;
    vector<TA_Real> outMacd(array_size, 0.0);
    vector<TA_Real> outSignal(array_size, 0.0);
    vector<TA_Real> outHistogram(array_size, 0.0);

    const TA_Real* close_c_pointer = close.data();
    TA_Real* outMacd_c_pointer = outMacd.data();
    TA_Real* outSignal_c_pointer = outMacd.data();
    TA_Real* outHistogram_c_pointer = outMacd.data();

    TA_RetCode retCode = TA_MACD( beginIndx, endIndx, close_c_pointer, fastPeriod, slowPeriod, signalPeriod, &outBegin, &outElements, outMacd_c_pointer, outSignal_c_pointer, outHistogram_c_pointer );

    if(retCode == TA_SUCCESS)
    {
        int lastElement = outElements-1;
        MacdResult.Macd = outMacd[lastElement];
        MacdResult.Signal = outSignal[lastElement];
        MacdResult.Histogram = outHistogram[lastElement];

        cout << "Macd = " << MacdResult.Macd << " Signal = " << MacdResult.Signal << " Histograme = " << MacdResult.Histogram << endl;
    }
}

int main(int argc, char**argv)
{
    vector<TA_Real> close_data {1.09999000,1.09995000,1.09996000,1.09995000,1.09994000,1.09993000,1.09994000,1.09996000,
                        1.09997000,1.09999000,1.10000000,1.09999000,1.10000000,1.09998000,1.09999000,1.09998000,
                        1.09999000,1.10000000,1.10001000,1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10005000,1.10006000,1.10007000,1.10008000,
                        1.10012000,1.10011000,1.10012000,1.10011000,1.10013000,1.10014000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10017000,1.10018000,1.10019000,1.10018000,1.10017000,
                        1.10018000,1.10017000,1.10018000,1.10017000,1.10016000,1.10014000,1.10013000,1.10015000,
                        1.10014000,1.10015000,1.10014000,1.10013000,1.10012000,1.10011000,1.10010000,1.10011000,
                        1.10010000,1.10011000,1.10010000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,
                        1.10008000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,1.10004000,
                        1.10003000,1.10002000,1.10007000,1.10008000,1.10007000,1.10008000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10009000,1.10008000,1.10009000,1.10008000,1.10007000,1.10008000,
                        1.10007000,1.10006000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,
                        1.10012000,1.10013000,1.10014000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10017000,
                        1.10018000,1.10019000,1.10020000,1.10019000,1.10020000,1.10019000,1.10018000,1.10019000,
                        1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10019000,
                        1.10018000,1.10019000,1.10018000,1.10019000,1.10018000,1.10019000,1.10017000,1.10018000,
                        1.10016000,1.10017000,1.10016000,1.10015000,1.10011000,1.10013000,1.10014000,1.10013000,
                        1.10014000,1.10013000,1.10015000,1.10014000,1.10015000,1.10016000,1.10015000,1.10014000,
                        1.10013000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,
                        1.10011000,1.10012000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,1.10006000,
                        1.10007000,1.10006000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,
                        1.10005000,1.10004000,1.10003000,1.10002000,1.10001000,1.10002000,1.10001000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10005000,1.10006000,1.10014000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10007000,1.10006000,1.10005000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,
                        1.10001000,1.10000000,1.09999000,1.09998000,1.09997000,1.09998000,1.09997000,1.09999000,
                        1.09998000,1.10000000,1.09999000,1.10000000,1.09999000,1.10000000,1.09999000,1.09998000,
                        1.09999000,1.09998000,1.09999000,1.10000000,1.10001000,1.10002000,1.10006000,1.10004000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10001000,1.10000000,1.09998000,1.09999000,
                        1.09998000,1.09999000,1.09997000};

    go(close_data,12,26,9);
    return 0;
}

I believe I have a linker error now:

-------------- Build: Debug in Test (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -fexceptions -std=c++11 -g -I..\..\..\..\..\ta-lib-0.4.0-msvc\ta-lib\c\include -c C:\Users\ypx7647\Documents\C++\Test\main.cpp -o obj\Debug\main.o
mingw32-g++.exe  -o bin\Debug\Test.exe obj\Debug\main.o   
obj\Debug\main.o: In function `Z2goRSt6vectorIdSaIdEEiii':
C:/Users/ypx7647/Documents/C++/Test/main.cpp:30: undefined reference to `TA_MACD'
collect2.exe: error: ld returned 1 exit status
Process terminated with status 1 (0 minute(s), 4 second(s))
1 error(s), 0 warning(s) (0 minute(s), 4 second(s))

What on earth is function "Z2goRSt6vectorIdSaIdEEiii"????

Well progress, the program now compiles and links BUT it produces 0 for the output. Any ideas?

Here's my latest code:

#include <iostream>
#include <vector>
#include "ta_libc.h"

using namespace std;

struct Struct_Macd
{
    double Macd;
    double Signal;
    double Histogram;
} MacdResult;

void go(const vector<TA_Real> &close, TA_Integer fastPeriod, TA_Integer slowPeriod, TA_Integer signalPeriod)
{
    TA_Integer outBegin = 0, outElements = 0;

    int beginIndx = close.size()-slowPeriod-1;
    int endIndx = close.size();
    int array_size = endIndx - beginIndx + 1;
    cout << "beginIndx = " << beginIndx << endl << "endIndx = " << endIndx << endl << "array_size = " << array_size << endl;
    vector<TA_Real> outMacd(array_size, 0.0);
    vector<TA_Real> outSignal(array_size, 0.0);
    vector<TA_Real> outHistogram(array_size, 0.0);

    const TA_Real* close_c_pointer = close.data();
    TA_Real* outMacd_c_pointer = outMacd.data();
    TA_Real* outSignal_c_pointer = outMacd.data();
    TA_Real* outHistogram_c_pointer = outMacd.data();

    TA_RetCode retCode = TA_MACD( beginIndx, endIndx, close_c_pointer, fastPeriod, slowPeriod, signalPeriod, &outBegin, &outElements, outMacd_c_pointer, outSignal_c_pointer, outHistogram_c_pointer );

    cout << "retCode = " << retCode << endl;

    if(retCode == TA_SUCCESS)
    {
        cout << "outBegin = " << outBegin << " outElements = " << outElements << endl;
        int lastElement = outElements-1;
        cout << "outMacd.at(lastElement) = " << outMacd.at(lastElement) << " outSignal.at(lastElement) = " << outSignal.at(lastElement) << " outHistogram.at(lastElement) = " << outHistogram.at(lastElement) << endl;
        MacdResult.Macd = outMacd.at(lastElement);
        MacdResult.Signal = outSignal.at(lastElement);
        MacdResult.Histogram = outHistogram.at(lastElement);

        cout << "Macd = " << MacdResult.Macd << " Signal = " << MacdResult.Signal << " Histogram = " << MacdResult.Histogram << endl;
    }
}

int main(int argc, char**argv)
{
    vector<TA_Real> close_data {1.09999000,1.09995000,1.09996000,1.09995000,1.09994000,1.09993000,1.09994000,1.09996000,
                        1.09997000,1.09999000,1.10000000,1.09999000,1.10000000,1.09998000,1.09999000,1.09998000,
                        1.09999000,1.10000000,1.10001000,1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10005000,1.10006000,1.10007000,1.10008000,
                        1.10012000,1.10011000,1.10012000,1.10011000,1.10013000,1.10014000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10017000,1.10018000,1.10019000,1.10018000,1.10017000,
                        1.10018000,1.10017000,1.10018000,1.10017000,1.10016000,1.10014000,1.10013000,1.10015000,
                        1.10014000,1.10015000,1.10014000,1.10013000,1.10012000,1.10011000,1.10010000,1.10011000,
                        1.10010000,1.10011000,1.10010000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,
                        1.10008000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,1.10004000,
                        1.10003000,1.10002000,1.10007000,1.10008000,1.10007000,1.10008000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10009000,1.10008000,1.10009000,1.10008000,1.10007000,1.10008000,
                        1.10007000,1.10006000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,
                        1.10012000,1.10013000,1.10014000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,
                        1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10015000,1.10016000,1.10017000,
                        1.10018000,1.10019000,1.10020000,1.10019000,1.10020000,1.10019000,1.10018000,1.10019000,
                        1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10018000,1.10017000,1.10019000,
                        1.10018000,1.10019000,1.10018000,1.10019000,1.10018000,1.10019000,1.10017000,1.10018000,
                        1.10016000,1.10017000,1.10016000,1.10015000,1.10011000,1.10013000,1.10014000,1.10013000,
                        1.10014000,1.10013000,1.10015000,1.10014000,1.10015000,1.10016000,1.10015000,1.10014000,
                        1.10013000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,1.10011000,1.10012000,
                        1.10011000,1.10012000,1.10011000,1.10010000,1.10009000,1.10008000,1.10007000,1.10006000,
                        1.10007000,1.10006000,1.10007000,1.10008000,1.10007000,1.10008000,1.10007000,1.10006000,
                        1.10005000,1.10004000,1.10003000,1.10002000,1.10001000,1.10002000,1.10001000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,1.10003000,
                        1.10002000,1.10003000,1.10004000,1.10005000,1.10006000,1.10014000,1.10009000,1.10008000,
                        1.10009000,1.10008000,1.10007000,1.10006000,1.10005000,1.10004000,1.10003000,1.10004000,
                        1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10004000,1.10003000,1.10002000,
                        1.10001000,1.10000000,1.09999000,1.09998000,1.09997000,1.09998000,1.09997000,1.09999000,
                        1.09998000,1.10000000,1.09999000,1.10000000,1.09999000,1.10000000,1.09999000,1.09998000,
                        1.09999000,1.09998000,1.09999000,1.10000000,1.10001000,1.10002000,1.10006000,1.10004000,
                        1.10002000,1.10003000,1.10004000,1.10003000,1.10001000,1.10000000,1.09998000,1.09999000,
                        1.09998000,1.09999000,1.09997000};

    go(close_data,12,26,9);
    return 0;
}

Program output:

beginIndx = 232
endIndx = 259
array_size = 28
retCode = 0
outBegin = 232 outElements = 28
outMacd.at(lastElement) = 0 outSignal.at(lastElement) = 0 outHistogram.at(lastEl
ement) = 0
Macd = 0 Signal = 0 Histogram = 0

Process returned 0 (0x0)   execution time : 0.080 s

@truf found the stupid error with e c pointer references not pointing to individual arrays.

Here's my final code to (too long to enter so here a snippet!) help people who are having problems too:

    MacdResult.Macd = outMacd.at(lastElement);
    MacdResult.Signal = outSignal.at(lastElement);
    MacdResult.Histogram = outHistogram.at(lastElement);

Source: (StackOverflow)

Advertisements

Java TA Lib methods not working

I am trying to use TA lib candle patterns to check some data but what i see is it continuously returns a value of 0, indicating nothing.

I tried using some sample data with 5-6 elements and all methods return the same. All zero's.

If any one could guide or post a working example on how they got the methods working, that would be great.

My eg:

    r = cr.cdlDragonflyDoji(0, 5, o, h, l, c, begin, length, status);
    for (int i=0 ; i < 5; i++){
        System.out.println("3 Whites Value is " + status[i]);
    } 

In the above example, no matter what method i use, i get only zero's in output.


Source: (StackOverflow)

Python ta-lib with pandas.io.data: candlestick not plotting but other charts are ok

iPython 2.3.1, OS-X Yosemite 10.10.2
Python print (sys.version):
2.7.6 (default, Sep 9 2014, 15:04:36)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)]

The following code works for data pulled for US stock data e.g. make the security id "INTC" for Intel. However when I access data for European stocks, the candlestick function fails even though all the OHLC data is there in the dataframe. Have put the full code in here to show that the other tech analysis charts plot just fine for the European stock data.

import pandas.io.data as web
import pandas as pd
import numpy as np
import talib as ta
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from matplotlib.dates import date2num
from matplotlib.finance import candlestick
import datetime

ticker = 'DNO.L'

# Download sample data
sec_id = web.get_data_yahoo(ticker, '2014-06-01')

# Data for matplotlib finance plot
sec_id_ochl = np.array(pd.DataFrame({'0':date2num(sec_id.index),
                                  '1':sec_id.Open,
                                  '2':sec_id.Close,
                                  '3':sec_id.High,
                                  '4':sec_id.Low}))

# Technical Analysis
SMA_FAST = 50
SMA_SLOW = 200
RSI_PERIOD = 14
RSI_AVG_PERIOD = 15
MACD_FAST = 12
MACD_SLOW = 26
MACD_SIGNAL = 9
STOCH_K = 14
STOCH_D = 3
SIGNAL_TOL = 3
Y_AXIS_SIZE = 12

analysis = pd.DataFrame(index = sec_id.index)

analysis['sma_f'] = pd.rolling_mean(sec_id.Close, SMA_FAST)
analysis['sma_s'] = pd.rolling_mean(sec_id.Close, SMA_SLOW)
analysis['rsi'] = ta.RSI(sec_id.Close.as_matrix(), RSI_PERIOD)
analysis['sma_r'] = pd.rolling_mean(analysis.rsi, RSI_AVG_PERIOD) # check shift
analysis['macd'], analysis['macdSignal'], analysis['macdHist'] = \
    ta.MACD(sec_id.Close.as_matrix(), fastperiod=MACD_FAST, slowperiod=MACD_SLOW, signalperiod=MACD_SIGNAL)
analysis['stoch_k'], analysis['stoch_d'] = \
    ta.STOCH(sec_id.High.as_matrix(), sec_id.Low.as_matrix(), sec_id.Close.as_matrix(), slowk_period=STOCH_K, slowd_period=STOCH_D)

analysis['sma'] = np.where(analysis.sma_f > analysis.sma_s, 1, 0)
analysis['macd_test'] = np.where((analysis.macd > analysis.macdSignal), 1, 0)
analysis['stoch_k_test'] = np.where((analysis.stoch_k < 50) & (analysis.stoch_k > analysis.stoch_k.shift(1)), 1, 0)
analysis['rsi_test'] = np.where((analysis.rsi < 50) & (analysis.rsi > analysis.rsi.shift(1)), 1, 0)

# Prepare plot
fig, (ax1, ax2, ax3, ax4) = plt.subplots(4, 1, sharex=True)
ax1.set_ylabel(ticker, size=20)

#size plot
fig.set_size_inches(15,30)

# Plot candles
candlestick(ax1, sec_id_ochl, width=0.5, colorup='g', colordown='r', alpha=1)

# Draw Moving Averages
analysis.sma_f.plot(ax=ax1, c='r')
analysis.sma_s.plot(ax=ax1, c='g')

#RSI
ax2.set_ylabel('RSI', size=Y_AXIS_SIZE)
analysis.rsi.plot(ax = ax2, c='g', label = 'Period: ' + str(RSI_PERIOD))        
analysis.sma_r.plot(ax = ax2, c='r', label = 'MA: ' + str(RSI_AVG_PERIOD))
ax2.axhline(y=30, c='b')
ax2.axhline(y=50, c='black')
ax2.axhline(y=70, c='b')
ax2.set_ylim([0,100])
handles, labels = ax2.get_legend_handles_labels()
ax2.legend(handles, labels)

# Draw MACD computed with Talib
ax3.set_ylabel('MACD: '+ str(MACD_FAST) + ', ' + str(MACD_SLOW) + ', ' + str(MACD_SIGNAL), size=Y_AXIS_SIZE)
analysis.macd.plot(ax=ax3, color='b', label='Macd')
analysis.macdSignal.plot(ax=ax3, color='g', label='Signal')
analysis.macdHist.plot(ax=ax3, color='r', label='Hist')
ax3.axhline(0, lw=2, color='0')
handles, labels = ax3.get_legend_handles_labels()
ax3.legend(handles, labels)

# Stochastic plot
ax4.set_ylabel('Stoch (k,d)', size=Y_AXIS_SIZE)
analysis.stoch_k.plot(ax=ax4, label='stoch_k:'+ str(STOCH_K), color='r')
analysis.stoch_d.plot(ax=ax4, label='stoch_d:'+ str(STOCH_D), color='g')
handles, labels = ax4.get_legend_handles_labels()
ax4.legend(handles, labels)
ax4.axhline(y=20, c='b')
ax4.axhline(y=50, c='black')
ax4.axhline(y=80, c='b')

plt.show()

plot


Source: (StackOverflow)

PHP Trader Function: trader_sma, when it asks for time period, what type of period is it asking? Days, Seconds, etc?

PHP Trader Function: trader_sma, when it asks for time period, what type of period is it asking ? Days, Seconds, etc?

Regarding: array trader_sma ( array $real [, integer $timePeriod ] )

Any insight regarding this function would be very appreciated. The trader functions are highly undocumented. If you know of any documentation, let me know about it please.


Source: (StackOverflow)

Error installing TA-Lib for Anaconda

I am running Python 3.4.1 Anaconda 2.1.0 on Win7 x64. Cython version is 0.21 and I can confirm it has been installed.

I am trying to install the TA-lib wrapper via the command: easy_install TA-lib

I already have the ta-lib folder in c:\ta-lib

This is the full print out of what happens:

easy_install ta-lib Searching for ta-lib Reading htt'ps://pypi.python.org/simple/ta-lib/ Reading htt'p://github.com/mrjbq7/ta-lib Reading https://github.com/mrjbq7/ta-lib/releases Best match: TA-Lib 0.4.8 Downloading https://github.com/mrjbq7/ta-lib/archive/TA_Lib-0.4.8.zip Processing TA_Lib-0.4.8.zip Writing C:\Users\ULYATES\AppData\Local\Temp\easy_install-mxydk494\ta-lib- TA_Lib- 0.4.8\setup.cfg Running ta-lib-TA_Lib-0.4.8\setup.py -q bdist_egg --dist-dir C:\Users\ULYATES\Ap pData\Local\Temp\easy_install-mxydk494\ta-lib-TA_Lib-0.4.8\egg-dist-tmp- dvmbdia1

c:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w6
4-mingw32/bin/ld.exe: skipping incompatible c:\ta-lib\c\lib/ta_libc_cdr.lib     when
 searching for -lta_libc_cdr
c:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-    mingw32/4.7.0/../../../../x86_64-w6
4-mingw32/bin/ld.exe: skipping incompatible c:\ta-lib\c\lib/ta_libc_cdr.lib when

searching for -lta_libc_cdr c:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w6 4-mingw32/bin/ld.exe: skipping incompatible c:\ta-lib\c\lib\ta_libc_cdr.lib when searching for -lta_libc_cdr c:/anaconda3/mingw/bin/../lib/gcc/x86_64-w64-mingw32/4.7.0/../../../../x86_64-w6 4-mingw32/bin/ld.exe: cannot find -lta_libc_cdr collect2.exe: error: ld returned 1 exit status error: Setup script exited with error: command 'C:\Anaconda3\Scripts\gcc.bat' failed with exit status 1

Please help, I am at my whits end.

Thanks,

Sean


Source: (StackOverflow)

nodejs talib MACD

I am using talib technical analysis library to calculate MACD.
I used AAPL data to calculate MACD(8, 17, 9) but the talib values are completely different from Google and Yahoo finance.
Here is my javascript (I copied last AAPL close data since 2015-08-21):

var talib = require('./node_modules/talib/build/Release/talib');
var marketData = { open: [], close: [106.2199999999999989,
 112.6500000000000057,
 115.0100000000000051,
 116.5000000000000000,
 117.1599999999999966,
 116,
 115.1500000000000057,
 115.2399999999999949,
 113.5498999999999938,
 119.6901000000000010,
 115.5199999999999960,
 115.1700000000000017,
 115.4000000000000057,
 114.6400000000000006,
 118.4350000000000023,
 121.4599999999999937,
 122.3700000000000045,
 122.9899999999999949,
 123.3199999999999932,
 122.8900000000000006,
 124.4800000000000040,
 125.1599999999999966,
 125.2199999999999989,
 130.7500000000000000,
 132.0699999999999932],high: [], low: [], volume: [] };
 talib.execute({
    name: "MACD",
    startIdx: 0,
    endIdx: marketData.close.length - 1,
    inReal: marketData.close,
    optInFastPeriod: 8,
    optInSlowPeriod: 17,
    optInSignalPeriod: 9
}, function (result) {
   console.log(result);
});

MACD value of 2005-08-21 from Yahoo and Google finance is -2.73, talib value is 3.83 and with more data MACD are very different. What I am doing wrong?
I also noticed that talib SMA and EMA give the same results.
By the way, inverting in Google charts MACD slow and fast periods, does not change the chart... Yahoo does.


Source: (StackOverflow)

DEMA & TEMA Ta-lib Java Implementation

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.


Source: (StackOverflow)

Meteorjs with ta-lib npm module (server side)

I would like to use npm talib module within a meteorjs application.
I followed the instruction here and I added this to the packages.json file:

{
  "talib" :   "0.6.0"
}

After running meteor the module talib.node is there in the node_modules/talib/build/Release/ folder.
Then I wrote the following:

if (Meteor.isServer) {
  var Talib = Meteor.npmRequire('talib');
  var talib = new Talib();
}

The Talib object is created and can be logged, like this:

{ version: '0.6.0',
  functions: 
  [ { name: 'ADD',
     group: 'Math Operators',
     ...
     }
  ],
  functionUnstIds: 
   { TA_FUNC_UNST_ADX: 0,
     TA_FUNC_UNST_ADXR: 1,
     ...
   }
 }

The line var talib = new Talib() gives instead this error:

 TypeError: object is not a function

What I am doing wrong?


Source: (StackOverflow)

Example usage of TA-LIB trader_sma function?

I just installed TA-Lib / trader into my php installation and it's good to go. My PHP isn't great and even with the trader documentation I just need a bit of guidance. I want to load an array of values from my database and send them into "trader_sma" to get the small moving average. My pseudo code will look something like:

<?php

$finance = $dbrequest("SELECT close_price FROM market_table WHERE stock='$symbol');

//So now $finance is an array with all of the stocks closing prices
//how do I place it into this function? I also need to 'count' the rows in
//the array to send them into $timePeriod?

//array trader_sma ( array $real [, integer $timePeriod ] )


?>

Any help appreciated. Thanks.


Source: (StackOverflow)

Amibroker WMA methods output

I am new to AFL of Amibroker. For Weighted Moving Average(WMA) I'm getting different output with the AFL returns output compared to my calculated WMA.

I use following code to get output of WMA from AFL. I use ten length array and period of 5. As I'm new to it so, I don't have idea to prepare an array from my input data file. For this reason I've hard coded in my code.

 function writeToFile( output, file, length )
{
for( i = 0; i < length; i++ )
    {
      singleElement = output[i];
      fputs(NumToStr(singleElement),file);
      fputs("\t ",file);
    }
    fclose(file);
}

Array[0] = 207.400; 
Array[1] = 207.310; 
Array[2] = 207.210; 
Array[3] = 209.960; 
Array[4] = 210.870; 
Array[5] = 209.350;
Array[6] = 207.250;
Array[7] = 209.960;
Array[8] = 207.650;
Array[9] = 205.160;

foutputWMA = fopen("C:/outputWMA.txt", "w");
input = fopen( "C:/input.txt", "w");

outputWMA = wma(Array, 5);

writeToFile(Array, input, 10);
writeToFile(outputWMA, foutputWMA, 10);

Here is the input array that prints to input.txt file

207.400   207.310     207.210     209.960     210.870     209.350     207.250     209.960     207.650     205.160

And the output of WMA from AFL is below

{EMPTY}   207.310     207.254     208.381     209.317     209.456     208.893     209.237     208.627     207.342    

I have calculated WMA in excel according to https://www.youtube.com/watch?v=-ZsrkI0OsEw

My calculated WMA is

209.189   209.456   208.893   209.237   208.627   207.342

Note that I also get the same output as above in ta-lib.

My question is that, Why the two outputs are differed?

Please help me to get rid of this problem. A big thanks in advance.


Source: (StackOverflow)

TA-LIB missing datapoints when calculating a simple moving average

I am using PHP and recently started using the technical analysis extension TA-LIB to calculate indicators on stock price data. I am getting what I consider a strange result on one of the simplest indicators there is, the simple moving average, and I have not figured out the reason. I have posted a similar question on the TA-LIB forum, but the activity there is very low and I suspect I might not get an answer in a long time, if at all.

The SMA calculates the average based on a given number of previous price datapoints. The problem I am having is best illustrated by an example. Let us say I have a set of 10 price datapoints and I would like to calculate the SMA. For simplicity let us use an average of 4. When calculating this we would expect a new set of 7 averagevalues. However, TA-LIB returns 4 as seen below:

$sma=trader_sma($close,4);
echo"<pre>";
print_r($sma);

Array
(
[0] => Array
    (
        [0] => 
        [1] => 0
        [2] => 
    )

[1] => Array
    (
        [0] => 
        [1] => 1
        [2] => 
    )

[2] => Array
    (
        [0] => 
        [1] => 2
        [2] => 
    )

[3] => Array
    (
        [0] => 
        [1] => 3
        [2] => 573.267
    )

[4] => Array
    (
        [0] => 
        [1] => 4
        [2] => 565.307
    )

[5] => Array
    (
        [0] => 
        [1] => 5
        [2] => 560.552
    )

[6] => Array
    (
        [0] => 
        [1] => 6
        [2] => 557.382
    )

)

As you can see we get nulls at the beginning of the set, as expected. However, we are missing datapoints at the end and the number of missing datapoints always corresponds to the number of datapoints I am averaging over. This causes an unatural gap at the end when I plot the moving average against my price data.

Any ideas on what is going on?


Source: (StackOverflow)