forked from mywildquant/ChanlunX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBiChuLi.cpp
223 lines (220 loc) · 7.99 KB
/
BiChuLi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#include <iostream>
#include <fstream>
#include <exception>
#include "BiChuLi.h"
#include "KxianChuLi.h"
using namespace std;
bool ifChengbi(vector<Kxian> &tempKxianList, int direction)
{
if (tempKxianList.size() < 4)
{
// 如果连4根K线都没有的话肯定不是笔
return false;
}
if (direction == -1)
{
// 是不是向下成笔
// 先找有没有下降K线
unsigned int i = 2;
while (true)
{
for (; i < tempKxianList.size(); i++)
{
if (tempKxianList.at(i).di < tempKxianList.at(i - 1).di && tempKxianList.at(i - 1).di < tempKxianList.at(i - 2).di)
{
// 找到下降K线
break;
}
}
if (i >= tempKxianList.size())
{
// 下降K线都没找到
return false;
}
// 找前面的最低价
float zuiDiJia = tempKxianList.at(i).di;
// 如果出现了更低价,这个笔就成立了
for (unsigned int j = i + 1; j < tempKxianList.size(); j++)
{
if (tempKxianList.at(j).di < zuiDiJia)
{
return true;
}
}
i = i + 1;
}
}
else if (direction == 1)
{
// 是不是向上成笔
// 先找有没有上升K线
unsigned int i = 2;
while (true)
{
for (; i < tempKxianList.size(); i++)
{
if (tempKxianList.at(i).gao > tempKxianList.at(i - 1).gao && tempKxianList.at(i - 1).gao > tempKxianList.at(i - 2).gao)
{
// 找到上升K线
break;
}
}
if (i >= tempKxianList.size())
{
// 上升K线都没找到
return false;
}
// 找前面的最高价
float zuiGaoJia = tempKxianList.at(i).gao;
// 如果出现了更高价,这个笔就成立了
for (unsigned int j = i + 1; j < tempKxianList.size(); j++)
{
if (tempKxianList.at(j).gao > zuiGaoJia)
{
return true;
}
}
i = i + 1;
}
}
return false;
}
void BiChuLi::handle(vector<Kxian> &kxianList)
{
vector<Kxian> tempKxianList; // 临时未成笔K线的保存
for (vector<Kxian>::iterator iter = kxianList.begin(); iter != kxianList.end(); iter++)
{
if (this->biList.empty())
{
// 第一笔生成中,也是假设第一笔是向上的
Bi bi;
bi.fangXiang = 1;
bi.kaiShi = (*iter).kaiShi;
bi.jieShu = (*iter).jieShu;
bi.gao = (*iter).gao;
bi.di = (*iter).di;
bi.kxianList.push_back(*iter);
this->biList.push_back(bi);
}
else
{
if (this->biList.back().fangXiang == 1)
{
// 上一笔是向上笔
if ((*iter).gao >= this->biList.back().gao)
{
// 向上笔继续延续
this->biList.back().jieShu = (*iter).jieShu;
this->biList.back().gao = (*iter).gao;
if (tempKxianList.size() > 0)
{
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
this->biList.back().kxianList.push_back(*it);
}
tempKxianList.clear();
}
this->biList.back().kxianList.push_back(*iter);
}
else
{
tempKxianList.push_back(*iter);
// 有没有成新的向下笔
if (ifChengbi(tempKxianList, -1))
{
Bi bi;
bi.fangXiang = -1;
bi.kaiShi = this->biList.back().jieShu;
bi.jieShu = tempKxianList.back().jieShu;
bi.di = tempKxianList.back().di;
bi.gao = this->biList.back().gao;
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
bi.kxianList.push_back(*it);
}
tempKxianList.clear();
this->biList.push_back(bi);
}
}
}
else if (this->biList.back().fangXiang == -1)
{
// 上一笔是向下笔
if ((*iter).di <= this->biList.back().di)
{
// 向下笔继续延续
this->biList.back().jieShu = (*iter).jieShu;
this->biList.back().di = (*iter).di;
if (tempKxianList.size() > 0)
{
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
this->biList.back().kxianList.push_back(*it);
}
tempKxianList.clear();
}
this->biList.back().kxianList.push_back(*iter);
}
else
{
tempKxianList.push_back(*iter);
// 有没有成新的向上笔
if (ifChengbi(tempKxianList, 1))
{
Bi bi;
bi.fangXiang = 1;
bi.kaiShi = this->biList.back().jieShu;
bi.jieShu = tempKxianList.back().jieShu;
bi.gao = tempKxianList.back().gao;
bi.di = this->biList.back().di;
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
bi.kxianList.push_back(*it);
}
tempKxianList.clear();
this->biList.push_back(bi);
}
}
}
}
}
if (tempKxianList.size() >= 4)
{
if (this->biList.back().fangXiang == 1)
{
if (ifChengbi(tempKxianList, -1))
{
Bi bi;
bi.fangXiang = -1;
bi.kaiShi = this->biList.back().jieShu;
bi.jieShu = tempKxianList.back().jieShu;
bi.di = tempKxianList.back().di;
bi.gao = this->biList.back().gao;
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
bi.kxianList.push_back(*it);
}
tempKxianList.clear();
this->biList.push_back(bi);
}
}
else if (this->biList.back().fangXiang == -1)
{
if (ifChengbi(tempKxianList, 1))
{
Bi bi;
bi.fangXiang = 1;
bi.kaiShi = this->biList.back().jieShu;
bi.jieShu = tempKxianList.back().jieShu;
bi.gao = tempKxianList.back().gao;
bi.di = this->biList.back().di;
for (vector<Kxian>::iterator it = tempKxianList.begin(); it != tempKxianList.end(); it++)
{
bi.kxianList.push_back(*it);
}
tempKxianList.clear();
this->biList.push_back(bi);
}
}
}
}