Skip to content

Commit 496e9ec

Browse files
committed
Init version based on chanlun 2.1
1 parent 975fdc0 commit 496e9ec

25 files changed

+3770
-0
lines changed

ChanlunCore.cpp

+1,611
Large diffs are not rendered by default.

ChanlunCore.h

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/************************************************************************/
2+
/*
3+
缠论核心模块实现
4+
单例模式
5+
所有Chanlun接口中缠论核心函数在此实现
6+
*/
7+
/************************************************************************/
8+
#ifndef __CHANLUNCORE_H_INCLUDE
9+
#define __CHANLUNCORE_H_INCLUDE
10+
11+
#include "FxjFunc.h"
12+
#include <list>
13+
14+
using namespace std;
15+
16+
//定义基本数据
17+
// 缠论K线结构 处理过包含关系的K线
18+
typedef struct chankx
19+
{
20+
int no; // K线序号 从1开始是
21+
float rhigh; // 高值
22+
float rlow; // 低值
23+
float high; //包含处理后的高值
24+
float low; //包含处理后的低值
25+
int flag; //1顶 -1底 0 非顶底
26+
float fxqj; // 分型区间 如果为顶底 记录区间边界
27+
int dir; //K线方向 1上 -1下 2 上包含 -2 下包含
28+
int bi; //笔 1上 -1下 2 上包含 -2 下包含
29+
int duan; //段 1上 -1下 2 上包含 -2 下包含
30+
} ckx;
31+
32+
// 笔 (特征序列)
33+
typedef struct chanbi
34+
{
35+
int no; // 序号
36+
int noh; // 高点K线编号
37+
int nol; // 低点K线编号
38+
float high; // 高点
39+
float low; // 低点
40+
int dir; // 方向 方向 1上 -1下 2 上包含 -2 下包含
41+
int flag; // 1顶 -1底
42+
int qk; // 特征1 2 之间是否存在缺口
43+
} cbi;
44+
45+
//
46+
typedef struct chanduan
47+
{
48+
int no; // 序号
49+
int noh; // 高点K线编号
50+
int nol; // 低点K线编号
51+
float high; // 高点
52+
float low; // 低点
53+
int flag; // 1顶 -1底
54+
int binum; // 包含几笔
55+
} cduan;
56+
57+
// 走势中枢
58+
typedef struct chanzhongshu
59+
{
60+
int no; // 序号
61+
int duanno; // 段序号
62+
int flag; // 走势方向 1上 -1下
63+
int ksno; // zg所在K线NO (有zg必有zd)
64+
int jsno; // zd所在K线NO
65+
int znnum; // 包含zn数
66+
float zg; // ZG=min(g1、g2)
67+
float zd; // ZD=max(d1、d2)
68+
float gg; // GG=max(gn);
69+
float dd; // dd=min(dn);
70+
float zz; // 震荡中轴(监视器)
71+
} czhongshu;
72+
//定义基本数据 END
73+
74+
typedef list<ckx> KXDATA;
75+
typedef list<cbi> BIDATA;
76+
typedef list<cduan> DUANDATA;
77+
typedef list<czhongshu> ZSDATA;
78+
79+
typedef list<ckx>::iterator CKXIT;
80+
typedef list<cbi>::iterator BIIT;
81+
typedef list<cduan>::iterator DUANIT;
82+
typedef list<czhongshu>::iterator ZSIT;
83+
84+
typedef list<ckx>::const_iterator C_CKXIT;
85+
typedef list<cbi>::const_iterator C_BIIT;
86+
typedef list<cduan>::const_iterator C_DUANIT;
87+
typedef list<czhongshu>::const_iterator C_ZSIT;
88+
89+
// 缠论核心实现
90+
class ChanlunCore
91+
{
92+
private:
93+
ChanlunCore(); // 构造函数
94+
~ChanlunCore(); // 析构函数
95+
96+
static ChanlunCore* instance;
97+
98+
99+
KXDATA kxData; // 根据缠论处理过的K线
100+
BIDATA xbData; // 向下笔 (向上笔开始的段的特征序列)
101+
BIDATA sbData; // 向上笔 (向下笔开始的段的特征序列)
102+
DUANDATA dData; //
103+
ZSDATA zsData; // 中枢
104+
105+
float biQuekou;
106+
int firstDuanDir;
107+
108+
void initBiQK(CALCINFO* pData); // 初始化缺口
109+
void initTZXL(); // 初始化特征分型
110+
void initDuanList(); //初始化段
111+
112+
BIIT findTZG(int fromNo); // 查找特征序列的顶分型
113+
BIIT findTZD(int fromNo); // 查找特征序列的底分型
114+
115+
void findFanTanZS(int duanno, int begin, int end, int high, int low); // 查找下跌段中枢
116+
void findHuiTiaoZS(int duanno, int begin, int end, int high, int low); // 查找上升段中枢
117+
118+
public:
119+
static ChanlunCore* GetInstance(); //获取 唯一实例
120+
121+
void initKx(CALCINFO* pData); // 初始化缠论K线
122+
void initFX(); // 初始化分型
123+
void initBi(); // 初始化笔
124+
void initDuan(); // 初始化段
125+
void initZhongshu(); // 初始化中枢
126+
127+
CKXIT getCKX(int num);
128+
129+
// Getter
130+
KXDATA getCkxData();
131+
BIDATA getXbData();
132+
BIDATA getSbData();
133+
DUANDATA getDuanData();
134+
ZSDATA getZsData();
135+
136+
// 自定义常量
137+
// 方向 1向上 -1向下
138+
static const int DIR_0;
139+
static const int DIR_UP;
140+
static const int DIR_DN;
141+
static const int DIR_SBH;
142+
static const int DIR_XBH;
143+
144+
static const int QK_N; // 不存在缺口
145+
static const int QK_Y; // 存在缺口
146+
};
147+
148+
#endif // __CHANLUNTOOLS_H_INCLUDE

ChanlunTools.cpp

+175
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
#include "stdafx.h"
2+
#include "ChanlunTools.h"
3+
4+
//初始化静态成员
5+
ChanlunTools* ChanlunTools::instance = NULL;
6+
7+
const int ChanlunTools::cjunx[8] = {5, 13, 21, 34, 55, 89, 144, 233};
8+
9+
// 构造函数
10+
ChanlunTools::ChanlunTools()
11+
{
12+
//nothing
13+
}
14+
15+
ChanlunTools::~ChanlunTools()
16+
{
17+
if(NULL != instance)
18+
{
19+
delete instance;
20+
instance = NULL;
21+
}
22+
}
23+
24+
// 静态实例
25+
ChanlunTools* ChanlunTools::GetInstance()
26+
{
27+
if(NULL == instance)
28+
{
29+
instance = new ChanlunTools();
30+
}
31+
return instance;
32+
}
33+
34+
float ChanlunTools::ma_close(CALCINFO* pData, int num, int zq)
35+
{
36+
float ret = 0;
37+
for(int j=0;j<zq;j++) //累加
38+
ret += pData->m_pData[num-j].m_fClose;
39+
40+
return ret/zq;
41+
}
42+
43+
int ChanlunTools::jxzt(CALCINFO* pData, int num)
44+
{
45+
int ss = 1;
46+
float ma5 = ma_close(pData, num, 5);
47+
float ma13 = ma_close(pData, num, 13);
48+
float ma21 = ma_close(pData, num, 21);
49+
float ma34 = ma_close(pData, num, 34);
50+
float ma55 = ma_close(pData, num, 55);
51+
float ma89 = ma_close(pData, num, 89);
52+
float ma144 = ma_close(pData, num, 144);
53+
float ma233 = ma_close(pData, num, 233);
54+
55+
float c = pData->m_pData[num].m_fClose;
56+
57+
if(c>ma5) ss++;
58+
if(c>ma13) ss++;
59+
if(c>ma21) ss++;
60+
if(c>ma34) ss++;
61+
if(c>ma55) ss++;
62+
if(c>ma89) ss++;
63+
if(c>ma144) ss++;
64+
if(c>ma233) ss++;
65+
66+
return ss;
67+
}
68+
69+
int ChanlunTools::jxyl(CALCINFO* pData, int num)
70+
{
71+
float ma5 = ma_close(pData, num, 5);
72+
float ma13 = ma_close(pData, num, 13);
73+
float ma21 = ma_close(pData, num, 21);
74+
float ma34 = ma_close(pData, num, 34);
75+
float ma55 = ma_close(pData, num, 55);
76+
float ma89 = ma_close(pData, num, 89);
77+
float ma144 = ma_close(pData, num, 144);
78+
float ma233 = ma_close(pData, num, 233);
79+
80+
float c = pData->m_pData[num].m_fClose;
81+
82+
float cz1 = c - ma5;
83+
float cz2 = c - ma13;
84+
float cz3 = c - ma21;
85+
float cz4 = c - ma34;
86+
float cz5 = c - ma55;
87+
float cz6 = c - ma89;
88+
float cz7 = c - ma144;
89+
float cz8 = c - ma233;
90+
float czs[] = {cz1, cz2, cz3, cz4, cz5, cz6, cz7, cz8};
91+
92+
int flag = 1;
93+
float ylw = czs[0];
94+
if (ylw>0) {
95+
ylw = -99999;
96+
flag = 9;
97+
}
98+
for(int i=1; i<8; i++)
99+
{
100+
if(czs[i]<0 && czs[i] > ylw) {
101+
ylw = czs[i];
102+
flag = i+1;
103+
}
104+
}
105+
106+
return flag;
107+
}
108+
109+
int ChanlunTools::jxzc(CALCINFO* pData, int num)
110+
{
111+
float ma5 = ma_close(pData, num, 5);
112+
float ma13 = ma_close(pData, num, 13);
113+
float ma21 = ma_close(pData, num, 21);
114+
float ma34 = ma_close(pData, num, 34);
115+
float ma55 = ma_close(pData, num, 55);
116+
float ma89 = ma_close(pData, num, 89);
117+
float ma144 = ma_close(pData, num, 144);
118+
float ma233 = ma_close(pData, num, 233);
119+
120+
float c = pData->m_pData[num].m_fClose;
121+
122+
float cz1 = c - ma5;
123+
float cz2 = c - ma13;
124+
float cz3 = c - ma21;
125+
float cz4 = c - ma34;
126+
float cz5 = c - ma55;
127+
float cz6 = c - ma89;
128+
float cz7 = c - ma144;
129+
float cz8 = c - ma233;
130+
float czs[] = {cz1, cz2, cz3, cz4, cz5, cz6, cz7, cz8};
131+
132+
int flag = 1;
133+
float zcw = czs[0];
134+
if (zcw<0)
135+
{
136+
zcw = 99999;
137+
flag = 0;
138+
}
139+
140+
for(int i=1; i<8; i++)
141+
{
142+
if(czs[i]>0 && czs[i] < zcw)
143+
{
144+
zcw = czs[i];
145+
flag = i+1;
146+
}
147+
}
148+
149+
return flag;
150+
}
151+
152+
int ChanlunTools::jxyl2(CALCINFO* pData, int num)
153+
{
154+
int ret = 0;
155+
int i = jxyl(pData, num);
156+
if(9 != i)
157+
{
158+
ret = cjunx[i-1];
159+
}
160+
161+
return ret;
162+
}
163+
164+
int ChanlunTools::jxzc2(CALCINFO* pData, int num)
165+
{
166+
int ret = 0;
167+
int i = jxzc(pData, num);
168+
if(0 != i)
169+
{
170+
ret = cjunx[i-1];
171+
}
172+
173+
return ret;
174+
}
175+

ChanlunTools.h

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/************************************************************************/
2+
/*
3+
缠论可单独调用的函数在此实现
4+
单例模式
5+
所有Chanlun接口中可单独调用的函数在此实现
6+
*/
7+
/************************************************************************/
8+
#ifndef __CHANLUNTOOLS_H_INCLUDE
9+
#define __CHANLUNTOOLS_H_INCLUDE
10+
/*
11+
#ifdef __cplusplus
12+
extern "C"
13+
{
14+
#endif //__cplusplus
15+
*/
16+
#include "FxjFunc.h"
17+
18+
class ChanlunTools
19+
{
20+
private:
21+
ChanlunTools(); // 构造函数
22+
virtual ~ChanlunTools(); // 析构函数
23+
static ChanlunTools* instance; // 单例实例
24+
25+
static const int cjunx[8]; // 缠论均线1-8类
26+
27+
public:
28+
static ChanlunTools* GetInstance(); // 获取单例实例
29+
30+
/*
31+
* 收盘价均线
32+
*/
33+
float ma_close(CALCINFO* pData, int num, int zq);
34+
35+
/*
36+
* 均线评分 1-9类 1为全在均线之下 9为全在均线之上
37+
*/
38+
int jxzt(CALCINFO* pData, int num);
39+
40+
/*
41+
* 均线压力 9为无压制均线 多头排列 返回1-8类均线
42+
*/
43+
int jxyl(CALCINFO* pData, int num);
44+
45+
/*
46+
* 均线支撑 0为无任何支撑 空头排列 返回1-8类均线
47+
*/
48+
int jxzc(CALCINFO* pData, int num);
49+
50+
/*
51+
* 均线压力 0为无压制均线 多头排列 返回5 13 21 34 55 89 144 233
52+
*/
53+
int jxyl2(CALCINFO* pData, int num);
54+
55+
/*
56+
* 均线支撑 0为无任何支撑 空头排列 返回5 13 21 34 55 89 144 233
57+
*/
58+
int jxzc2(CALCINFO* pData, int num);
59+
60+
};
61+
62+
/*
63+
#ifdef __cplusplus
64+
}
65+
#endif //__cplusplus
66+
*/
67+
#endif // __CHANLUNTOOLS_H_INCLUDE

0 commit comments

Comments
 (0)