这是我的第一个 c++ 程序,我对 c 也不是很熟悉,所以请对我温柔一点!
我试图从 ta_lib 库中调用 TA_MACD 函数但没有成功。有人可以帮帮我吗?
我的代码是这样的:
#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;
}
}
当我使用 MinGW 编译时,出现以下错误:
"/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)
我将是第一个承认我不知道自己在做什么的人,因此将不胜感激。
另外,当我不知道 TA_MACD 函数返回多少时,如何设置 out 变量的大小?
提前致谢。
使用 C++11 Std 修改后,我现在在这里,仍然有问题。
#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;
}
这是输出:
||=== 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)) ===|
进行了修改和调整后,建议我的代码现在是:
#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;
}
我相信我现在有一个链接器错误:
-------------- 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))
到底什么是函数“Z2goRSt6vectorIdSaIdEEiii”????
进展顺利,程序现在编译并链接,但它为输出生成 0。有任何想法吗?
这是我的最新代码:
#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;
}
程序输出:
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 发现 ec 指针引用不指向单个数组的愚蠢错误。
这是我的最终代码(输入太长,所以这里是一个片段!)帮助有问题的人:
MacdResult.Macd = outMacd.at(lastElement);
MacdResult.Signal = outSignal.at(lastElement);
MacdResult.Histogram = outHistogram.at(lastElement);