-
Notifications
You must be signed in to change notification settings - Fork 68
/
ZhongShu.cpp
148 lines (143 loc) · 3.43 KB
/
ZhongShu.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
#include "ZhongShu.h"
ZhongShu::ZhongShu()
{
this->bValid = false;
this->nTop1 = 0;
this->nTop2 = 0;
this->nTop3 = 0;
this->nBot1 = 0;
this->nBot2 = 0;
this->nBot3 = 0;
this->fTop1 = 0;
this->fTop2 = 0;
this->fTop3 = 0;
this->fBot1 = 0;
this->fBot2 = 0;
this->fBot3 = 0;
this->nLines = 0;
this->nStart = 0;
this->nEnd = 0;
this->fHigh = 0;
this->fLow = 0;
this->nDirection = 0;
this->nTerminate = 0;
}
ZhongShu::~ZhongShu()
{
}
void ZhongShu::Reset()
{
this->bValid = false;
this->nTop1 = 0;
this->nTop2 = 0;
this->nTop3 = 0;
this->nBot1 = 0;
this->nBot2 = 0;
this->nBot3 = 0;
this->fTop1 = 0;
this->fTop2 = 0;
this->fTop3 = 0;
this->fBot1 = 0;
this->fBot2 = 0;
this->fBot3 = 0;
this->nLines = 0;
this->nStart = 0;
this->nEnd = 0;
this->fHigh = 0;
this->fLow = 0;
this->nDirection = 0;
this->nTerminate = 0;
}
// 推入高点并计算状态
bool ZhongShu::PushHigh(int nIndex, float fValue)
{
nTop3 = nTop2;
fTop3 = fTop2;
nTop2 = nTop1;
fTop2 = fTop1;
nTop1 = nIndex;
fTop1 = fValue;
if (bValid == true)
{
if (fTop1 < fLow) // 中枢终结
{
nTerminate = -1;
if (nTop2 > nEnd)
{
nEnd = nTop2;
}
return true;
}
else
{
if (nBot1 > nEnd)
{
nEnd = nBot1; // 中枢终结点后移
}
}
}
else
{
if (nTop3 > 0 && nTop2 > 0 && nTop1 > 0 && nBot2 > 0 && nBot1 > 0) // 有两个高点和两个低点
{
float fTempHigh = (fTop1 < fTop2 ? fTop1 : fTop2);
float fTempLow = (fBot1 > fBot2 ? fBot1 : fBot2);
if (fTop3 > fTop2 && fTempHigh > fTempLow) // 有中枢
{
nDirection = -1; // 向下中枢
nStart = nBot2;
nEnd = nTop1;
fHigh = fTempHigh;
fLow = fTempLow;
bValid = true;
}
}
}
return false;
}
bool ZhongShu::PushLow(int nIndex, float fValue)
{
nBot3 = nBot2;
fBot3 = fBot2;
nBot2 = nBot1;
fBot2 = fBot1;
nBot1 = nIndex;
fBot1 = fValue;
if (bValid == true)
{
if (fBot1 > fHigh) // 中枢终结
{
nTerminate = 1;
if (nBot2 > nEnd)
{
nEnd = nBot2;
}
return true;
}
else
{
if (nTop1 > nEnd)
{
nEnd = nTop1; // 中枢终结点后移
}
}
}
else
{
if (nTop2 > 0 && nTop1 > 0 && nBot3 > 0 && nBot2 > 0 && nBot1 > 0) // 有两个高点和两个低点
{
float fTempHigh = (fTop1 < fTop2 ? fTop1 : fTop2);
float fTempLow = (fBot1 > fBot2 ? fBot1 : fBot2);
if (fBot3 < fBot2 && fTempHigh > fTempLow) // 有中枢
{
nDirection = 1; // 向上中枢
nStart = nTop2;
nEnd = nBot1;
fHigh = fTempHigh;
fLow = fTempLow;
bValid = true;
}
}
}
return false;
}