用VC开发股票分析软件(二)

本文介绍TA-LIB库的基本使用方法,包括在C/C++环境下如何定义参数、调用技术分析函数如MACD,并展示了如何链接必要的库文件。此外,还提供了不同编程语言下的函数调用示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


  1. TA_Real    closePrice[400];
  2. TA_Real    out[400];
  3. TA_Integer outBeg;
  4. TA_Integer outNbElement;
  5. 这是定义参数的地方
  6. int main(int argc, char* argv[])
  7. {
  8.     /* The output is displayed here */
  9.    for(int j=0;j<401;)
  10.    {
  11.        closePrice[j++]=1; //closePrice指的是收盘价MACD,MA等技术图形都是根据收盘价格形成的图形
  12.       
  13.    }    
  14.    TA_RetCode retCode = TA_MA(0,399,&closePrice[0],30,TA_MAType_SMA,&outBeg,&outNbElement,&out[0]);
  15.    //这里传参数 
  16.    for(int i=0; i < outNbElement; i++ )
  17.    printf( "Day %d = %f/n", outBeg+i, out[i] );

  18.     return 0;
  19. }
  TA-LIB 有支持  C/C++;Excel;JAVA; Python.Net的函数库
  在C库中有重要的ta_defs.h,ta_common.h,ta_func.h三个重要的头文件
  ta_libc.h是所有头文件的定义开始
  ta_defs.h用来定义Ta lib 的数据类型包括一些常用的类型。ta_func.h是技术分析公式的头文件,如果你要找到MACD公式的
  定义可以这样查找 TA_MACD 如果找CCI,可以TA_CCI
  在VC中的LINK面板中要加入这N多个库文件的Link
   比如:ta_abstract_ ta_common_,ta_func_cdd.,ta_libc_cdd前缀开始的LIB库
   每个有_cdd,_cdr,_cmd,_cmr,_csd,csr_ 所以有N多个。
  主要需要如下库:
  ta_libc_csr.lib ta_libc_csd.lib ta_libc_cmr.lib ta_libc_cmd.lib ta_libc_cdr.lib ta_libc_cdd.lib 
  (更正)
  为了满足其他开发语言的需求,每个公式上面定义了很多编译控制。要使用要注意一下。
  
  1. /* Generated */ #if defined( _MANAGED ) && defined( USE_SUBARRAY )
  2. /* Generated */ enum class Core::RetCode Core::Macd( int    startIdx,
  3. /* Generated */                                      int    endIdx,
  4. /* Generated */                                      SubArray^    inReal,
  5. /* Generated */                                      int           optInFastPeriod, /* From 2 to 100000 */
  6. /* Generated */                                      int           optInSlowPeriod, /* From 2 to 100000 */
  7. /* Generated */                                      int           optInSignalPeriod, /* From 1 to 100000 */
  8. /* Generated */                                      [Out]int%    outBegIdx,
  9. /* Generated */                                      [Out]int%    outNBElement,
  10. /* Generated */                                      cli::array<double>^  outMACD,
  11. /* Generated */                                      cli::array<double>^  outMACDSignal,
  12. /* Generated */                                      cli::array<double>^  outMACDHist )
  13. /* Generated */ #elif defined( _MANAGED )
  14. /* Generated */ enum class Core::RetCode Core::Macd( int    startIdx,
  15. /* Generated */                                      int    endIdx,
  16. /* Generated */                                      cli::array<double>^ inReal,
  17. /* Generated */                                      int           optInFastPeriod, /* From 2 to 100000 */
  18. /* Generated */                                      int           optInSlowPeriod, /* From 2 to 100000 */
  19. /* Generated */                                      int           optInSignalPeriod, /* From 1 to 100000 */
  20. /* Generated */                                      [Out]int%    outBegIdx,
  21. /* Generated */                                      [Out]int%    outNBElement,
  22. /* Generated */                                      cli::array<double>^  outMACD,
  23. /* Generated */                                      cli::array<double>^  outMACDSignal,
  24. /* Generated */                                      cli::array<double>^  outMACDHist )
  25. /* Generated */ #elif defined( _JAVA )
  26. /* Generated */ public RetCode macd( int    startIdx,
  27. /* Generated */                      int    endIdx,
  28. /* Generated */                      double       inReal[],
  29. /* Generated */                      int           optInFastPeriod, /* From 2 to 100000 */
  30. /* Generated */                      int           optInSlowPeriod, /* From 2 to 100000 */
  31. /* Generated */                      int           optInSignalPeriod, /* From 1 to 100000 */
  32. /* Generated */                      MInteger     outBegIdx,
  33. /* Generated */                      MInteger     outNBElement,
  34. /* Generated */                      double        outMACD[],
  35. /* Generated */                      double        outMACDSignal[],
  36. /* Generated */                      double        outMACDHist[] )
  37. /* Generated */ #else
  38. /* Generated */ TA_RetCode TA_MACD( int    startIdx,
  39. /* Generated */                     int    endIdx,
  40. /* Generated */                     const double inReal[],
  41. /* Generated */                     int           optInFastPeriod, /* From 2 to 100000 */
  42. /* Generated */                     int           optInSlowPeriod, /* From 2 to 100000 */
  43. /* Generated */                     int           optInSignalPeriod, /* From 1 to 100000 */
  44. /* Generated */                     int          *outBegIdx,
  45. /* Generated */                     int          *outNBElement,
  46. /* Generated */                     double        outMACD[],
  47. /* Generated */                     double        outMACDSignal[],
  48. /* Generated */                     double        outMACDHist[] )
    目前技术公式的版本还不高,我测试了几个简单的,基本是对的。国外好象有分析软件在应用这个库
 关注升级版本。至于如果只是单纯应用。将LIB导入就行。如果VC是精通的。应该一下子可以分析出包结构。
 Python也是最近才支持的。我真的怀疑Ruby的未来。我下的版本当时还没有支持。
 在EXCEL中使用只要在单元格中输入简单的公式就行{=TA_EMA( A1:A200, 13 )}//我没有测试过


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值