ta-lib 里的蜡烛图形态函数源码

以CDL2CROWS为例, 看一看c语言的源码:

有关的源码文件包括

  • d:\Documents\Pictures\ta-lib\c\src\ta_func\ta_CDL2CROWS.c
  • d:\Documents\Pictures\ta-lib\c\src\ta_func\ta_utility.h
  • d:\Documents\Pictures\ta-lib\c\src\ta_common\ta_global.c
  • d:\Documents\Pictures\ta-lib\c\src\ta_common\ta_global.h
   i = startIdx;

   /* Proceed with the calculation for the requested range.
* Must have:
* - first candle: long white candle
* - second candle: black real body
* - gap between the first and the second candle's real bodies
* - third candle: black candle that opens within the second real body and closes within the first real body
* The meaning of "long" is specified with TA_SetCandleSettings
* outInteger is negative (-1 to -100): two crows is always bearish;
* the user should consider that two crows is significant when it appears in an uptrend, while this function
* does not consider the trend
*/
outIdx = 0;
do
{
if( TA_CANDLECOLOR(i-2) == 1 && // 1st: white
TA_REALBODY(i-2) > TA_CANDLEAVERAGE( BodyLong, BodyLongPeriodTotal, i-2 ) && // long
TA_CANDLECOLOR(i-1) == -1 && // 2nd: black
TA_REALBODYGAPUP(i-1,i-2) && // gapping up
TA_CANDLECOLOR(i) == -1 && // 3rd: black
inOpen[i] < inOpen[i-1] && inOpen[i] > inClose[i-1] && // opening within 2nd rb
inClose[i] > inOpen[i-2] && inClose[i] < inClose[i-2] // closing within 1st rb
)
outInteger[outIdx++] = -100;
else
outInteger[outIdx++] = 0;
/* add the current range and subtract the first range: this is done after the pattern recognition
* when avgPeriod is not 0, that means "compare with the previous candles" (it excludes the current candle)
*/
BodyLongPeriodTotal += TA_CANDLERANGE( BodyLong, i-2 ) - TA_CANDLERANGE( BodyLong, BodyLongTrailingIdx );
i++;
BodyLongTrailingIdx++;
} while( i <= endIdx ); TA_RetCode TA_RestoreCandleDefaultSettings( TA_CandleSettingType settingType )
{
const TA_CandleSetting TA_CandleDefaultSettings[] = {
/* real body is long when it's longer than the average of the 10 previous candles' real body */
{ TA_BodyLong, TA_RangeType_RealBody, 10, 1.0 },
/* real body is very long when it's longer than 3 times the average of the 10 previous candles' real body */
{ TA_BodyVeryLong, TA_RangeType_RealBody, 10, 3.0 },
/* real body is short when it's shorter than the average of the 10 previous candles' real bodies */
{ TA_BodyShort, TA_RangeType_RealBody, 10, 1.0 },
/* real body is like doji's body when it's shorter than 10% the average of the 10 previous candles' high-low range */
{ TA_BodyDoji, TA_RangeType_HighLow, 10, 0.1 },
/* shadow is long when it's longer than the real body */
{ TA_ShadowLong, TA_RangeType_RealBody, 0, 1.0 },
/* shadow is very long when it's longer than 2 times the real body */
{ TA_ShadowVeryLong, TA_RangeType_RealBody, 0, 2.0 },
/* shadow is short when it's shorter than half the average of the 10 previous candles' sum of shadows */
{ TA_ShadowShort, TA_RangeType_Shadows, 10, 1.0 },
/* shadow is very short when it's shorter than 10% the average of the 10 previous candles' high-low range */
{ TA_ShadowVeryShort, TA_RangeType_HighLow, 10, 0.1 },
/* when measuring distance between parts of candles or width of gaps */
/* "near" means "<= 20% of the average of the 5 previous candles' high-low range" */
{ TA_Near, TA_RangeType_HighLow, 5, 0.2 },
/* when measuring distance between parts of candles or width of gaps */
/* "far" means ">= 60% of the average of the 5 previous candles' high-low range" */
{ TA_Far, TA_RangeType_HighLow, 5, 0.6 },
/* when measuring distance between parts of candles or width of gaps */
/* "equal" means "<= 5% of the average of the 5 previous candles' high-low range" */
{ TA_Equal, TA_RangeType_HighLow, 5, 0.05 }
}; /* Candlestick macros (used by candlestick functions, where the parameters are always called inClose, inOpen, etc.
* Don't use i++ or func(i) with these macros !
*/ #define TA_REALBODY(IDX) ( std_fabs( inClose[IDX] - inOpen[IDX] ) )
#define TA_UPPERSHADOW(IDX) ( inHigh[IDX] - ( inClose[IDX] >= inOpen[IDX] ? inClose[IDX] : inOpen[IDX] ) )
#define TA_LOWERSHADOW(IDX) ( ( inClose[IDX] >= inOpen[IDX] ? inOpen[IDX] : inClose[IDX] ) - inLow[IDX] )
#define TA_HIGHLOWRANGE(IDX) ( inHigh[IDX] - inLow[IDX] )
#define TA_CANDLECOLOR(IDX) ( inClose[IDX] >= inOpen[IDX] ? 1 : -1 ) #if defined( _MANAGED )
#define TA_CANDLERANGETYPE(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->rangeType)
#define TA_CANDLEAVGPERIOD(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->avgPeriod)
#define TA_CANDLEFACTOR(SET) (Globals->candleSettings[(int)CandleSettingType::SET]->factor)
#elif defined( _JAVA )
#define TA_CANDLERANGETYPE(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].rangeType)
#define TA_CANDLEAVGPERIOD(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].avgPeriod)
#define TA_CANDLEFACTOR(SET) (this.candleSettings[CandleSettingType.SET.ordinal()].factor)
#else
#define TA_CANDLERANGETYPE(SET) (TA_Globals->candleSettings[TA_##SET].rangeType)
#define TA_CANDLEAVGPERIOD(SET) (TA_Globals->candleSettings[TA_##SET].avgPeriod)
#define TA_CANDLEFACTOR(SET) (TA_Globals->candleSettings[TA_##SET].factor)
#endif #define TA_CANDLERANGE(SET,IDX) \
( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_RealBody,RealBody) ? TA_REALBODY(IDX) : \
( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_HighLow,HighLow) ? TA_HIGHLOWRANGE(IDX) : \
( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_Shadows,Shadows) ? TA_UPPERSHADOW(IDX) + TA_LOWERSHADOW(IDX) : \
0 ) ) )
#define TA_CANDLEAVERAGE(SET,SUM,IDX) \
( TA_CANDLEFACTOR(SET) \
* ( TA_CANDLEAVGPERIOD(SET) != 0.0? SUM / TA_CANDLEAVGPERIOD(SET) : TA_CANDLERANGE(SET,IDX) ) \
/ ( TA_CANDLERANGETYPE(SET) == ENUM_VALUE(RangeType,TA_RangeType_Shadows,Shadows) ? 2.0 : 1.0 ) \
)
#define TA_REALBODYGAPUP(IDX2,IDX1) ( min(inOpen[IDX2],inClose[IDX2]) > max(inOpen[IDX1],inClose[IDX1]) )
#define TA_REALBODYGAPDOWN(IDX2,IDX1) ( max(inOpen[IDX2],inClose[IDX2]) < min(inOpen[IDX1],inClose[IDX1]) )
#define TA_CANDLEGAPUP(IDX2,IDX1) ( inLow[IDX2] > inHigh[IDX1] )
#define TA_CANDLEGAPDOWN(IDX2,IDX1) ( inHigh[IDX2] < inLow[IDX1] )

ta-lib 里的蜡烛图形态函数源码的更多相关文章

  1. E-Form++图形可视化源码库新增同BCGSoft的Ribbon结合示例

    2015年11月20日,来自UCanCode E-Form++源码库的开发团队消息,E-Form++正式提供了同BCGSoft的Ribbon界面风格相结合的示例,如下图: 下载此示例请访问: http ...

  2. leaflet 实现克里金插值功能(附源码下载)

    前言 leaflet 入门开发系列环境知识点了解: leaflet api文档介绍,详细介绍 leaflet 每个类的函数以及属性等等 leaflet 在线例子 leaflet 插件,leaflet ...

  3. Android的/system/lib里加入自己的so库

    执行下命令: 1 重新挂载/system目录,使之能读写:mount -o remount,rw /dev/null /system 2 修改这个文件的权限:chmod 777 /system 3 利 ...

  4. Eclipse导入Tomcat源码(转)

    想要研究下Tomcat的体系结构或者源码,最好将Tomcat的源码导入到ide中,编写实例进行代码跟踪(debug). 这里参考了网上一些资料,将自己操作过程记个流水账. 准备: 1.Tomcat源码 ...

  5. 2014年5月份第3周51Aspx源码发布详情

    HGM简单连连看游戏源码  2014-5-19 [VS2010]源码描述:这是一款基于WinForm窗体程序的简单水果连连看的小游戏.界面比较美观, 功能如下:该游戏可以显示当前关卡,还有剩余时间.重 ...

  6. Tomcat源码导入Eclipse测试

    想要研究下Tomcat的体系结构或者源码,最好将Tomcat的源码导入到ide中,编写实例进行代码跟踪(debug). 这里参考了网上一些资料,将自己操作过程记个流水账. 准备: 1.Tomcat源码 ...

  7. 16Aspx.com源码2014年7月详细

            Web电子商务网(三层)V2.0源码 2014-07-31   [VS2010] 源码介绍: Web电子商务网(三层)V2.0源码 源码描述: 一.源码特点     采用三层架构开发, ...

  8. Ubuntu编译Android源码过程中的空间不足解决方法

    Android源码一般几十G,就拿Android5.0来说,下载下来大概也有44G左右,和编译产生的文件以及Ubuntu系统占用的空间加起来,源码双倍的空间都不够有.编译源码前能分配足够的空间再好不过 ...

  9. eclipse编译Jmeter源码

    1.在apache官网下载源码和安装包   http://jmeter.apache.org/ 2.  解压     解压安装包和源码包,     将安装包apache-jmeter-3.3 里lib ...

随机推荐

  1. spring整合http

    本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接出处:https://blog.csdn.net/qq_3076499,否则保留追究法律责任的权利. 如果 ...

  2. 2018-11-19-windows-应用程序在关机时的退出代号

    title author date CreateTime categories windows 应用程序在关机时的退出代号 lindexi 2018-11-19 14:31:38 +0800 2018 ...

  3. Leetcode447.Number of Boomerangs回旋镖的数量

    给定平面上 n 对不同的点,"回旋镖" 是由点表示的元组 (i, j, k) ,其中 i 和 j 之间的距离和 i 和 k 之间的距离相等(需要考虑元组的顺序). 找到所有回旋镖的 ...

  4. JS random函数深入理解(转载)

    转载自:(本文对读者有帮助的话请移步支持原作者) http://www.cnblogs.com/starof/p/4988516.html 一.预备知识 Math.ceil();  //向上取整. M ...

  5. mysql 索引优化 性能调优 锁

    1 检查mysql 是否安装 rpm -qa|grep -i mysql 2 ntsysv 查看和设置开机启动列表 3 mysql 在 centos 上默认 的数据目录是 /var/lib/mysql ...

  6. 开户项目的sql查询语句备查

    查询全国所有的券商名录 SELECT id,security,province,city,borough FROM t_security GROUP BY security ; 查询某个省份的所有券商 ...

  7. java笔记之split

    Java split()用法 特殊情况有 * ^ : | . \ 一.单个符号作为分隔符  String address="上海\上海市|闵行区\吴中路"; String[] sp ...

  8. CentOS 7 yum 安装与配置MySQL5.7

    1.下载mysql源安装包 wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm 2.安装mysql源 yu ...

  9. 100个常用的原生JavaScript函数

    1.原生JavaScript实现字符串长度截取 复制代码代码如下: function cutstr(str, len) {    var temp;    var icount = 0;    var ...

  10. Ionic.Zip

    1.Ionic.zIP 实现文件压缩和解压 2.压缩: /// <summary>        /// 压缩文件        /// </summary>        / ...