• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
ypdxcn
博客园    首页    新随笔    联系   管理    订阅  订阅

郁金香指标开源库的使用--(tulipindicators-0.8.4)

瞎逛发现最新出了这么一个指标库,有100多种指标的函数库,文档写的比较好,重要的是作者一直在维护。

把它编成库,然后测试一下,可用于自动交易,策略交易等开发。

 

1.下载地址

https://github.com/TulipCharts/tulipindicators

2.编译成DLL,和lib

打开VS2015,文件->新建->项目...

然后,选择“win32 控制台程序”   ,导向最后一步,选择“空项目”,反选“预编译头文件”

3.导入文件

右键工程属性  ->  "在文件资源管理器中打开文件夹"   -》把“indicators.h” 文件,以及“utils”,“indicators”2个目录拷贝到工程下     -》“显示所有文件”

4.修改所有文件为在项目中包含

选中文件右键-》在项目中包含

右键-》工程属性->改为DLL类型

5.生成导出DLL

要生成DLL和lib导出库,需要有导出标记“__declspec(dllexport)”,在函数声明和实现文件的头部都需要加上这个字串。

在函数中发现一个共性,函数名称都已“ti_”开头  ,返回类型为“int”,于是打开工程替换(CTRL + H),选中“整个解决方案” ,“__declspec(dllexport) int ti   ”   替换掉 “   int ti_” ,选择全部替换,最后爆出工替换“369”处。

6.编译

 indoicatorLib.vcxproj -> E:\work\tulipindicators-master\indoicatorLib\x64\Release\indoicatorLib.dll

提示成功。

 7.加入测试代码

就在本工程程添加项目:右键工程  -》 新建项目    。。 。 添加一个工程“”TestIndicator"(一个控制台空项目,应用程序工程).

添加测试cpp,文件main.cpp:

文件main.cpp:

 1 #include "test_sma.hpp"
 2 #include "test_crossover.hpp"
 3 #include "test_boll.hpp"
 4 
 5 int main()
 6 {
 7     test_crossover();
 8     test_sma();
 9     test_boll();
10 
11     return 0;
12 }

 列出一个上穿指标测试代码:

 1 void test_crossover()
 2 {
 3     TI_REAL input1[] = { 4, 4, 6, 6, 6, 4, 4, 6, 5, 5, 5 };
 4     TI_REAL input2[] = { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
 5     /* Example usage of Crossover */
 6     /* Assuming that 'input1' and 'input2' are pre-loaded arrays of size 'in_size'. */
 7     TI_REAL *inputs[] = { input1, input2 };
 8     TI_REAL options[1]; /* No options */
 9     TI_REAL *outputs[1]; /* crossover */
10 
11     int in_size = 11;
12     /* Determine how large the output size is for our options. */
13     const int out_size = in_size - ti_crossover_start(options);
14 
15     /* Allocate memory for output. */
16     outputs[0] = reinterpret_cast<double *>(  malloc(sizeof(TI_REAL) * out_size) ); 
17     assert(outputs[0] != 0); /* crossover */
18 
19      /* Run the actual calculation. */
20     const int ret = ti_crossover(in_size, inputs, options, outputs);
21     assert(ret == TI_OKAY);
22 
23     printf("The output data is: ");
24     print_array(outputs[0], out_size);
25 
26 }


输入序列:
index:0~N

序列1:{4, 4, 6, 6, 6, 4, 4, 6, 5, 5, 5}
序列2:{5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5}

输出序列:

index:1  ~  N 

{0, 1, 0, 0, 0, 0, 1, 0, 0, 0}

 

序列1和序列2,数据长度相同,crossover输出从index1开始,检测由下往上的上穿,1表示true;

 

 

具体代码代码见:(下载)

 

posted @ 2018-09-21 10:51  ypdxcn  阅读(991)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3