forked from expressoman/ewa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselector_corrections.go
249 lines (194 loc) · 4.92 KB
/
selector_corrections.go
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
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package ewa
//SelectorCorrections struct
type SelectorCorrections struct {
Label string
lastPrice *Point
Corr Corrections
}
func (in SelectorCorrections) outCopy() SelectorCorrections {
return SelectorCorrections{
Label: in.Label,
lastPrice: in.lastPrice,
}
}
//ByWave finder
func (in SelectorCorrections) ByWave(w Waver) (Correction, bool) {
for _, one := range in.Corr {
if one.Starts() == w.Starts() && one.Tops() == w.Tops() {
return one, true
}
}
return Correction{}, false
}
//Ongoing waves
func (in SelectorCorrections) Ongoing() (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Begins().Before(in.lastPrice.T) && one.Ends().After(in.lastPrice.T) {
out.Corr = append(out.Corr, one)
}
}
return
}
//FromTo finds waves that start and end at specified price
func (in SelectorCorrections) FromTo(from, to float64) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Starts() == from && one.Tops() == to {
out.Corr = append(out.Corr, one)
}
}
return
}
//From finds waves that start there
func (in SelectorCorrections) From(from float64) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Starts() == from {
out.Corr = append(out.Corr, one)
}
}
return
}
//To finds waves that end there
func (in SelectorCorrections) To(to float64) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Tops() == to {
out.Corr = append(out.Corr, one)
}
}
return
}
//Sub finds waves that have subdivision
func (in SelectorCorrections) Sub(has bool) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Sub() == has {
out.Corr = append(out.Corr, one)
}
}
return
}
func (in SelectorCorrections) dir(dir bool) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Up() == dir {
out.Corr = append(out.Corr, one)
}
}
return
}
//Up finds waves that go up
func (in SelectorCorrections) Up() SelectorCorrections {
return in.dir(true)
}
//Down finds waves that go down
func (in SelectorCorrections) Down() SelectorCorrections {
return in.dir(false)
}
//Degree finds waves that end there
func (in SelectorCorrections) Degree(degree DegreeType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Degree() == degree {
out.Corr = append(out.Corr, one)
}
}
return
}
//DegreeGreaterOr finds waves that degree GreaterOr
func (in SelectorCorrections) DegreeGreaterOr(degree DegreeType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Degree() >= degree {
out.Corr = append(out.Corr, one)
}
}
return
}
//DegreeGreater finds waves that degree GreaterOr
func (in SelectorCorrections) DegreeGreater(degree DegreeType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Degree() > degree {
out.Corr = append(out.Corr, one)
}
}
return
}
//DegreeLessOr finds waves that degree GreaterOr
func (in SelectorCorrections) DegreeLessOr(degree DegreeType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Degree() <= degree {
out.Corr = append(out.Corr, one)
}
}
return
}
//DegreeLess finds waves that degree GreaterOr
func (in SelectorCorrections) DegreeLess(degree DegreeType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Degree() < degree {
out.Corr = append(out.Corr, one)
}
}
return
}
//Info selector
func (in SelectorCorrections) Info() {
for _, one := range in.Corr {
one.Info(in.Label)
}
}
//Len how many waves
func (in SelectorCorrections) Len() int {
return len(in.Corr)
}
//First gets first correction
func (in SelectorCorrections) First() (Correction, bool) {
if len(in.Corr) > 0 {
return in.Corr[0], true
}
return Correction{}, false
}
//Last gets last correction
func (in SelectorCorrections) Last() (Correction, bool) {
if len(in.Corr) > 0 {
return in.Corr[len(in.Corr)-1], true
}
return Correction{}, false
}
// Specific to corrections
//Type gets corrections by type
func (in SelectorCorrections) Type(ct CorrectionType) (out SelectorCorrections) {
out = in.outCopy()
for _, one := range in.Corr {
if one.Type() == ct {
out.Corr = append(out.Corr, one)
}
}
return
}
//Zigzag corrections only
func (in SelectorCorrections) Zigzag() (out SelectorCorrections) {
return in.Type(CTZigzag)
}
//Flat corrections only
func (in SelectorCorrections) Flat() (out SelectorCorrections) {
return in.Type(CTFlat)
}
//Triangle corrections only
func (in SelectorCorrections) Triangle() (out SelectorCorrections) {
return in.Type(CTTriangle)
}
//Combo corrections only
func (in SelectorCorrections) Combo() (out SelectorCorrections) {
return in.Type(CTCombo)
}
//Triple corrections only
func (in SelectorCorrections) Triple() (out SelectorCorrections) {
return in.Type(CTTriple)
}