forked from Chudleyj/AlgoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GetSetClearTA.cpp
291 lines (248 loc) · 7.92 KB
/
GetSetClearTA.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
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
#include "TechnicalAnalysis.h"
std::mutex mtx; //For std::lock_guard
/* Access functions are used to call either the get or set for a
member variable, depending on what is past to them
(hence the boost::optionals)
Using boost::optional over std::optional so I can pass by reference
The point of using these instead of directly calling get or set functions
is to ensure thread safety. This way, no function can look at or set
a var while another thread has the lock.
***Technically, these are not needed for this class as it stands now
However, as algorithms that will use these variables are added, this will
be needed. */
//Temp = varible to temporarily hold value to be set via set functions
//Copy = variable that will get a copy of whatever is returned by the get func
void TechnicalAnalysis::accessMACD(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx); //Lock function from all other threads
if(temp)
setMACD(*temp);
else if(copy)
getMACD(*copy);
}
void TechnicalAnalysis::accessSignal(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setSignal(*temp);
else if(copy)
getSignal(*copy);
}
void TechnicalAnalysis::accessRSI(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setRSI(*temp);
else if(copy)
getRSI(*copy);
}
void TechnicalAnalysis::accessStoch(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setStoch(*temp);
else if(copy)
getStoch(*copy);
}
void TechnicalAnalysis::accessFifSMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setFifSMA(*temp);
else if (copy)
getFifSMA(*copy);
}
void TechnicalAnalysis::accessHundSMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setHundSMA(*temp);
else if (copy)
getHundSMA(*copy);
}
void TechnicalAnalysis::accessHundFifSMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setHundFifSMA(*temp);
else if (copy)
getHundFifSMA(*copy);
}
void TechnicalAnalysis::accessTwoHundSMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setTwoHundSMA(*temp);
else if (copy)
getTwoHundSMA(*copy);
}
void TechnicalAnalysis::accessFifEMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setFifEMA(*temp);
else if (copy)
getFifEMA(*copy);
}
void TechnicalAnalysis::accessHundEMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setHundEMA(*temp);
else if (copy)
getHundEMA(*copy);
}
void TechnicalAnalysis::accessHundFifEMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setHundFifEMA(*temp);
else if (copy)
getHundFifEMA(*copy);
}
void TechnicalAnalysis::accessTwoHundEMA(boost::optional<std::vector<double>&> copy,
boost::optional<double> temp)
{
std::lock_guard<std::mutex> guard(mtx);
if(temp)
setTwoHundEMA(*temp);
else if (copy)
getTwoHundEMA(*copy);
}
/* -------------------- START GETS --------------------
Get functions take in an vector, and make it a copy of whatever vector
the specific get function is for. These can be void because the vector
is passed by reference
These functions are const because we never modify any part of the class,
and a const function will ensure this */
void TechnicalAnalysis::getMACD(std::vector <double> ©) const
{
copy = indicators.MACD;
}
void TechnicalAnalysis::getSignal(std::vector <double> ©) const
{
copy = indicators.MACD_Signal;
}
void TechnicalAnalysis::getRSI(std::vector <double> ©) const
{
copy = indicators.RSI;
}
void TechnicalAnalysis::getStoch(std::vector <double> ©) const
{
copy = indicators.stochRSI;
}
void TechnicalAnalysis::getFifSMA(std::vector <double> ©) const
{
copy = indicators.fiftySMA;
}
void TechnicalAnalysis::getHundSMA(std::vector <double> ©) const
{
copy = indicators.hundredSMA;
}
void TechnicalAnalysis::getHundFifSMA(std::vector <double> ©) const
{
copy = indicators.hundFifSMA;
}
void TechnicalAnalysis::getTwoHundSMA(std::vector <double> ©) const
{
copy = indicators.twoHundSMA;
}
void TechnicalAnalysis::getFifEMA(std::vector <double> ©) const
{
copy = indicators.fiftyEMA;
}
void TechnicalAnalysis::getHundEMA(std::vector <double> ©) const
{
copy = indicators.hundredEMA;
}
void TechnicalAnalysis::getHundFifEMA(std::vector <double> ©) const
{
copy = indicators.hundFifEMA;
}
void TechnicalAnalysis::getTwoHundEMA(std::vector <double> ©) const
{
copy = indicators.twoHundEMA;
}
/*-------------------- END GETS --------------------*/
/* -------------------- START SETS --------------------
Here, set functions take in a value (temp), and push it back to their
corresponding member variable vector */
void TechnicalAnalysis::setFifSMA(const double &temp)
{
indicators.fiftySMA.push_back(temp);
}
void TechnicalAnalysis::setHundSMA(const double &temp)
{
indicators.hundredSMA.push_back(temp);
}
void TechnicalAnalysis::setHundFifSMA(const double &temp)
{
indicators.hundFifSMA.push_back(temp);
}
void TechnicalAnalysis::setTwoHundSMA(const double &temp)
{
indicators.twoHundSMA.push_back(temp);
}
void TechnicalAnalysis::setFifEMA(const double &temp)
{
indicators.fiftyEMA.push_back(temp);
}
void TechnicalAnalysis::setHundEMA(const double &temp)
{
indicators.hundredEMA.push_back(temp);
}
void TechnicalAnalysis::setHundFifEMA(const double &temp)
{
indicators.hundFifEMA.push_back(temp);
}
void TechnicalAnalysis::setTwoHundEMA(const double &temp)
{
indicators.twoHundEMA.push_back(temp);
}
void TechnicalAnalysis::setRSI(const double &temp)
{
indicators.RSI.push_back(temp);
}
void TechnicalAnalysis::setStoch(const double &temp)
{
indicators.stochRSI.push_back(temp);
}
void TechnicalAnalysis::setMACD(const double &temp)
{
indicators.MACD.push_back(temp);
}
void TechnicalAnalysis::setSignal(const double &temp)
{
indicators.MACD_Signal.push_back(temp);
}
/*-------------------- END SETS --------------------*/
/* Clear all the data out of the vectors
This is done because the data needs to be always as up to date as possible
So, the data is calculated once, and then cleared and replaced.
In the future, before it is cleared, it will be used by algorithms
Which will always want the newest possible data, hence the clear function */
void TechnicalAnalysis::clearTAobj()
{
indicators.RSI.clear();
indicators.stochRSI.clear();
indicators.fiftySMA.clear();
indicators.hundredSMA.clear();
indicators.hundFifSMA.clear();
indicators.twoHundSMA.clear();
indicators.fiftyEMA.clear();
indicators.hundredEMA.clear();
indicators.hundFifEMA.clear();
indicators.twoHundEMA.clear();
indicators.stdDeviation.clear();
}