rust_ta_lib/wrapper.rs
1/// TA_ACCBANDS - Acceleration Bands
2/// #Sample
3/// ```
4/// let close_prices: Vec<f64> = vec![
5/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
6/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
7/// 1.086670, 1.086630,
8/// ];
9/// let high_prices = close_prices.clone();
10/// let low_prices = close_prices.clone();
11/// let (uppers,middles,lowers, begin) = rust_ta_lib::wrapper::accbands(10, &high_prices,&low_prices,&close_prices);
12/// for (index, value) in uppers.iter().enumerate() {
13/// println!("upper index {} = {}", begin + index as i32 + 1, value);
14/// println!("middle index {} = {:?}", begin + index as i32 + 1, middles.get(index));
15/// println!("lower index {} = {:?}", begin + index as i32 + 1, lowers.get(index));
16/// }
17/// ```
18pub fn accbands(
19 period: u32,
20 high: &Vec<f64>,
21 low: &Vec<f64>,
22 close: &Vec<f64>,
23) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
24 let mut outUpper: Vec<f64> = Vec::with_capacity(close.len());
25 let mut middleUpper: Vec<f64> = Vec::with_capacity(close.len());
26 let mut lowerUpper: Vec<f64> = Vec::with_capacity(close.len());
27 let mut out_begin: crate::TA_Integer = 0;
28 let mut out_size: crate::TA_Integer = 0;
29
30 unsafe {
31 crate::TA_Initialize();
32 let ret_code = crate::TA_ACCBANDS(
33 0, // index of the first close to use
34 close.len() as i32 - 1, // index of the last close to use
35 high.as_ptr(), // pointer to the first element of the high vector
36 low.as_ptr(), // pointer to the first element of the low vector
37 close.as_ptr(), // pointer to the first element of the close vector
38 period as i32, // period of the atr
39 &mut out_begin, // set to index of the first close to have an atr value
40 &mut out_size, // set to number of atr values computed
41 outUpper.as_mut_ptr(), // pointer to the first element of the output vector
42 middleUpper.as_mut_ptr(),
43 lowerUpper.as_mut_ptr(),
44 );
45
46 match ret_code {
47 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
48 // Rust doesn't know what is the new length of the vector, so we set it manually
49 // to the number of values returned by the TA_ATR call
50 crate::TA_RetCode_TA_SUCCESS => outUpper.set_len(out_size as usize),
51 // An error occured
52 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
53 }
54 crate::TA_Shutdown();
55 }
56
57 (outUpper, middleUpper, lowerUpper, out_begin)
58}
59
60/// TA_ACCBANDS - Acceleration Bands
61/// #Sample
62/// ```
63/// let close_prices: Vec<f32> = vec![
64/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
65/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
66/// 1.086670, 1.086630,
67/// ];
68/// let high_prices = close_prices.clone();
69/// let low_prices = close_prices.clone();
70/// let (uppers,middles,lowers, begin) = rust_ta_lib::wrapper::s_accbands(10, &high_prices,&low_prices,&close_prices);
71/// for (index, value) in uppers.iter().enumerate() {
72/// println!("upper index {} = {}", begin + index as i32 + 1, value);
73/// println!("middle index {} = {:?}", begin + index as i32 + 1, middles.get(index));
74/// println!("lower index {} = {:?}", begin + index as i32 + 1, lowers.get(index));
75/// }
76/// ```
77pub fn s_accbands(
78 period: u32,
79 high: &Vec<f32>,
80 low: &Vec<f32>,
81 close: &Vec<f32>,
82) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
83 let mut outUpper: Vec<f64> = Vec::with_capacity(close.len());
84 let mut middleUpper: Vec<f64> = Vec::with_capacity(close.len());
85 let mut lowerUpper: Vec<f64> = Vec::with_capacity(close.len());
86 let mut out_begin: crate::TA_Integer = 0;
87 let mut out_size: crate::TA_Integer = 0;
88
89 unsafe {
90 crate::TA_Initialize();
91 let ret_code = crate::TA_S_ACCBANDS(
92 0, // index of the first close to use
93 close.len() as i32 - 1, // index of the last close to use
94 high.as_ptr(), // pointer to the first element of the high vector
95 low.as_ptr(), // pointer to the first element of the low vector
96 close.as_ptr(), // pointer to the first element of the close vector
97 period as i32, // period of the atr
98 &mut out_begin, // set to index of the first close to have an atr value
99 &mut out_size, // set to number of atr values computed
100 outUpper.as_mut_ptr(), // pointer to the first element of the output vector
101 middleUpper.as_mut_ptr(),
102 lowerUpper.as_mut_ptr(),
103 );
104
105 match ret_code {
106 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
107 // Rust doesn't know what is the new length of the vector, so we set it manually
108 // to the number of values returned by the TA_ATR call
109 crate::TA_RetCode_TA_SUCCESS => outUpper.set_len(out_size as usize),
110 // An error occured
111 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
112 }
113 crate::TA_Shutdown();
114 }
115
116 (outUpper, middleUpper, lowerUpper, out_begin)
117}
118
119///
120/// TA_COS - Vector Trigonometric Cos
121///
122/// Input = double
123/// Output = double
124/// #Sample
125/// ```
126/// let close_prices: Vec<f64> = vec![
127/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
128/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
129/// 1.086670, 1.086630,
130/// ];
131/// let (outs, begin) = rust_ta_lib::wrapper::acos(&close_prices);
132/// for (index, value) in outs.iter().enumerate() {
133/// println!("outs index {} = {}", begin + index as i32 + 1, value);
134/// }
135/// ```
136pub fn acos(close: &Vec<f64>) -> (Vec<f64>, crate::TA_Integer) {
137 let mut out: Vec<f64> = Vec::with_capacity(close.len());
138 let mut out_begin: crate::TA_Integer = 0;
139 let mut out_size: crate::TA_Integer = 0;
140
141 unsafe {
142 crate::TA_Initialize();
143
144 let ret_code = crate::TA_COS(
145 0, // index of the first close to use
146 close.len() as i32 - 1, // index of the last close to use
147 close.as_ptr(), // pointer to the first element of the close vector
148 &mut out_begin, // set to index of the first close to have an atr value
149 &mut out_size, // set to number of atr values computed
150 out.as_mut_ptr(), // pointer to the first element of the output vector
151 );
152
153 match ret_code {
154 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
155 // Rust doesn't know what is the new length of the vector, so we set it manually
156 // to the number of values returned by the TA_ATR call
157 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
158 // An error occured
159 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
160 }
161 crate::TA_Shutdown();
162 }
163
164 (out, out_begin)
165}
166
167///
168/// TA_COS - Vector Trigonometric Cos
169///
170/// Input = double
171/// Output = double
172/// #Sample
173/// ```
174/// let close_prices: Vec<f32> = vec![
175/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
176/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
177/// 1.086670, 1.086630,
178/// ];
179/// let (outs, begin) = rust_ta_lib::wrapper::s_acos(&close_prices);
180/// for (index, value) in outs.iter().enumerate() {
181/// println!("outs index {} = {}", begin + index as i32 + 1, value);
182/// }
183/// ```
184pub fn s_acos(close: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
185 let mut out: Vec<f64> = Vec::with_capacity(close.len());
186 let mut out_begin: crate::TA_Integer = 0;
187 let mut out_size: crate::TA_Integer = 0;
188
189 unsafe {
190 crate::TA_Initialize();
191
192 let ret_code = crate::TA_S_COS(
193 0, // index of the first close to use
194 close.len() as i32 - 1, // index of the last close to use
195 close.as_ptr(), // pointer to the first element of the close vector
196 &mut out_begin, // set to index of the first close to have an atr value
197 &mut out_size, // set to number of atr values computed
198 out.as_mut_ptr(), // pointer to the first element of the output vector
199 );
200
201 match ret_code {
202 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
203 // Rust doesn't know what is the new length of the vector, so we set it manually
204 // to the number of values returned by the TA_ATR call
205 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
206 // An error occured
207 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
208 }
209 crate::TA_Shutdown();
210 }
211
212 (out, out_begin)
213}
214///
215/// TA_AD - Chaikin A/D Line
216///
217/// Input = High, Low, Close, Volume
218/// Output = double
219/// #Sample
220/// ```
221/// let close_prices: Vec<f64> = vec![
222/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
223/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
224/// 1.086670, 1.086630,
225/// ];
226/// let high_prices = close_prices.clone();
227/// let low_prices = close_prices.clone();
228/// let volume = close_prices.clone();
229/// let (outs, begin) = rust_ta_lib::wrapper::ad( &high_prices,&low_prices,&close_prices,&volume);
230/// for (index, value) in outs.iter().enumerate() {
231/// println!("outs index {} = {}", begin + index as i32 + 1, value);
232/// }
233/// ```
234pub fn ad(
235 high: &Vec<f64>,
236 low: &Vec<f64>,
237 close: &Vec<f64>,
238 volume: &Vec<f64>,
239) -> (Vec<f64>, crate::TA_Integer) {
240 let mut out: Vec<f64> = Vec::with_capacity(close.len());
241 let mut out_begin: crate::TA_Integer = 0;
242 let mut out_size: crate::TA_Integer = 0;
243
244 unsafe {
245 crate::TA_Initialize();
246 let ret_code = crate::TA_AD(
247 0, // index of the first close to use
248 close.len() as i32 - 1, // index of the last close to use
249 high.as_ptr(), // pointer to the first element of the high vector
250 low.as_ptr(), // pointer to the first element of the low vector
251 close.as_ptr(), // pointer to the first element of the close vector
252 volume.as_ptr(), // pointer to the first element of the volume vector
253 &mut out_begin, // set to index of the first close to have an atr value
254 &mut out_size, // set to number of atr values computed
255 out.as_mut_ptr(), // pointer to the first element of the output vector
256 );
257
258 match ret_code {
259 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
260 // Rust doesn't know what is the new length of the vector, so we set it manually
261 // to the number of values returned by the TA_ATR call
262 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
263 // An error occured
264 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
265 }
266 crate::TA_Shutdown();
267 }
268
269 (out, out_begin)
270}
271///
272/// TA_S_AD - Chaikin A/D Line
273///
274/// Input = High, Low, Close, Volume
275/// Output = double
276/// #Sample
277/// ```
278/// let close_prices: Vec<f32> = vec![
279/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
280/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
281/// 1.086670, 1.086630,
282/// ];
283/// let high_prices = close_prices.clone();
284/// let low_prices = close_prices.clone();
285/// let volume = close_prices.clone();
286/// let (outs, begin) = rust_ta_lib::wrapper::s_ad( &high_prices,&low_prices,&close_prices,&volume);
287/// for (index, value) in outs.iter().enumerate() {
288/// println!("outs index {} = {}", begin + index as i32 + 1, value);
289/// }
290/// ```
291pub fn s_ad(
292 high: &Vec<f32>,
293 low: &Vec<f32>,
294 close: &Vec<f32>,
295 volume: &Vec<f32>,
296) -> (Vec<f64>, crate::TA_Integer) {
297 let mut out: Vec<f64> = Vec::with_capacity(close.len());
298 let mut out_begin: crate::TA_Integer = 0;
299 let mut out_size: crate::TA_Integer = 0;
300
301 unsafe {
302 crate::TA_Initialize();
303 let ret_code = crate::TA_S_AD(
304 0, // index of the first close to use
305 close.len() as i32 - 1, // index of the last close to use
306 high.as_ptr(), // pointer to the first element of the high vector
307 low.as_ptr(), // pointer to the first element of the low vector
308 close.as_ptr(), // pointer to the first element of the close vector
309 volume.as_ptr(), // pointer to the first element of the volume vector
310 &mut out_begin, // set to index of the first close to have an atr value
311 &mut out_size, // set to number of atr values computed
312 out.as_mut_ptr(), // pointer to the first element of the output vector
313 );
314
315 match ret_code {
316 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
317 // Rust doesn't know what is the new length of the vector, so we set it manually
318 // to the number of values returned by the TA_ATR call
319 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
320 // An error occured
321 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
322 }
323 crate::TA_Shutdown();
324 }
325
326 (out, out_begin)
327}
328pub fn add() {}
329pub fn s_add() {}
330
331///
332/// TA_ADOSC - Aroon Oscillator
333///
334/// `Input`: high, low, close, volume, fastperiod, slowperiod
335///
336/// `Output`: (1st, 2nd)
337///
338/// 1st: output vector(f64)
339///
340/// 2nd: the first index of inputs corresponding to an valid output value
341///
342pub fn adosc(
343 high: &Vec<f64>,
344 low: &Vec<f64>,
345 close: &Vec<f64>,
346 volume: &Vec<f64>,
347 fastperiod: i32,
348 slowperiod: i32,
349) -> (Vec<f64>, crate::TA_Integer) {
350 let hlen = high.len();
351 if hlen.ne(&low.len()) || hlen.ne(&close.len()) || hlen.ne(&volume.len()) {
352 panic!("The length of input vectors are not equal, please double check the size of each.");
353 }
354
355 let mut out: Vec<f64> = Vec::with_capacity(hlen);
356 let mut out_begin: crate::TA_Integer = 0;
357 let mut out_size: crate::TA_Integer = 0;
358
359 unsafe {
360 crate::TA_Initialize();
361 let ret_code = crate::TA_ADOSC(
362 0, // the first index of the input vector to use
363 hlen as i32 - 1, // the last index of the input vector to use
364 high.as_ptr(), // pointer to the high vector
365 low.as_ptr(), // pointer to the low vector
366 close.as_ptr(), // pointer to the close vector
367 volume.as_ptr(), // pointer to the volume vector
368 fastperiod, // fast period
369 slowperiod, // slow period
370 &mut out_begin, // set to index of the first close to have an valid output value
371 &mut out_size, // set to number of values computed
372 out.as_mut_ptr(), // pointer to the first element of the output vector
373 );
374
375 match ret_code {
376 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
377 // Rust doesn't know what is the new length of the vector, so we set it manually
378 // to the number of values returned by the TA_ATR call
379 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
380 // An error occured
381 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
382 }
383 crate::TA_Shutdown();
384 }
385
386 (out, out_begin)
387}
388pub fn s_adosc() {}
389
390///
391/// TA_ADX - Average Directional Movement Index
392///
393/// Input = High, Low, Close, Volume
394/// Output = double
395/// #Sample
396/// ```
397/// let close_prices: Vec<f64> = vec![
398/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
399/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
400/// 1.086670, 1.086630,
401/// ];
402/// let high_prices = close_prices.clone();
403/// let low_prices = close_prices.clone();
404/// let (outs, begin) = rust_ta_lib::wrapper::adx( 10,&high_prices,&low_prices,&close_prices);
405/// for (index, value) in outs.iter().enumerate() {
406/// println!("outs index {} = {}", begin + index as i32 + 1, value);
407/// }
408/// ```
409pub fn adx(
410 period: u32,
411 high: &Vec<f64>,
412 low: &Vec<f64>,
413 close: &Vec<f64>,
414) -> (Vec<f64>, crate::TA_Integer) {
415 let mut out: Vec<f64> = Vec::with_capacity(close.len());
416 let mut out_begin: crate::TA_Integer = 0;
417 let mut out_size: crate::TA_Integer = 0;
418
419 unsafe {
420 crate::TA_Initialize();
421 let ret_code = crate::TA_ADX(
422 0, // index of the first close to use
423 close.len() as i32 - 1, // index of the last close to use
424 high.as_ptr(), // pointer to the first element of the high vector
425 low.as_ptr(), // pointer to the first element of the low vector
426 close.as_ptr(), // pointer to the first element of the close vector
427 period as i32, // period of the atr
428 &mut out_begin, // set to index of the first close to have an atr value
429 &mut out_size, // set to number of atr values computed
430 out.as_mut_ptr(), // pointer to the first element of the output vector
431 );
432 match ret_code {
433 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
434 // Rust doesn't know what is the new length of the vector, so we set it manually
435 // to the number of values returned by the TA_ATR call
436 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
437 // An error occured
438 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
439 }
440 crate::TA_Shutdown();
441 }
442
443 (out, out_begin)
444}
445///
446/// TA_S_ADX - Average Directional Movement Index
447///
448/// Input = High, Low, Close, Volume
449/// Output = double
450/// #Sample
451/// ```
452/// let close_prices: Vec<f32> = vec![
453/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
454/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
455/// 1.086670, 1.086630,
456/// ];
457/// let high_prices = close_prices.clone();
458/// let low_prices = close_prices.clone();
459/// let (outs, begin) = rust_ta_lib::wrapper::s_adx( 10,&high_prices,&low_prices,&close_prices);
460/// for (index, value) in outs.iter().enumerate() {
461/// println!("outs index {} = {}", begin + index as i32 + 1, value);
462/// }
463/// ```
464pub fn s_adx(
465 period: u32,
466 high: &Vec<f32>,
467 low: &Vec<f32>,
468 close: &Vec<f32>,
469) -> (Vec<f64>, crate::TA_Integer) {
470 let mut out: Vec<f64> = Vec::with_capacity(close.len());
471 let mut out_begin: crate::TA_Integer = 0;
472 let mut out_size: crate::TA_Integer = 0;
473
474 unsafe {
475 crate::TA_Initialize();
476 let ret_code = crate::TA_S_ADX(
477 0, // index of the first close to use
478 close.len() as i32 - 1, // index of the last close to use
479 high.as_ptr(), // pointer to the first element of the high vector
480 low.as_ptr(), // pointer to the first element of the low vector
481 close.as_ptr(), // pointer to the first element of the close vector
482 period as i32, // period of the atr
483 &mut out_begin, // set to index of the first close to have an atr value
484 &mut out_size, // set to number of atr values computed
485 out.as_mut_ptr(), // pointer to the first element of the output vector
486 );
487 match ret_code {
488 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
489 // Rust doesn't know what is the new length of the vector, so we set it manually
490 // to the number of values returned by the TA_ATR call
491 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
492 // An error occured
493 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
494 }
495 crate::TA_Shutdown();
496 }
497
498 (out, out_begin)
499}
500pub fn adxr() {}
501pub fn s_adxr() {}
502
503///
504/// TA_APO - Absolute Price Oscillator
505///
506/// `Input` = close, fastperiod(12), slowperiod(26), matype
507///
508/// `Output`: (1st, 2nd)
509///
510/// 1st: output vector(f64)
511///
512/// 2nd: the first index of inputs corresponding to an valid output value
513///
514pub fn apo(
515 close: &Vec<f64>,
516 fastperiod: i32,
517 slowperiod: i32,
518 matype: crate::TA_MAType,
519) -> (Vec<f64>, crate::TA_Integer) {
520 let mut out: Vec<f64> = Vec::with_capacity(close.len());
521 let mut out_begin: crate::TA_Integer = 0;
522 let mut out_size: crate::TA_Integer = 0;
523
524 unsafe {
525 crate::TA_Initialize();
526 let ret_code = crate::TA_APO(
527 0, // index of the first close to use
528 close.len() as i32 - 1, // index of the last close to use
529 close.as_ptr(), // pointer to the first element of the close vector
530 fastperiod, // fast period (suggest default 12)
531 slowperiod, // slow period (suggest default 26)
532 matype, // MA Type
533 &mut out_begin, // set to index of the first close to have an valid output value
534 &mut out_size, // set to number of values computed
535 out.as_mut_ptr(), // pointer to the first element of the output vector
536 );
537
538 match ret_code {
539 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
540 // Rust doesn't know what is the new length of the vector, so we set it manually
541 // to the number of values returned by the TA_ATR call
542 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
543 // An error occured
544 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
545 }
546 crate::TA_Shutdown();
547 }
548
549 (out, out_begin)
550}
551pub fn s_apo() {}
552pub fn aroon() {}
553pub fn s_aroon() {}
554
555///
556/// TA_AROONOSC - Aroon Oscillator
557///
558/// `Input`: high, low, timeperiod
559///
560/// `Output`: (1st, 2nd)
561///
562/// 1st: output vector(f64)
563///
564/// 2nd: the first index of inputs corresponding to an valid output value
565///
566pub fn aroonosc(high: &Vec<f64>, low: &Vec<f64>, timeperiod: i32) -> (Vec<f64>, crate::TA_Integer) {
567 let hlen = high.len();
568 if hlen.ne(&low.len()) {
569 panic!("The length of input vectors are not equal, please double check the size of each.");
570 }
571
572 let mut out: Vec<f64> = Vec::with_capacity(hlen);
573 let mut out_begin: crate::TA_Integer = 0;
574 let mut out_size: crate::TA_Integer = 0;
575
576 unsafe {
577 crate::TA_Initialize();
578 let ret_code = crate::TA_AROONOSC(
579 0, // the first index of the input vector to use
580 hlen as i32 - 1, // the last index of the input vector to use
581 high.as_ptr(), // pointer to the high vector
582 low.as_ptr(), // pointer to the low vector
583 timeperiod, // time period
584 &mut out_begin, // set to index of the first close to have an valid output value
585 &mut out_size, // set to number of values computed
586 out.as_mut_ptr(), // pointer to the first element of the output vector
587 );
588
589 match ret_code {
590 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
591 // Rust doesn't know what is the new length of the vector, so we set it manually
592 // to the number of values returned by the TA_ATR call
593 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
594 // An error occured
595 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
596 }
597 crate::TA_Shutdown();
598 }
599
600 (out, out_begin)
601}
602pub fn s_aroonosc() {}
603pub fn asin() {}
604pub fn s_asin() {}
605pub fn atan() {}
606pub fn s_atan() {}
607pub fn atr(
608 period: u32,
609 high: &Vec<f64>,
610 low: &Vec<f64>,
611 close: &Vec<f64>,
612) -> (Vec<f64>, crate::TA_Integer) {
613 let mut out: Vec<f64> = Vec::with_capacity(close.len());
614 let mut out_begin: crate::TA_Integer = 0;
615 let mut out_size: crate::TA_Integer = 0;
616
617 unsafe {
618 crate::TA_Initialize();
619 let ret_code = crate::TA_ATR(
620 0, // index of the first close to use
621 close.len() as i32 - 1, // index of the last close to use
622 high.as_ptr(), // pointer to the first element of the high vector
623 low.as_ptr(), // pointer to the first element of the low vector
624 close.as_ptr(), // pointer to the first element of the close vector
625 period as i32, // period of the atr
626 &mut out_begin, // set to index of the first close to have an atr value
627 &mut out_size, // set to number of atr values computed
628 out.as_mut_ptr(), // pointer to the first element of the output vector
629 );
630 match ret_code {
631 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
632 // Rust doesn't know what is the new length of the vector, so we set it manually
633 // to the number of values returned by the TA_ATR call
634 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
635 // An error occured
636 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
637 }
638 crate::TA_Shutdown();
639 }
640
641 (out, out_begin)
642}
643pub fn s_atr(
644 period: u32,
645 high: &Vec<f32>,
646 low: &Vec<f32>,
647 close: &Vec<f32>,
648) -> (Vec<crate::TA_Real>, crate::TA_Integer) {
649 let mut out: Vec<crate::TA_Real> = Vec::with_capacity(close.len());
650 let mut out_begin: crate::TA_Integer = 0;
651 let mut out_size: crate::TA_Integer = 0;
652 unsafe {
653 crate::TA_Initialize();
654 let ret_code = crate::TA_S_ATR(
655 0, // index of the first close to use
656 close.len() as i32 - 1, // index of the last close to use
657 high.as_ptr(), // pointer to the first element of the high vector
658 low.as_ptr(), // pointer to the first element of the low vector
659 close.as_ptr(), // pointer to the first element of the close vector
660 period as i32, // period of the atr
661 &mut out_begin, // set to index of the first close to have an atr value
662 &mut out_size, // set to number of atr values computed
663 out.as_mut_ptr(), // pointer to the first element of the output vector
664 );
665 match ret_code {
666 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
667 // Rust doesn't know what is the new length of the vector, so we set it manually
668 // to the number of values returned by the TA_ATR call
669 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
670 // An error occured
671 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
672 }
673 crate::TA_Shutdown();
674 }
675
676 (out, out_begin)
677}
678pub fn avgprice() {}
679pub fn s_avgprice() {}
680pub fn avgdev() {}
681pub fn s_avgdev() {}
682///
683/// TA_BBANDS - Bollinger Bands
684///
685/// Input = double
686/// Output = double, double, double
687///
688/// Optional Parameters
689/// -------------------
690/// optInTimePeriod:(From 2 to 100000)
691/// Number of period
692///
693/// optInNbDevUp:(From TA_REAL_MIN to TA_REAL_MAX)
694/// Deviation multiplier for upper band
695///
696/// optInNbDevDn:(From TA_REAL_MIN to TA_REAL_MAX)
697/// Deviation multiplier for lower band
698///
699/// optInMAType:
700/// Type of Moving Average
701///
702/// #Sample
703/// ```
704/// let close_prices: Vec<f64> = vec![
705/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
706/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
707/// 1.086670, 1.086630,
708/// ];
709/// let (outs,_,_, begin) = rust_ta_lib::wrapper::bbands( 10,&close_prices,0.2,0.3,rust_ta_lib::TA_MAType_TA_MAType_SMA);
710/// for (index, value) in outs.iter().enumerate() {
711/// println!("outs index {} = {}", begin + index as i32 + 1, value);
712/// }
713/// ```
714pub fn bbands(
715 period: u32,
716 in_real: &Vec<f64>,
717 in_db_dev_up: f64,
718 in_db_dev_down: f64,
719 in_ma_type: crate::TA_MAType,
720) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
721 let mut upper_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
722 let mut middle_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
723 let mut lower_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
724 let mut out_begin: crate::TA_Integer = 0;
725 let mut out_size: crate::TA_Integer = 0;
726 unsafe {
727 crate::TA_Initialize();
728 let ret_code = crate::TA_BBANDS(
729 0, // index of the first close to use
730 in_real.len() as i32 - 1, // index of the last close to use
731 in_real.as_ptr(), // pointer to the first element of the high vector
732 period as i32, // pointer to the first element of the low vector
733 in_db_dev_up, // pointer to the first element of the close vector
734 in_db_dev_down, // period of the atr
735 in_ma_type,
736 &mut out_begin, // set to index of the first close to have an atr value
737 &mut out_size, // set to number of atr values computed
738 upper_band.as_mut_ptr(), // pointer to the first element of the output vector
739 middle_band.as_mut_ptr(), // pointer to the first element of the output vector
740 lower_band.as_mut_ptr(), // pointer to the first element of the output vector
741 );
742 match ret_code {
743 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
744 // Rust doesn't know what is the new length of the vector, so we set it manually
745 // to the number of values returned by the TA_ATR call
746 crate::TA_RetCode_TA_SUCCESS => {
747 upper_band.set_len(out_size as usize);
748 middle_band.set_len(out_size as usize);
749 lower_band.set_len(out_size as usize);
750 }
751 // An error occured
752 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
753 }
754 crate::TA_Shutdown();
755 }
756
757 (upper_band, middle_band, lower_band, out_begin)
758}
759///
760/// TA_S_BBANDS - Bollinger Bands
761///
762/// Input = double
763/// Output = double, double, double
764///
765/// Optional Parameters
766/// -------------------
767/// optInTimePeriod:(From 2 to 100000)
768/// Number of period
769///
770/// optInNbDevUp:(From TA_REAL_MIN to TA_REAL_MAX)
771/// Deviation multiplier for upper band
772///
773/// optInNbDevDn:(From TA_REAL_MIN to TA_REAL_MAX)
774/// Deviation multiplier for lower band
775///
776/// optInMAType:
777/// Type of Moving Average
778///
779/// #Sample
780/// ```
781/// let close_prices: Vec<f32> = vec![
782/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
783/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
784/// 1.086670, 1.086630,
785/// ];
786/// let (outs,_,_, begin) = rust_ta_lib::wrapper::s_bbands( 10,&close_prices,0.2,0.3,rust_ta_lib::TA_MAType_TA_MAType_SMA);
787/// for (index, value) in outs.iter().enumerate() {
788/// println!("outs index {} = {}", begin + index as i32 + 1, value);
789/// }
790/// ```
791pub fn s_bbands(
792 period: u32,
793 in_real: &Vec<f32>,
794 in_db_dev_up: f64,
795 in_db_dev_down: f64,
796 in_ma_type: crate::TA_MAType,
797) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
798 let mut upper_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
799 let mut middle_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
800 let mut lower_band: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
801 let mut out_begin: crate::TA_Integer = 0;
802 let mut out_size: crate::TA_Integer = 0;
803 unsafe {
804 crate::TA_Initialize();
805 let ret_code = crate::TA_S_BBANDS(
806 0, // index of the first close to use
807 in_real.len() as i32 - 1, // index of the last close to use
808 in_real.as_ptr(), // pointer to the first element of the high vector
809 period as i32, // pointer to the first element of the low vector
810 in_db_dev_up, // pointer to the first element of the close vector
811 in_db_dev_down, // period of the atr
812 in_ma_type,
813 &mut out_begin, // set to index of the first close to have an atr value
814 &mut out_size, // set to number of atr values computed
815 upper_band.as_mut_ptr(), // pointer to the first element of the output vector
816 middle_band.as_mut_ptr(), // pointer to the first element of the output vector
817 lower_band.as_mut_ptr(), // pointer to the first element of the output vector
818 );
819 match ret_code {
820 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
821 // Rust doesn't know what is the new length of the vector, so we set it manually
822 // to the number of values returned by the TA_ATR call
823 crate::TA_RetCode_TA_SUCCESS => {
824 upper_band.set_len(out_size as usize);
825 middle_band.set_len(out_size as usize);
826 lower_band.set_len(out_size as usize);
827 }
828 // An error occured
829 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
830 }
831 crate::TA_Shutdown();
832 }
833
834 (upper_band, middle_band, lower_band, out_begin)
835}
836pub fn beta() {}
837pub fn s_beta() {}
838pub fn bop() {}
839pub fn s_bop() {}
840
841///
842/// TA_CCI - Commodity Channel Index
843///
844/// `Input`: high, low, close, timeperiod
845///
846/// `Output`: (1st, 2nd)
847///
848/// 1st: output vector(f64)
849///
850/// 2nd: the first index of inputs corresponding to an valid output value
851///
852pub fn cci(
853 high: &Vec<f64>,
854 low: &Vec<f64>,
855 close: &Vec<f64>,
856 timeperiod: i32,
857) -> (Vec<f64>, crate::TA_Integer) {
858 let clen = close.len();
859 if clen.ne(&high.len()) || clen.ne(&low.len()) {
860 panic!("The length of input vectors are not equal, please double check the size of each.");
861 }
862
863 let mut out: Vec<f64> = Vec::with_capacity(clen);
864 let mut out_begin: crate::TA_Integer = 0;
865 let mut out_size: crate::TA_Integer = 0;
866
867 unsafe {
868 crate::TA_Initialize();
869 let ret_code = crate::TA_CCI(
870 0, // the first index of the input vector to use
871 clen as i32 - 1, // the last index of the input vector to use
872 high.as_ptr(), // pointer to the high vector
873 low.as_ptr(), // pointer to the low vector
874 close.as_ptr(), // pointer to the close vector
875 timeperiod, // time period
876 &mut out_begin, // set to index of the first close to have an valid output value
877 &mut out_size, // set to number of values computed
878 out.as_mut_ptr(), // pointer to the first element of the output vector
879 );
880
881 match ret_code {
882 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
883 // Rust doesn't know what is the new length of the vector, so we set it manually
884 // to the number of values returned by the TA_ATR call
885 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
886 // An error occured
887 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
888 }
889 crate::TA_Shutdown();
890 }
891
892 (out, out_begin)
893}
894pub fn s_cci() {}
895pub fn cdl2crows() {}
896pub fn s_cdl2crows() {}
897pub fn cdl3blackcrows() {}
898pub fn s_cdl3blackcrows() {}
899pub fn cdl3inside() {}
900pub fn s_cdl3inside() {}
901pub fn cdl3linestrike() {}
902pub fn s_cdl3linestrike() {}
903pub fn cdl3outside() {}
904pub fn s_cdl3outside() {}
905pub fn cdl3starsinsouth() {}
906pub fn s_cdl3starsinsouth() {}
907pub fn cdl3whitesoldiers() {}
908pub fn s_cdl3whitesoldiers() {}
909pub fn cdlabandonedbaby() {}
910pub fn s_cdlabandonedbaby() {}
911pub fn cdladvanceblock() {}
912pub fn s_cdladvanceblock() {}
913pub fn cdlbelthold() {}
914pub fn s_cdlbelthold() {}
915pub fn cdlbreakaway() {}
916pub fn s_cdlbreakaway() {}
917pub fn cdlclosingmarubozu() {}
918pub fn s_cdlclosingmarubozu() {}
919pub fn cdlconcealbabyswall() {}
920pub fn s_cdlconcealbabyswall() {}
921pub fn cdlcounterattack() {}
922pub fn s_cdlcounterattack() {}
923pub fn cdldarkcloudcover() {}
924pub fn s_cdldarkcloudcover() {}
925pub fn cdldoji() {}
926pub fn s_cdldoji() {}
927pub fn cdldojistar() {}
928pub fn s_cdldojistar() {}
929pub fn cdldragonflydoji() {}
930pub fn s_cdldragonflydoji() {}
931pub fn cdlengulfing() {}
932pub fn s_cdlengulfing() {}
933pub fn cdleveningdojistar() {}
934pub fn s_cdleveningdojistar() {}
935pub fn cdleveningstar() {}
936pub fn s_cdleveningstar() {}
937pub fn cdlgapsidesidewhite() {}
938pub fn s_cdlgapsidesidewhite() {}
939pub fn cdlgravestonedoji() {}
940pub fn s_cdlgravestonedoji() {}
941pub fn cdlhammer() {}
942pub fn s_cdlhammer() {}
943pub fn cdlhangingman() {}
944pub fn s_cdlhangingman() {}
945pub fn cdlharami() {}
946pub fn s_cdlharami() {}
947pub fn cdlharamicross() {}
948pub fn s_cdlharamicross() {}
949pub fn cdlhighwave() {}
950pub fn s_cdlhighwave() {}
951pub fn cdlhikkake() {}
952pub fn s_cdlhikkake() {}
953pub fn cdlhikkakemod() {}
954pub fn s_cdlhikkakemod() {}
955pub fn cdlhomingpigeon() {}
956pub fn s_cdlhomingpigeon() {}
957pub fn cdlidentical3crows() {}
958pub fn s_cdlidentical3crows() {}
959pub fn cdlinneck() {}
960pub fn s_cdlinneck() {}
961pub fn cdlinvertedhammer() {}
962pub fn s_cdlinvertedhammer() {}
963pub fn cdlkicking() {}
964pub fn s_cdlkicking() {}
965pub fn cdlkickingbylength() {}
966pub fn s_cdlkickingbylength() {}
967pub fn cdlladderbottom() {}
968pub fn s_cdlladderbottom() {}
969pub fn cdllongleggeddoji() {}
970pub fn s_cdllongleggeddoji() {}
971pub fn cdllongline() {}
972pub fn s_cdllongline() {}
973pub fn cdlmarubozu() {}
974pub fn s_cdlmarubozu() {}
975pub fn cdlmatchinglow() {}
976pub fn s_cdlmatchinglow() {}
977pub fn cdlmathold() {}
978pub fn s_cdlmathold() {}
979pub fn cdlmorningdojistar() {}
980pub fn s_cdlmorningdojistar() {}
981pub fn cdlmorningstar() {}
982pub fn s_cdlmorningstar() {}
983pub fn cdlonneck() {}
984pub fn s_cdlonneck() {}
985pub fn cdlpiercing() {}
986pub fn s_cdlpiercing() {}
987pub fn cdlrickshawman() {}
988pub fn s_cdlrickshawman() {}
989pub fn cdlrisefall3methods() {}
990pub fn s_cdlrisefall3methods() {}
991pub fn cdlseparatinglines() {}
992pub fn s_cdlseparatinglines() {}
993pub fn cdlshootingstar() {}
994pub fn s_cdlshootingstar() {}
995pub fn cdlshortline() {}
996pub fn s_cdlshortline() {}
997pub fn cdlspinningtop() {}
998pub fn s_cdlspinningtop() {}
999pub fn cdlstalledpattern() {}
1000pub fn s_cdlstalledpattern() {}
1001pub fn cdlsticksandwich() {}
1002pub fn s_cdlsticksandwich() {}
1003pub fn cdltakuri() {}
1004pub fn s_cdltakuri() {}
1005pub fn cdltasukigap() {}
1006pub fn s_cdltasukigap() {}
1007pub fn cdlthrusting() {}
1008pub fn s_cdlthrusting() {}
1009pub fn cdltristar() {}
1010pub fn s_cdltristar() {}
1011pub fn cdlunique3river() {}
1012pub fn s_cdlunique3river() {}
1013pub fn cdlupsidegap2crows() {}
1014pub fn s_cdlupsidegap2crows() {}
1015pub fn cdlxsidegap3methods() {}
1016pub fn s_cdlxsidegap3methods() {}
1017pub fn ceil() {}
1018pub fn s_ceil() {}
1019pub fn cmo() {}
1020pub fn s_cmo() {}
1021pub fn correl() {}
1022pub fn s_correl() {}
1023pub fn cos() {}
1024pub fn s_cos() {}
1025pub fn cosh() {}
1026pub fn s_cosh() {}
1027pub fn dema() {}
1028pub fn s_dema() {}
1029pub fn div() {}
1030pub fn s_div() {}
1031pub fn dx() {}
1032pub fn s_dx() {}
1033pub fn ema() {}
1034pub fn s_ema() {}
1035pub fn exp() {}
1036pub fn s_exp() {}
1037pub fn floor() {}
1038pub fn s_floor() {}
1039pub fn ht_dcperiod() {}
1040pub fn s_ht_dcperiod() {}
1041pub fn ht_dcphase() {}
1042pub fn s_ht_dcphase() {}
1043pub fn ht_phasor() {}
1044pub fn s_ht_phasor() {}
1045pub fn ht_sine() {}
1046pub fn s_ht_sine() {}
1047pub fn ht_trendline() {}
1048pub fn s_ht_trendline() {}
1049pub fn ht_trendmode() {}
1050pub fn s_ht_trendmode() {}
1051pub fn imi() {}
1052pub fn s_imi() {}
1053pub fn kama() {}
1054pub fn s_kama() {}
1055pub fn linearreg() {}
1056pub fn s_linearreg() {}
1057pub fn linearreg_angle() {}
1058pub fn s_linearreg_angle() {}
1059pub fn linearreg_intercept() {}
1060pub fn s_linearreg_intercept() {}
1061pub fn linearreg_slope() {}
1062pub fn s_linearreg_slope() {}
1063pub fn ln() {}
1064pub fn s_ln() {}
1065pub fn log10() {}
1066pub fn s_log10() {}
1067///
1068/// TA_MA - Moving average
1069///
1070/// Input = double
1071/// Output = double
1072/// #Sample
1073/// ```
1074/// let close_prices: Vec<f64> = vec![
1075/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1076/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1077/// 1.086670, 1.086630,
1078/// ];
1079/// let (outs, begin) = rust_ta_lib::wrapper::ma(10,rust_ta_lib::TA_MAType_TA_MAType_SMA,&close_prices);
1080/// for (index, value) in outs.iter().enumerate() {
1081/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1082/// }
1083/// ```
1084pub fn ma(
1085 period: u32,
1086 optInMAType: crate::TA_MAType,
1087 close: &Vec<f64>,
1088) -> (Vec<f64>, crate::TA_Integer) {
1089 let mut out: Vec<f64> = Vec::with_capacity(close.len());
1090 let mut out_begin: crate::TA_Integer = 0;
1091 let mut out_size: crate::TA_Integer = 0;
1092
1093 unsafe {
1094 crate::TA_Initialize();
1095
1096 let ret_code = crate::TA_MA(
1097 0, // index of the first close to use
1098 close.len() as i32 - 1, // index of the last close to use
1099 close.as_ptr(), // pointer to the first element of the close vector
1100 period as i32, // period of the ma
1101 optInMAType,
1102 &mut out_begin, // set to index of the first close to have an atr value
1103 &mut out_size, // set to number of atr values computed
1104 out.as_mut_ptr(), // pointer to the first element of the output vector
1105 );
1106
1107 match ret_code {
1108 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1109 // Rust doesn't know what is the new length of the vector, so we set it manually
1110 // to the number of values returned by the TA_ATR call
1111 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1112 // An error occured
1113 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1114 }
1115 crate::TA_Shutdown();
1116 }
1117
1118 (out, out_begin)
1119}
1120
1121///
1122/// TA_S_MA - Moving average
1123///
1124/// Input = float
1125/// Output = double
1126/// #Sample
1127/// ```
1128/// let close_prices: Vec<f32> = vec![
1129/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1130/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1131/// 1.086670, 1.086630,
1132/// ];
1133/// let (outs, begin) = rust_ta_lib::wrapper::s_ma(10,rust_ta_lib::TA_MAType_TA_MAType_SMA,&close_prices);
1134/// for (index, value) in outs.iter().enumerate() {
1135/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1136/// }
1137/// ```
1138pub fn s_ma(
1139 period: u32,
1140 optInMAType: crate::TA_MAType,
1141 close: &Vec<f32>,
1142) -> (Vec<f64>, crate::TA_Integer) {
1143 let mut out: Vec<f64> = Vec::with_capacity(close.len());
1144 let mut out_begin: crate::TA_Integer = 0;
1145 let mut out_size: crate::TA_Integer = 0;
1146
1147 unsafe {
1148 crate::TA_Initialize();
1149
1150 let ret_code = crate::TA_S_MA(
1151 0, // index of the first close to use
1152 close.len() as i32 - 1, // index of the last close to use
1153 close.as_ptr(), // pointer to the first element of the close vector
1154 period as i32, // period of the ma
1155 optInMAType,
1156 &mut out_begin, // set to index of the first close to have an atr value
1157 &mut out_size, // set to number of atr values computed
1158 out.as_mut_ptr(), // pointer to the first element of the output vector
1159 );
1160
1161 match ret_code {
1162 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1163 // Rust doesn't know what is the new length of the vector, so we set it manually
1164 // to the number of values returned by the TA_ATR call
1165 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1166 // An error occured
1167 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1168 }
1169 crate::TA_Shutdown();
1170 }
1171
1172 (out, out_begin)
1173}
1174///
1175/// TA_MACD - Moving Average Convergence/Divergence
1176///
1177/// Input = double
1178/// Output = double, double, double
1179///
1180/// Optional Parameters
1181/// -------------------
1182/// optInFastPeriod:(From 2 to 100000)
1183/// Number of period for the fast MA
1184///
1185/// optInSlowPeriod:(From 2 to 100000)
1186/// Number of period for the slow MA
1187///
1188/// optInSignalPeriod:(From 1 to 100000)
1189/// Smoothing for the signal line (nb of period)
1190///
1191///
1192/// #Sample
1193/// ```
1194/// let close_prices: Vec<f64> = vec![
1195/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1196/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1197/// 1.086670, 1.086630,
1198/// ];
1199/// let (macd,macd_signal,macd_hist, begin) = rust_ta_lib::wrapper::macd(2,5,10,&close_prices);
1200/// for (index, value) in macd.iter().enumerate() {
1201/// println!("macd index {} = {}", begin + index as i32 + 1, value);
1202/// println!("macd_signal index {} = {:?}", begin + index as i32 + 1, macd_signal.get(index));
1203/// println!("macd_hist index {} = {:?}", begin + index as i32 + 1, macd_hist.get(index));
1204/// }
1205/// ```
1206pub fn macd(
1207 fast_period: u32,
1208 slow_period: u32,
1209 signal_period: u32,
1210 close: &Vec<f64>,
1211) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
1212 let mut macd: Vec<f64> = Vec::with_capacity(close.len());
1213 let mut macd_signal: Vec<f64> = Vec::with_capacity(close.len());
1214 let mut macd_hist: Vec<f64> = Vec::with_capacity(close.len());
1215 let mut out_begin: crate::TA_Integer = 0;
1216 let mut out_size: crate::TA_Integer = 0;
1217
1218 unsafe {
1219 crate::TA_Initialize();
1220
1221 let ret_code = crate::TA_MACD(
1222 0, // index of the first close to use
1223 close.len() as i32 - 1, // index of the last close to use
1224 close.as_ptr(), // pointer to the first element of the close vector
1225 fast_period as i32, // period of the ma
1226 slow_period as i32,
1227 signal_period as i32,
1228 &mut out_begin, // set to index of the first close to have an atr value
1229 &mut out_size, // set to number of atr values computed
1230 macd.as_mut_ptr(), // pointer to the first element of the output vector
1231 macd_signal.as_mut_ptr(), // pointer to the first element of the output vector
1232 macd_hist.as_mut_ptr(), // pointer to the first element of the output vector
1233 );
1234
1235 match ret_code {
1236 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1237 // Rust doesn't know what is the new length of the vector, so we set it manually
1238 // to the number of values returned by the TA_ATR call
1239 crate::TA_RetCode_TA_SUCCESS => {
1240 macd.set_len(out_size as usize);
1241 macd_signal.set_len(out_size as usize);
1242 macd_hist.set_len(out_size as usize)
1243 }
1244 // An error occured
1245 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1246 }
1247 crate::TA_Shutdown();
1248 }
1249
1250 (macd, macd_signal, macd_hist, out_begin)
1251}
1252///
1253/// TA_MACD - Moving Average Convergence/Divergence
1254///
1255/// Input = double
1256/// Output = double, double, double
1257///
1258/// Optional Parameters
1259/// -------------------
1260/// optInFastPeriod:(From 2 to 100000)
1261/// Number of period for the fast MA
1262///
1263/// optInSlowPeriod:(From 2 to 100000)
1264/// Number of period for the slow MA
1265///
1266/// optInSignalPeriod:(From 1 to 100000)
1267/// Smoothing for the signal line (nb of period)
1268///
1269///
1270/// #Sample
1271/// ```
1272/// let close_prices: Vec<f32> = vec![
1273/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1274/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1275/// 1.086670, 1.086630,
1276/// ];
1277/// let (macd,macd_signal,macd_hist, begin) = rust_ta_lib::wrapper::s_macd(2,5,10,&close_prices);
1278/// for (index, value) in macd.iter().enumerate() {
1279/// println!("macd index {} = {}", begin + index as i32 + 1, value);
1280/// println!("macd_signal index {} = {:?}", begin + index as i32 + 1, macd_signal.get(index));
1281/// println!("macd_hist index {} = {:?}", begin + index as i32 + 1, macd_hist.get(index));
1282/// }
1283/// ```
1284pub fn s_macd(
1285 fast_period: u32,
1286 slow_period: u32,
1287 signal_period: u32,
1288 close: &Vec<f32>,
1289) -> (Vec<f64>, Vec<f64>, Vec<f64>, crate::TA_Integer) {
1290 let mut macd: Vec<f64> = Vec::with_capacity(close.len());
1291 let mut macd_signal: Vec<f64> = Vec::with_capacity(close.len());
1292 let mut macd_hist: Vec<f64> = Vec::with_capacity(close.len());
1293 let mut out_begin: crate::TA_Integer = 0;
1294 let mut out_size: crate::TA_Integer = 0;
1295
1296 unsafe {
1297 crate::TA_Initialize();
1298
1299 let ret_code = crate::TA_S_MACD(
1300 0, // index of the first close to use
1301 close.len() as i32 - 1, // index of the last close to use
1302 close.as_ptr(), // pointer to the first element of the close vector
1303 fast_period as i32, // period of the ma
1304 slow_period as i32,
1305 signal_period as i32,
1306 &mut out_begin, // set to index of the first close to have an atr value
1307 &mut out_size, // set to number of atr values computed
1308 macd.as_mut_ptr(), // pointer to the first element of the output vector
1309 macd_signal.as_mut_ptr(), // pointer to the first element of the output vector
1310 macd_hist.as_mut_ptr(), // pointer to the first element of the output vector
1311 );
1312
1313 match ret_code {
1314 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1315 // Rust doesn't know what is the new length of the vector, so we set it manually
1316 // to the number of values returned by the TA_ATR call
1317 crate::TA_RetCode_TA_SUCCESS => {
1318 macd.set_len(out_size as usize);
1319 macd_signal.set_len(out_size as usize);
1320 macd_hist.set_len(out_size as usize)
1321 }
1322 // An error occured
1323 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1324 }
1325 crate::TA_Shutdown();
1326 }
1327
1328 (macd, macd_signal, macd_hist, out_begin)
1329}
1330pub fn macdext() {}
1331pub fn s_macdext() {}
1332pub fn macdfix() {}
1333pub fn s_macdfix() {}
1334///
1335/// TA_MAMA - MESA Adaptive Moving Average
1336///
1337/// Input = double
1338/// Output = double, double
1339///
1340/// Optional Parameters
1341/// -------------------
1342/// optInFastLimit:(From 0.01 to 0.99)
1343/// Upper limit use in the adaptive algorithm
1344///
1345/// optInSlowLimit:(From 0.01 to 0.99)
1346/// Lower limit use in the adaptive algorithm
1347///
1348/// #Sample
1349/// ```
1350/// let close_prices: Vec<f64> = vec![
1351/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1352/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1353/// 1.086670, 1.086630,
1354/// ];
1355/// let (outs,_, begin) = rust_ta_lib::wrapper::mama( &close_prices,0.2,0.3);
1356/// for (index, value) in outs.iter().enumerate() {
1357/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1358/// }
1359/// ```
1360pub fn mama(
1361 in_real: &Vec<f64>,
1362 in_fast_limit: f64,
1363 in_flow_limit: f64,
1364) -> (Vec<f64>, Vec<f64>, crate::TA_Integer) {
1365 let mut mama: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
1366 let mut fama: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
1367 let mut out_begin: crate::TA_Integer = 0;
1368 let mut out_size: crate::TA_Integer = 0;
1369 unsafe {
1370 crate::TA_Initialize();
1371 let ret_code = crate::TA_MAMA(
1372 0, // index of the first close to use
1373 in_real.len() as i32 - 1, // index of the last close to use
1374 in_real.as_ptr(), // pointer to the first element of the high vector
1375 in_fast_limit, // pointer to the first element of the close vector
1376 in_flow_limit, // period of the atr
1377 &mut out_begin, // set to index of the first close to have an atr value
1378 &mut out_size, // set to number of atr values computed
1379 mama.as_mut_ptr(), // pointer to the first element of the output vector
1380 fama.as_mut_ptr(), // pointer to the first element of the output vector
1381 );
1382 match ret_code {
1383 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1384 // Rust doesn't know what is the new length of the vector, so we set it manually
1385 // to the number of values returned by the TA_ATR call
1386 crate::TA_RetCode_TA_SUCCESS => {
1387 mama.set_len(out_size as usize);
1388 fama.set_len(out_size as usize);
1389 }
1390 // An error occured
1391 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1392 }
1393 crate::TA_Shutdown();
1394 }
1395
1396 (mama, fama, out_begin)
1397}
1398///
1399/// TA_S_MAMA - MESA Adaptive Moving Average
1400///
1401/// Input = double
1402/// Output = double, double
1403///
1404/// Optional Parameters
1405/// -------------------
1406/// optInFastLimit:(From 0.01 to 0.99)
1407/// Upper limit use in the adaptive algorithm
1408///
1409/// optInSlowLimit:(From 0.01 to 0.99)
1410/// Lower limit use in the adaptive algorithm
1411///
1412/// #Sample
1413/// ```
1414/// let close_prices: Vec<f32> = vec![
1415/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1416/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1417/// 1.086670, 1.086630,
1418/// ];
1419/// let (outs,_, begin) = rust_ta_lib::wrapper::s_mama( &close_prices,0.2,0.3);
1420/// for (index, value) in outs.iter().enumerate() {
1421/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1422/// }
1423/// ```
1424pub fn s_mama(
1425 in_real: &Vec<f32>,
1426 in_fast_limit: f64,
1427 in_flow_limit: f64,
1428) -> (Vec<f64>, Vec<f64>, crate::TA_Integer) {
1429 let mut mama: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
1430 let mut fama: Vec<crate::TA_Real> = Vec::with_capacity(in_real.len());
1431 let mut out_begin: crate::TA_Integer = 0;
1432 let mut out_size: crate::TA_Integer = 0;
1433 unsafe {
1434 crate::TA_Initialize();
1435 let ret_code = crate::TA_S_MAMA(
1436 0, // index of the first close to use
1437 in_real.len() as i32 - 1, // index of the last close to use
1438 in_real.as_ptr(), // pointer to the first element of the high vector
1439 in_fast_limit, // pointer to the first element of the close vector
1440 in_flow_limit, // period of the atr
1441 &mut out_begin, // set to index of the first close to have an atr value
1442 &mut out_size, // set to number of atr values computed
1443 mama.as_mut_ptr(), // pointer to the first element of the output vector
1444 fama.as_mut_ptr(), // pointer to the first element of the output vector
1445 );
1446 match ret_code {
1447 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1448 // Rust doesn't know what is the new length of the vector, so we set it manually
1449 // to the number of values returned by the TA_ATR call
1450 crate::TA_RetCode_TA_SUCCESS => {
1451 mama.set_len(out_size as usize);
1452 fama.set_len(out_size as usize);
1453 }
1454 // An error occured
1455 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1456 }
1457 crate::TA_Shutdown();
1458 }
1459
1460 (mama, fama, out_begin)
1461}
1462pub fn mavp() {}
1463pub fn s_mavp() {}
1464pub fn max() {}
1465pub fn s_max() {}
1466pub fn maxindex() {}
1467pub fn s_maxindex() {}
1468pub fn medprice() {}
1469pub fn s_medprice() {}
1470
1471///
1472/// TA_MFI - Money Flow Index
1473///
1474/// `Input`: high, low, close, volume, timeperiod
1475///
1476/// `Output`: (1st, 2nd)
1477///
1478/// 1st: output vector(f64)
1479///
1480/// 2nd: the first index of inputs corresponding to an valid output value
1481///
1482pub fn mfi(
1483 high: &Vec<f64>,
1484 low: &Vec<f64>,
1485 close: &Vec<f64>,
1486 volume: &Vec<f64>,
1487 timeperiod: i32,
1488) -> (Vec<f64>, crate::TA_Integer) {
1489 let clen = close.len();
1490 if clen.ne(&high.len()) || clen.ne(&low.len()) || clen.ne(&volume.len()) {
1491 panic!("The length of input vectors are not equal, please double check the size of each.");
1492 }
1493
1494 let mut out: Vec<f64> = Vec::with_capacity(clen);
1495 let mut out_begin: crate::TA_Integer = 0;
1496 let mut out_size: crate::TA_Integer = 0;
1497
1498 unsafe {
1499 crate::TA_Initialize();
1500 let ret_code = crate::TA_MFI(
1501 0, // the first index of the input vector to use
1502 clen as i32 - 1, // the last index of the input vector to use
1503 high.as_ptr(), // pointer to the high vector
1504 low.as_ptr(), // pointer to the low vector
1505 close.as_ptr(), // pointer to the close vector
1506 volume.as_ptr(), // pointer to the volume vector
1507 timeperiod, // time period
1508 &mut out_begin, // set to index of the first close to have an valid output value
1509 &mut out_size, // set to number of values computed
1510 out.as_mut_ptr(), // pointer to the first element of the output vector
1511 );
1512
1513 match ret_code {
1514 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1515 // Rust doesn't know what is the new length of the vector, so we set it manually
1516 // to the number of values returned by the TA_ATR call
1517 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1518 // An error occured
1519 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1520 }
1521 crate::TA_Shutdown();
1522 }
1523
1524 (out, out_begin)
1525}
1526pub fn s_mfi() {}
1527pub fn midpoint() {}
1528pub fn s_midpoint() {}
1529pub fn midprice() {}
1530pub fn s_midprice() {}
1531pub fn min() {}
1532pub fn s_min() {}
1533pub fn minindex() {}
1534pub fn s_minindex() {}
1535pub fn minmax() {}
1536pub fn s_minmax() {}
1537pub fn minmaxindex() {}
1538pub fn s_minmaxindex() {}
1539pub fn minus_di() {}
1540pub fn s_minus_di() {}
1541
1542///
1543/// TA_MINUS_DM - Minus Directional Movement
1544///
1545/// Input = High, Low
1546/// Output = double
1547///
1548/// Optional Parameters
1549/// -------------------
1550/// optInTimePeriod:(From 1 to 100000)
1551/// Number of period
1552///
1553/// #Sample
1554/// ```
1555/// let close_prices: Vec<f64> = vec![
1556/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1557/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1558/// 1.086670, 1.086630,
1559/// ];
1560/// let high_prices = close_prices.clone();
1561/// let low_prices = close_prices.clone();
1562/// let (outs, begin) = rust_ta_lib::wrapper::minus_dm( 10,&high_prices,&low_prices);
1563/// for (index, value) in outs.iter().enumerate() {
1564/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1565/// }
1566/// ```
1567pub fn minus_dm(period: u32, high: &Vec<f64>, low: &Vec<f64>) -> (Vec<f64>, crate::TA_Integer) {
1568 let mut out: Vec<f64> = Vec::with_capacity(high.len());
1569 let mut out_begin: crate::TA_Integer = 0;
1570 let mut out_size: crate::TA_Integer = 0;
1571
1572 unsafe {
1573 crate::TA_Initialize();
1574 let ret_code = crate::TA_MINUS_DM(
1575 0, // index of the first close to use
1576 high.len() as i32 - 1, // index of the last close to use
1577 high.as_ptr(), // pointer to the first element of the high vector
1578 low.as_ptr(), // pointer to the first element of the low vector
1579 period as i32, // pointer to the first element of the close vector
1580 &mut out_begin, // set to index of the first close to have an atr value
1581 &mut out_size, // set to number of atr values computed
1582 out.as_mut_ptr(), // pointer to the first element of the output vector
1583 );
1584
1585 match ret_code {
1586 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1587 // Rust doesn't know what is the new length of the vector, so we set it manually
1588 // to the number of values returned by the TA_ATR call
1589 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1590 // An error occured
1591 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1592 }
1593 crate::TA_Shutdown();
1594 }
1595
1596 (out, out_begin)
1597}
1598///
1599/// TA_S_MINUS_DM - Minus Directional Movement
1600///
1601/// Input = High, Low
1602/// Output = double
1603///
1604/// Optional Parameters
1605/// -------------------
1606/// optInTimePeriod:(From 1 to 100000)
1607/// Number of period
1608///
1609/// #Sample
1610/// ```
1611/// let close_prices: Vec<f32> = vec![
1612/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1613/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1614/// 1.086670, 1.086630,
1615/// ];
1616/// let high_prices = close_prices.clone();
1617/// let low_prices = close_prices.clone();
1618/// let (outs, begin) = rust_ta_lib::wrapper::s_minus_dm( 10,&high_prices,&low_prices);
1619/// for (index, value) in outs.iter().enumerate() {
1620/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1621/// }
1622/// ```
1623pub fn s_minus_dm(period: u32, high: &Vec<f32>, low: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
1624 let mut out: Vec<f64> = Vec::with_capacity(high.len());
1625 let mut out_begin: crate::TA_Integer = 0;
1626 let mut out_size: crate::TA_Integer = 0;
1627
1628 unsafe {
1629 crate::TA_Initialize();
1630 let ret_code = crate::TA_S_MINUS_DM(
1631 0, // index of the first close to use
1632 high.len() as i32 - 1, // index of the last close to use
1633 high.as_ptr(), // pointer to the first element of the high vector
1634 low.as_ptr(), // pointer to the first element of the low vector
1635 period as i32, // pointer to the first element of the close vector
1636 &mut out_begin, // set to index of the first close to have an atr value
1637 &mut out_size, // set to number of atr values computed
1638 out.as_mut_ptr(), // pointer to the first element of the output vector
1639 );
1640
1641 match ret_code {
1642 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1643 // Rust doesn't know what is the new length of the vector, so we set it manually
1644 // to the number of values returned by the TA_ATR call
1645 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1646 // An error occured
1647 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1648 }
1649 crate::TA_Shutdown();
1650 }
1651
1652 (out, out_begin)
1653}
1654pub fn mom() {}
1655pub fn s_mom() {}
1656pub fn mult() {}
1657pub fn s_mult() {}
1658
1659///
1660/// TA_NATR - Normalized Average True Range
1661///
1662/// `Input`: high, low, close, timeperiod
1663///
1664/// `Output`: (1st, 2nd)
1665///
1666/// 1st: output vector(f64)
1667///
1668/// 2nd: the first index of inputs corresponding to an valid output value
1669///
1670pub fn natr(
1671 high: &Vec<f64>,
1672 low: &Vec<f64>,
1673 close: &Vec<f64>,
1674 timeperiod: i32,
1675) -> (Vec<f64>, crate::TA_Integer) {
1676 let clen = close.len();
1677 if clen.ne(&high.len()) || clen.ne(&low.len()) {
1678 panic!("The length of input vectors are not equal, please double check the size of each.");
1679 }
1680
1681 let mut out: Vec<f64> = Vec::with_capacity(clen);
1682 let mut out_begin: crate::TA_Integer = 0;
1683 let mut out_size: crate::TA_Integer = 0;
1684
1685 unsafe {
1686 crate::TA_Initialize();
1687 let ret_code = crate::TA_NATR(
1688 0, // the first index of the input vector to use
1689 clen as i32 - 1, // the last index of the input vector to use
1690 high.as_ptr(), // pointer to the high vector
1691 low.as_ptr(), // pointer to the low vector
1692 close.as_ptr(), // pointer to the close vector
1693 timeperiod, // time period
1694 &mut out_begin, // set to index of the first close to have an valid output value
1695 &mut out_size, // set to number of values computed
1696 out.as_mut_ptr(), // pointer to the first element of the output vector
1697 );
1698
1699 match ret_code {
1700 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1701 // Rust doesn't know what is the new length of the vector, so we set it manually
1702 // to the number of values returned by the TA_ATR call
1703 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1704 // An error occured
1705 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1706 }
1707 crate::TA_Shutdown();
1708 }
1709
1710 (out, out_begin)
1711}
1712pub fn s_natr() {}
1713///
1714/// TA_COS - On Balance Volums
1715///
1716/// Input = double
1717/// Output = double
1718/// #Sample
1719/// ```
1720/// let close_prices: Vec<f64> = vec![
1721/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1722/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1723/// 1.086670, 1.086630,
1724/// ];
1725/// let volumes = close_prices.clone();
1726/// let (outs, begin) = rust_ta_lib::wrapper::obv(&close_prices,&volumes);
1727/// for (index, value) in outs.iter().enumerate() {
1728/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1729/// }
1730/// ```
1731pub fn obv(close: &Vec<f64>, volume: &Vec<f64>) -> (Vec<f64>, crate::TA_Integer) {
1732 let mut out: Vec<f64> = Vec::with_capacity(close.len());
1733 let mut out_begin: crate::TA_Integer = 0;
1734 let mut out_size: crate::TA_Integer = 0;
1735
1736 unsafe {
1737 crate::TA_Initialize();
1738
1739 let ret_code = crate::TA_OBV(
1740 0, // index of the first close to use
1741 close.len() as i32 - 1, // index of the last close to use
1742 close.as_ptr(), // pointer to the first element of the close vector
1743 volume.as_ptr(),
1744 &mut out_begin, // set to index of the first close to have an atr value
1745 &mut out_size, // set to number of atr values computed
1746 out.as_mut_ptr(), // pointer to the first element of the output vector
1747 );
1748
1749 match ret_code {
1750 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1751 // Rust doesn't know what is the new length of the vector, so we set it manually
1752 // to the number of values returned by the TA_ATR call
1753 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1754 // An error occured
1755 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1756 }
1757 crate::TA_Shutdown();
1758 }
1759
1760 (out, out_begin)
1761}
1762///
1763/// TA_S_COS - On Balance Volume
1764///
1765/// Input = double
1766/// Output = double
1767/// #Sample
1768/// ```
1769/// let close_prices: Vec<f32> = vec![
1770/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1771/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1772/// 1.086670, 1.086630,
1773/// ];
1774/// let volumes = close_prices.clone();
1775/// let (outs, begin) = rust_ta_lib::wrapper::s_obv(&close_prices,&volumes);
1776/// for (index, value) in outs.iter().enumerate() {
1777/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1778/// }
1779/// ```
1780pub fn s_obv(close: &Vec<f32>, volume: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
1781 let mut out: Vec<f64> = Vec::with_capacity(close.len());
1782 let mut out_begin: crate::TA_Integer = 0;
1783 let mut out_size: crate::TA_Integer = 0;
1784
1785 unsafe {
1786 crate::TA_Initialize();
1787
1788 let ret_code = crate::TA_S_OBV(
1789 0, // index of the first close to use
1790 close.len() as i32 - 1, // index of the last close to use
1791 close.as_ptr(), // pointer to the first element of the close vector
1792 volume.as_ptr(),
1793 &mut out_begin, // set to index of the first close to have an atr value
1794 &mut out_size, // set to number of atr values computed
1795 out.as_mut_ptr(), // pointer to the first element of the output vector
1796 );
1797
1798 match ret_code {
1799 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1800 // Rust doesn't know what is the new length of the vector, so we set it manually
1801 // to the number of values returned by the TA_ATR call
1802 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1803 // An error occured
1804 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1805 }
1806 crate::TA_Shutdown();
1807 }
1808
1809 (out, out_begin)
1810}
1811pub fn plus_di() {}
1812pub fn s_plus_di() {}
1813///
1814/// TA_PLUS_DM - Plus Directional Movement
1815///
1816/// Input = High, Low
1817/// Output = double
1818///
1819/// Optional Parameters
1820/// -------------------
1821/// optInTimePeriod:(From 1 to 100000)
1822/// Number of period
1823///
1824/// #Sample
1825/// ```
1826/// let close_prices: Vec<f64> = vec![
1827/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1828/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1829/// 1.086670, 1.086630,
1830/// ];
1831/// let high_prices = close_prices.clone();
1832/// let low_prices = close_prices.clone();
1833/// let (outs, begin) = rust_ta_lib::wrapper::plus_dm( 10,&high_prices,&low_prices);
1834/// for (index, value) in outs.iter().enumerate() {
1835/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1836/// }
1837/// ```
1838pub fn plus_dm(period: u32, high: &Vec<f64>, low: &Vec<f64>) -> (Vec<f64>, crate::TA_Integer) {
1839 let mut out: Vec<f64> = Vec::with_capacity(high.len());
1840 let mut out_begin: crate::TA_Integer = 0;
1841 let mut out_size: crate::TA_Integer = 0;
1842
1843 unsafe {
1844 crate::TA_Initialize();
1845 let ret_code = crate::TA_PLUS_DM(
1846 0, // index of the first close to use
1847 high.len() as i32 - 1, // index of the last close to use
1848 high.as_ptr(), // pointer to the first element of the high vector
1849 low.as_ptr(), // pointer to the first element of the low vector
1850 period as i32, // pointer to the first element of the close vector
1851 &mut out_begin, // set to index of the first close to have an atr value
1852 &mut out_size, // set to number of atr values computed
1853 out.as_mut_ptr(), // pointer to the first element of the output vector
1854 );
1855
1856 match ret_code {
1857 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1858 // Rust doesn't know what is the new length of the vector, so we set it manually
1859 // to the number of values returned by the TA_ATR call
1860 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1861 // An error occured
1862 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1863 }
1864 crate::TA_Shutdown();
1865 }
1866
1867 (out, out_begin)
1868}
1869///
1870/// TA_S_PLUS_DM - Plus Directional Movement
1871///
1872/// Input = High, Low
1873/// Output = double
1874///
1875/// Optional Parameters
1876/// -------------------
1877/// optInTimePeriod:(From 1 to 100000)
1878/// Number of period
1879///
1880/// #Sample
1881/// ```
1882/// let close_prices: Vec<f32> = vec![
1883/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1884/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1885/// 1.086670, 1.086630,
1886/// ];
1887/// let high_prices = close_prices.clone();
1888/// let low_prices = close_prices.clone();
1889/// let (outs, begin) = rust_ta_lib::wrapper::s_plus_dm( 10,&high_prices,&low_prices);
1890/// for (index, value) in outs.iter().enumerate() {
1891/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1892/// }
1893/// ```
1894pub fn s_plus_dm(period: u32, high: &Vec<f32>, low: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
1895 let mut out: Vec<f64> = Vec::with_capacity(high.len());
1896 let mut out_begin: crate::TA_Integer = 0;
1897 let mut out_size: crate::TA_Integer = 0;
1898
1899 unsafe {
1900 crate::TA_Initialize();
1901 let ret_code = crate::TA_S_PLUS_DM(
1902 0, // index of the first close to use
1903 high.len() as i32 - 1, // index of the last close to use
1904 high.as_ptr(), // pointer to the first element of the high vector
1905 low.as_ptr(), // pointer to the first element of the low vector
1906 period as i32, // pointer to the first element of the close vector
1907 &mut out_begin, // set to index of the first close to have an atr value
1908 &mut out_size, // set to number of atr values computed
1909 out.as_mut_ptr(), // pointer to the first element of the output vector
1910 );
1911
1912 match ret_code {
1913 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1914 // Rust doesn't know what is the new length of the vector, so we set it manually
1915 // to the number of values returned by the TA_ATR call
1916 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1917 // An error occured
1918 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1919 }
1920 crate::TA_Shutdown();
1921 }
1922
1923 (out, out_begin)
1924}
1925///
1926/// TA_PPO - Percentage Price Oscillator
1927///
1928/// `Input` = close, fastperiod(12), slowperiod(26), matype
1929///
1930/// `Output`: (1st, 2nd)
1931///
1932/// 1st: output vector(f64)
1933///
1934/// 2nd: the first index of inputs corresponding to an valid output value
1935///
1936pub fn ppo(
1937 close: &Vec<f64>,
1938 fastperiod: i32,
1939 slowperiod: i32,
1940 matype: crate::TA_MAType,
1941) -> (Vec<f64>, crate::TA_Integer) {
1942 let mut out: Vec<f64> = Vec::with_capacity(close.len());
1943 let mut out_begin: crate::TA_Integer = 0;
1944 let mut out_size: crate::TA_Integer = 0;
1945
1946 unsafe {
1947 crate::TA_Initialize();
1948 let ret_code = crate::TA_PPO(
1949 0, // index of the first close to use
1950 close.len() as i32 - 1, // index of the last close to use
1951 close.as_ptr(), // pointer to the first element of the close vector
1952 fastperiod, // fast period (suggest default 12)
1953 slowperiod, // slow period (suggest default 26)
1954 matype, // MA Type
1955 &mut out_begin, // set to index of the first close to have an valid output value
1956 &mut out_size, // set to number of values computed
1957 out.as_mut_ptr(), // pointer to the first element of the output vector
1958 );
1959
1960 match ret_code {
1961 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
1962 // Rust doesn't know what is the new length of the vector, so we set it manually
1963 // to the number of values returned by the TA_ATR call
1964 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
1965 // An error occured
1966 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
1967 }
1968 crate::TA_Shutdown();
1969 }
1970
1971 (out, out_begin)
1972}
1973pub fn s_ppo() {}
1974pub fn roc() {}
1975pub fn s_roc() {}
1976pub fn rocp() {}
1977pub fn s_rocp() {}
1978pub fn rocr() {}
1979pub fn s_rocr() {}
1980pub fn rocr100() {}
1981pub fn s_rocr100() {}
1982///
1983/// TA_RSI - Relative Strength Index
1984///
1985/// Input = double
1986/// Output = double
1987/// #Sample
1988/// ```
1989/// let close_prices: Vec<f64> = vec![
1990/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
1991/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
1992/// 1.086670, 1.086630,
1993/// ];
1994/// let (outs, begin) = rust_ta_lib::wrapper::rsi(10,&close_prices);
1995/// for (index, value) in outs.iter().enumerate() {
1996/// println!("outs index {} = {}", begin + index as i32 + 1, value);
1997/// }
1998/// ```
1999pub fn rsi(
2000 period: u32,
2001 close_prices: &Vec<crate::TA_Real>,
2002) -> (Vec<crate::TA_Real>, crate::TA_Integer) {
2003 let mut out: Vec<crate::TA_Real> = Vec::with_capacity(close_prices.len());
2004 let mut out_begin: crate::TA_Integer = 0;
2005 let mut out_size: crate::TA_Integer = 0;
2006 unsafe {
2007 crate::TA_Initialize();
2008 let ret_code = crate::TA_RSI(
2009 0, // index of the first close to use
2010 close_prices.len() as i32 - 1, // index of the last close to use
2011 close_prices.as_ptr(), // pointer to the first element of the vector
2012 period as i32, // period of the rsi
2013 &mut out_begin, // set to index of the first close to have an rsi value
2014 &mut out_size, // set to number of sma values computed
2015 out.as_mut_ptr(), // pointer to the first element of the output vector
2016 );
2017 match ret_code {
2018 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2019 // Rust doesn't know what is the new length of the vector, so we set it manually
2020 // to the number of values returned by the TA_RSI call
2021 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2022 // An error occured
2023 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2024 }
2025 crate::TA_Shutdown();
2026 }
2027
2028 (out, out_begin)
2029}
2030///
2031/// TA_S_RSI - Relative Strength Index
2032///
2033/// Input = float
2034/// Output = double
2035/// #Sample
2036/// ```
2037/// let close_prices: Vec<f32> = vec![
2038/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2039/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2040/// 1.086670, 1.086630,
2041/// ];
2042/// let (outs, begin) = rust_ta_lib::wrapper::s_rsi(10,&close_prices);
2043/// for (index, value) in outs.iter().enumerate() {
2044/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2045/// }
2046/// ```
2047pub fn s_rsi(period: u32, close_prices: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
2048 let mut out: Vec<f64> = Vec::with_capacity(close_prices.len());
2049 let mut out_begin: crate::TA_Integer = 0;
2050 let mut out_size: crate::TA_Integer = 0;
2051 unsafe {
2052 crate::TA_Initialize();
2053 let ret_code = crate::TA_S_RSI(
2054 0, // index of the first close to use
2055 close_prices.len() as i32 - 1, // index of the last close to use
2056 close_prices.as_ptr(), // pointer to the first element of the vector
2057 period as i32, // period of the rsi
2058 &mut out_begin, // set to index of the first close to have an rsi value
2059 &mut out_size, // set to number of sma values computed
2060 out.as_mut_ptr(), // pointer to the first element of the output vector
2061 );
2062 match ret_code {
2063 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2064 // Rust doesn't know what is the new length of the vector, so we set it manually
2065 // to the number of values returned by the TA_RSI call
2066 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2067 // An error occured
2068 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2069 }
2070 crate::TA_Shutdown();
2071 }
2072
2073 (out, out_begin)
2074}
2075pub fn sar() {}
2076pub fn s_sar() {}
2077pub fn sarext() {}
2078pub fn s_sarext() {}
2079pub fn sin() {}
2080pub fn s_sin() {}
2081pub fn sinh() {}
2082pub fn s_sinh() {}
2083///
2084/// TA_SMA - Simple Moving Average
2085///
2086/// Input = double
2087/// Output = double
2088/// #Sample
2089/// ```
2090/// let inReal: Vec<f64> = vec![
2091/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2092/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2093/// 1.086670, 1.086630,
2094/// ];
2095/// let (outReal, begin) = rust_ta_lib::wrapper::sma( 10,&inReal);
2096/// for (index, value) in outReal.iter().enumerate() {
2097/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2098/// }
2099/// ```
2100pub fn sma(
2101 period: u32,
2102 close_prices: &Vec<crate::TA_Real>,
2103) -> (Vec<crate::TA_Real>, crate::TA_Integer) {
2104 let mut out: Vec<crate::TA_Real> = Vec::with_capacity(close_prices.len());
2105 let mut out_begin: crate::TA_Integer = 0;
2106 let mut out_size: crate::TA_Integer = 0;
2107 unsafe {
2108 crate::TA_Initialize();
2109 let ret_code = crate::TA_MA(
2110 0, // index of the first close to use
2111 close_prices.len() as i32 - 1, // index of the last close to use
2112 close_prices.as_ptr(), // pointer to the first element of the vector
2113 period as i32, // period of the sma
2114 crate::TA_MAType_TA_MAType_SMA, // type of the MA, here forced to sma
2115 &mut out_begin, // set to index of the first close to have an sma value
2116 &mut out_size, // set to number of sma values computed
2117 out.as_mut_ptr(), // pointer to the first element of the output vector
2118 );
2119 match ret_code {
2120 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2121 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2122 }
2123 crate::TA_Shutdown();
2124 }
2125
2126 (out, out_begin)
2127}
2128
2129///
2130/// TA_S_SMA - Simple Moving Average
2131///
2132/// Input = float
2133/// Output = double
2134/// #Sample
2135/// ```
2136/// let inReal: Vec<f32> = vec![
2137/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2138/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2139/// 1.086670, 1.086630,
2140/// ];
2141/// let (outReal, begin) = rust_ta_lib::wrapper::s_sma( 10,&inReal);
2142/// for (index, value) in outReal.iter().enumerate() {
2143/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2144/// }
2145/// ```
2146pub fn s_sma(period: u32, close_prices: &Vec<f32>) -> (Vec<crate::TA_Real>, crate::TA_Integer) {
2147 let mut out: Vec<crate::TA_Real> = Vec::with_capacity(close_prices.len());
2148 let mut out_begin: crate::TA_Integer = 0;
2149 let mut out_size: crate::TA_Integer = 0;
2150 unsafe {
2151 crate::TA_Initialize();
2152 let ret_code = crate::TA_S_MA(
2153 0, // index of the first close to use
2154 close_prices.len() as i32 - 1, // index of the last close to use
2155 close_prices.as_ptr(), // pointer to the first element of the vector
2156 period as i32, // period of the sma
2157 crate::TA_MAType_TA_MAType_SMA, // type of the MA, here forced to sma
2158 &mut out_begin, // set to index of the first close to have an sma value
2159 &mut out_size, // set to number of sma values computed
2160 out.as_mut_ptr(), // pointer to the first element of the output vector
2161 );
2162 match ret_code {
2163 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2164 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2165 }
2166 crate::TA_Shutdown();
2167 }
2168 (out, out_begin)
2169}
2170pub fn sqrt() {}
2171pub fn s_sqrt() {}
2172pub fn stddev() {}
2173pub fn s_stddev() {}
2174///
2175/// TA_STOCH - Stochastic
2176///
2177/// Input = High, Low, Close
2178/// Output = double, double
2179///
2180/// Optional Parameters
2181/// -------------------
2182/// optInFastK_Period:(From 1 to 100000)
2183/// Time period for building the Fast-K line
2184///
2185/// optInSlowK_Period:(From 1 to 100000)
2186/// Smoothing for making the Slow-K line. Usually set to 3
2187///
2188/// optInSlowK_MAType:
2189/// Type of Moving Average for Slow-K
2190///
2191/// optInSlowD_Period:(From 1 to 100000)
2192/// Smoothing for making the Slow-D line
2193///
2194/// optInSlowD_MAType:
2195/// Type of Moving Average for Slow-D
2196///
2197/// #Sample
2198/// ```
2199/// let inReal: Vec<f64> = vec![
2200/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2201/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2202/// 1.086670, 1.086630,
2203/// ];
2204/// let high = inReal.clone();
2205/// let low = inReal.clone();
2206/// let close = inReal.clone();
2207/// let (outSlowK,outSlowD, begin) = rust_ta_lib::wrapper::stoch(9,3,0,3,0,&high,&low,&close);
2208/// for (index, value) in outSlowK.iter().enumerate() {
2209/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2210/// println!("outs index {} = {:?}", begin + index as i32 + 1, outSlowD.get(index));
2211/// }
2212/// ```
2213#[allow(clippy::too_many_arguments)]
2214pub fn stoch(
2215 fastk_period: u32,
2216 slowk_period: u32,
2217 optInSlowK_MAType: crate::TA_MAType,
2218 slowd_period: u32,
2219 optInSlowD_MAType: crate::TA_MAType,
2220 high: &Vec<f64>,
2221 low: &Vec<f64>,
2222 close: &Vec<f64>,
2223) -> (Vec<f64>, Vec<f64>, crate::TA_Integer) {
2224 let mut outSlowK: Vec<f64> = Vec::with_capacity(close.len());
2225 let mut outSlowD: Vec<f64> = Vec::with_capacity(close.len());
2226 let mut out_begin: crate::TA_Integer = 0;
2227 let mut out_size: crate::TA_Integer = 0;
2228
2229 unsafe {
2230 crate::TA_Initialize();
2231 let ret_code = crate::TA_STOCH(
2232 0, // index of the first close to use
2233 close.len() as i32 - 1, // index of the last close to use
2234 high.as_ptr(), // pointer to the first element of the high vector
2235 low.as_ptr(), // pointer to the first element of the low vector
2236 close.as_ptr(), // pointer to the first element of the close vector
2237 fastk_period as i32, // period of the atr
2238 slowk_period as i32,
2239 optInSlowK_MAType,
2240 slowd_period as i32,
2241 optInSlowD_MAType,
2242 &mut out_begin, // set to index of the first close to have an atr value
2243 &mut out_size, // set to number of atr values computed
2244 outSlowK.as_mut_ptr(), // pointer to the first element of the output vector
2245 outSlowD.as_mut_ptr(),
2246 );
2247
2248 match ret_code {
2249 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2250 // Rust doesn't know what is the new length of the vector, so we set it manually
2251 // to the number of values returned by the TA_ATR call
2252 crate::TA_RetCode_TA_SUCCESS => {
2253 outSlowK.set_len(out_size as usize);
2254 outSlowD.set_len(out_size as usize);
2255 }
2256 // An error occured
2257 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2258 }
2259 crate::TA_Shutdown();
2260 }
2261
2262 (outSlowK, outSlowD, out_begin)
2263}
2264///
2265/// TA_S_STOCH - Stochastic
2266///
2267/// Input = High, Low, Close
2268/// Output = double, double
2269///
2270/// Optional Parameters
2271/// -------------------
2272/// optInFastK_Period:(From 1 to 100000)
2273/// Time period for building the Fast-K line
2274///
2275/// optInSlowK_Period:(From 1 to 100000)
2276/// Smoothing for making the Slow-K line. Usually set to 3
2277///
2278/// optInSlowK_MAType:
2279/// Type of Moving Average for Slow-K
2280///
2281/// optInSlowD_Period:(From 1 to 100000)
2282/// Smoothing for making the Slow-D line
2283///
2284/// optInSlowD_MAType:
2285/// Type of Moving Average for Slow-D
2286///
2287/// #Sample
2288/// ```
2289/// let inReal: Vec<f32> = vec![
2290/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2291/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2292/// 1.086670, 1.086630,
2293/// ];
2294/// let high = inReal.clone();
2295/// let low = inReal.clone();
2296/// let close = inReal.clone();
2297/// let (outSlowK,outSlowD, begin) = rust_ta_lib::wrapper::s_stoch(9,3,0,3,0,&high,&low,&close);
2298/// for (index, value) in outSlowK.iter().enumerate() {
2299/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2300/// println!("outs index {} = {:?}", begin + index as i32 + 1, outSlowD.get(index));
2301/// }
2302/// ```
2303#[allow(clippy::too_many_arguments)]
2304pub fn s_stoch(
2305 fastk_period: u32,
2306 slowk_period: u32,
2307 optInSlowK_MAType: crate::TA_MAType,
2308 slowd_period: u32,
2309 optInSlowD_MAType: crate::TA_MAType,
2310 high: &Vec<f32>,
2311 low: &Vec<f32>,
2312 close: &Vec<f32>,
2313) -> (Vec<f64>, Vec<f64>, crate::TA_Integer) {
2314 let mut outSlowK: Vec<f64> = Vec::with_capacity(close.len());
2315 let mut outSlowD: Vec<f64> = Vec::with_capacity(close.len());
2316 let mut out_begin: crate::TA_Integer = 0;
2317 let mut out_size: crate::TA_Integer = 0;
2318
2319 unsafe {
2320 crate::TA_Initialize();
2321 let ret_code = crate::TA_S_STOCH(
2322 0, // index of the first close to use
2323 close.len() as i32 - 1, // index of the last close to use
2324 high.as_ptr(), // pointer to the first element of the high vector
2325 low.as_ptr(), // pointer to the first element of the low vector
2326 close.as_ptr(), // pointer to the first element of the close vector
2327 fastk_period as i32, // period of the atr
2328 slowk_period as i32,
2329 optInSlowK_MAType,
2330 slowd_period as i32,
2331 optInSlowD_MAType,
2332 &mut out_begin, // set to index of the first close to have an atr value
2333 &mut out_size, // set to number of atr values computed
2334 outSlowK.as_mut_ptr(), // pointer to the first element of the output vector
2335 outSlowD.as_mut_ptr(),
2336 );
2337
2338 match ret_code {
2339 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2340 // Rust doesn't know what is the new length of the vector, so we set it manually
2341 // to the number of values returned by the TA_ATR call
2342 crate::TA_RetCode_TA_SUCCESS => {
2343 outSlowK.set_len(out_size as usize);
2344 outSlowD.set_len(out_size as usize);
2345 }
2346 // An error occured
2347 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2348 }
2349 crate::TA_Shutdown();
2350 }
2351
2352 (outSlowK, outSlowD, out_begin)
2353}
2354
2355pub fn stochf() {}
2356pub fn s_stochf() {}
2357
2358///
2359/// TA_STOCHRSI - Stochastic Relative Strength Index
2360///
2361/// `Input`: close, timeperiod, fastk_period, fastd_period, fastd_matype=0
2362///
2363/// `Output`: (1st, 2nd, 3rd)
2364///
2365/// 1st: output fastk vector(f64)
2366///
2367/// 2nd: output fastd vector(f64)
2368///
2369/// 3rd: the first index of inputs corresponding to an valid output value
2370///
2371pub fn stochrsi(
2372 close: &Vec<f64>,
2373 timeperiod: i32,
2374 fastk_period: i32,
2375 fastd_period: i32,
2376 fastd_matype: crate::TA_MAType,
2377) -> (Vec<f64>, Vec<f64>, crate::TA_Integer) {
2378 let clen = close.len();
2379
2380 let mut out_fastk: Vec<f64> = Vec::with_capacity(clen);
2381 let mut out_fastd: Vec<f64> = Vec::with_capacity(clen);
2382 let mut out_begin: crate::TA_Integer = 0;
2383 let mut out_size: crate::TA_Integer = 0;
2384
2385 unsafe {
2386 crate::TA_Initialize();
2387 let ret_code = crate::TA_STOCHRSI(
2388 0, // the first index of the input vector to use
2389 clen as i32 - 1, // the last index of the input vector to use
2390 close.as_ptr(), // pointer to the close vector
2391 timeperiod, // time period
2392 fastk_period, // fastk period
2393 fastd_period, // slowd period
2394 fastd_matype,
2395 &mut out_begin, // set to index of the first close to have an valid output value
2396 &mut out_size, // set to number of values computed
2397 out_fastk.as_mut_ptr(), // pointer to the first element of the output fastk vector
2398 out_fastd.as_mut_ptr(), // pointer to the first element of the output fastd vector
2399 );
2400
2401 match ret_code {
2402 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2403 // Rust doesn't know what is the new length of the vector, so we set it manually
2404 // to the number of values returned by the TA_ATR call
2405 crate::TA_RetCode_TA_SUCCESS => {
2406 out_fastk.set_len(out_size as usize);
2407 out_fastd.set_len(out_size as usize);
2408 }
2409 // An error occured
2410 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2411 }
2412 crate::TA_Shutdown();
2413 }
2414
2415 (out_fastk, out_fastd, out_begin)
2416}
2417
2418pub fn s_stochrsi() {}
2419pub fn sub() {}
2420pub fn s_sub() {}
2421pub fn sum() {}
2422pub fn s_sum() {}
2423pub fn t3() {}
2424pub fn s_t3() {}
2425pub fn tan() {}
2426pub fn s_tan() {}
2427pub fn tanh() {}
2428pub fn s_tanh() {}
2429pub fn tema() {}
2430pub fn s_tema() {}
2431pub fn trange() {}
2432pub fn s_trange() {}
2433pub fn trima() {}
2434pub fn s_trima() {}
2435pub fn trix() {}
2436pub fn s_trix() {}
2437pub fn tsf() {}
2438pub fn s_tsf() {}
2439pub fn typprice() {}
2440pub fn s_typprice() {}
2441
2442///
2443/// TA_ULTOSC - Ultimate Oscillator
2444///
2445/// `Input`: high, low, close, timeperiod1, timeperiod2, timeperiod3
2446///
2447/// `Output`: (1st, 2nd)
2448///
2449/// 1st: output vector(f64)
2450///
2451/// 2nd: the first index of inputs corresponding to an valid output value
2452///
2453/// #Sample
2454/// ```
2455/// let inReal: Vec<f64> = vec![
2456/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2457/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2458/// 1.086670, 1.086630,
2459/// ];
2460/// let high = inReal.clone();
2461/// let low = inReal.clone();
2462/// let close = inReal.clone();
2463/// let (out, begin) = rust_ta_lib::wrapper::ultosc(&high,&low,&close,7,14,28);
2464/// for (index, value) in out.iter().enumerate() {
2465/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2466/// }
2467/// ```
2468pub fn ultosc(
2469 high: &Vec<f64>,
2470 low: &Vec<f64>,
2471 close: &Vec<f64>,
2472 timeperiod1: i32,
2473 timeperiod2: i32,
2474 timeperiod3: i32,
2475) -> (Vec<f64>, crate::TA_Integer) {
2476 let clen = close.len();
2477 if clen.ne(&high.len()) || clen.ne(&low.len()) {
2478 panic!("The length of input vectors are not equal, please double check the size of each.");
2479 }
2480
2481 let mut out: Vec<f64> = Vec::with_capacity(clen);
2482 let mut out_begin: crate::TA_Integer = 0;
2483 let mut out_size: crate::TA_Integer = 0;
2484
2485 unsafe {
2486 crate::TA_Initialize();
2487 let ret_code = crate::TA_ULTOSC(
2488 0, // the first index of the input vector to use
2489 clen as i32 - 1, // the last index of the input vector to use
2490 high.as_ptr(), // pointer to the high vector
2491 low.as_ptr(), // pointer to the low vector
2492 close.as_ptr(), // pointer to the close vector
2493 timeperiod1, // time period1
2494 timeperiod2, // time period2
2495 timeperiod3, // time period3
2496 &mut out_begin, // set to index of the first close to have an valid output value
2497 &mut out_size, // set to number of values computed
2498 out.as_mut_ptr(), // pointer to the first element of the output vector
2499 );
2500
2501 match ret_code {
2502 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2503 // Rust doesn't know what is the new length of the vector, so we set it manually
2504 // to the number of values returned by the TA_ATR call
2505 crate::TA_RetCode_TA_SUCCESS => {
2506 out.set_len(out_size as usize);
2507 }
2508 // An error occured
2509 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2510 }
2511 crate::TA_Shutdown();
2512 }
2513
2514 (out, out_begin)
2515}
2516
2517///
2518/// TA_S_ULTOSC - Ultimate Oscillator
2519///
2520/// `Input`: high, low, close, timeperiod1, timeperiod2, timeperiod3
2521///
2522/// `Output`: (1st, 2nd)
2523///
2524/// 1st: output vector(f32)
2525///
2526/// 2nd: the first index of inputs corresponding to an valid output value
2527///
2528/// #Sample
2529/// ```
2530/// let inReal: Vec<f32> = vec![
2531/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2532/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2533/// 1.086670, 1.086630,
2534/// ];
2535/// let high = inReal.clone();
2536/// let low = inReal.clone();
2537/// let close = inReal.clone();
2538/// let (out, begin) = rust_ta_lib::wrapper::s_ultosc(&high,&low,&close,7,14,28);
2539/// for (index, value) in out.iter().enumerate() {
2540/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2541/// }
2542/// ```
2543pub fn s_ultosc(
2544 high: &Vec<f32>,
2545 low: &Vec<f32>,
2546 close: &Vec<f32>,
2547 timeperiod1: i32,
2548 timeperiod2: i32,
2549 timeperiod3: i32,
2550) -> (Vec<f64>, crate::TA_Integer) {
2551 let clen = close.len();
2552 if clen.ne(&high.len()) || clen.ne(&low.len()) {
2553 panic!("The length of input vectors are not equal, please double check the size of each.");
2554 }
2555
2556 let mut out: Vec<f64> = Vec::with_capacity(clen);
2557 let mut out_begin: crate::TA_Integer = 0;
2558 let mut out_size: crate::TA_Integer = 0;
2559
2560 unsafe {
2561 crate::TA_Initialize();
2562 let ret_code = crate::TA_S_ULTOSC(
2563 0, // the first index of the input vector to use
2564 clen as i32 - 1, // the last index of the input vector to use
2565 high.as_ptr(), // pointer to the high vector
2566 low.as_ptr(), // pointer to the low vector
2567 close.as_ptr(), // pointer to the close vector
2568 timeperiod1, // time period1
2569 timeperiod2, // time period2
2570 timeperiod3, // time period3
2571 &mut out_begin, // set to index of the first close to have an valid output value
2572 &mut out_size, // set to number of values computed
2573 out.as_mut_ptr(), // pointer to the first element of the output vector
2574 );
2575
2576 match ret_code {
2577 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2578 // Rust doesn't know what is the new length of the vector, so we set it manually
2579 // to the number of values returned by the TA_ATR call
2580 crate::TA_RetCode_TA_SUCCESS => {
2581 out.set_len(out_size as usize);
2582 }
2583 // An error occured
2584 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2585 }
2586 crate::TA_Shutdown();
2587 }
2588
2589 (out, out_begin)
2590}
2591pub fn var() {}
2592pub fn s_var() {}
2593pub fn wclprice() {}
2594pub fn s_wclprice() {}
2595
2596///
2597/// TA_WILLR - Williams' %R
2598///
2599/// `Input`: high, low, close, timeperiod
2600///
2601/// `Output`: (1st, 2nd)
2602///
2603/// 1st: output vector(f64)
2604///
2605/// 2nd: the first index of inputs corresponding to an valid output value
2606///
2607pub fn willr(
2608 high: &Vec<f64>,
2609 low: &Vec<f64>,
2610 close: &Vec<f64>,
2611 timeperiod: i32,
2612) -> (Vec<f64>, crate::TA_Integer) {
2613 let clen = close.len();
2614 if clen.ne(&high.len()) || clen.ne(&low.len()) {
2615 panic!("The length of input vectors are not equal, please double check the size of each.");
2616 }
2617
2618 let mut out: Vec<f64> = Vec::with_capacity(clen);
2619 let mut out_begin: crate::TA_Integer = 0;
2620 let mut out_size: crate::TA_Integer = 0;
2621
2622 unsafe {
2623 crate::TA_Initialize();
2624 let ret_code = crate::TA_WILLR(
2625 0, // the first index of the input vector to use
2626 clen as i32 - 1, // the last index of the input vector to use
2627 high.as_ptr(), // pointer to the high vector
2628 low.as_ptr(), // pointer to the low vector
2629 close.as_ptr(), // pointer to the close vector
2630 timeperiod, // time period
2631 &mut out_begin, // set to index of the first close to have an valid output value
2632 &mut out_size, // set to number of values computed
2633 out.as_mut_ptr(), // pointer to the first element of the output vector
2634 );
2635
2636 match ret_code {
2637 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2638 // Rust doesn't know what is the new length of the vector, so we set it manually
2639 // to the number of values returned by the TA_ATR call
2640 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2641 // An error occured
2642 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2643 }
2644 crate::TA_Shutdown();
2645 }
2646
2647 (out, out_begin)
2648}
2649pub fn s_willr() {}
2650///
2651/// TA_WMA - Weighted Moving Average
2652///
2653/// Input = double
2654/// Output = double
2655/// -------------------
2656/// optInTimePeriod:(From 2 to 100000)
2657/// Number of period
2658//
2659/// #Sample
2660/// ```
2661/// let close_prices: Vec<f64> = vec![
2662/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2663/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2664/// 1.086670, 1.086630,
2665/// ];
2666/// let (outs, begin) = rust_ta_lib::wrapper::wma(10,&close_prices);
2667/// for (index, value) in outs.iter().enumerate() {
2668/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2669/// }
2670/// ```
2671pub fn wma(period: u32, close: &Vec<f64>) -> (Vec<f64>, crate::TA_Integer) {
2672 let mut out: Vec<f64> = Vec::with_capacity(close.len());
2673 let mut out_begin: crate::TA_Integer = 0;
2674 let mut out_size: crate::TA_Integer = 0;
2675
2676 unsafe {
2677 crate::TA_Initialize();
2678
2679 let ret_code = crate::TA_WMA(
2680 0, // index of the first close to use
2681 close.len() as i32 - 1, // index of the last close to use
2682 close.as_ptr(), // pointer to the first element of the close vector
2683 period as i32, // period of the ma
2684 &mut out_begin, // set to index of the first close to have an atr value
2685 &mut out_size, // set to number of atr values computed
2686 out.as_mut_ptr(), // pointer to the first element of the output vector
2687 );
2688
2689 match ret_code {
2690 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2691 // Rust doesn't know what is the new length of the vector, so we set it manually
2692 // to the number of values returned by the TA_ATR call
2693 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2694 // An error occured
2695 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2696 }
2697 crate::TA_Shutdown();
2698 }
2699
2700 (out, out_begin)
2701}
2702///
2703/// TA_S_WMA - Weighted Moving Average
2704///
2705/// Input = double
2706/// Output = double
2707/// -------------------
2708/// optInTimePeriod:(From 2 to 100000)
2709/// Number of period
2710//
2711/// #Sample
2712/// ```
2713/// let close_prices: Vec<f32> = vec![
2714/// 1.087010, 1.087120, 1.087080, 1.087170, 1.087110, 1.087010, 1.087100, 1.087120, 1.087110,
2715/// 1.087080, 1.087000, 1.086630, 1.086630, 1.086610, 1.086630, 1.086640, 1.086650, 1.086650,
2716/// 1.086670, 1.086630,
2717/// ];
2718/// let (outs, begin) = rust_ta_lib::wrapper::s_wma(10,&close_prices);
2719/// for (index, value) in outs.iter().enumerate() {
2720/// println!("outs index {} = {}", begin + index as i32 + 1, value);
2721/// }
2722/// ```
2723pub fn s_wma(period: u32, close: &Vec<f32>) -> (Vec<f64>, crate::TA_Integer) {
2724 let mut out: Vec<f64> = Vec::with_capacity(close.len());
2725 let mut out_begin: crate::TA_Integer = 0;
2726 let mut out_size: crate::TA_Integer = 0;
2727
2728 unsafe {
2729 crate::TA_Initialize();
2730
2731 let ret_code = crate::TA_S_WMA(
2732 0, // index of the first close to use
2733 close.len() as i32 - 1, // index of the last close to use
2734 close.as_ptr(), // pointer to the first element of the close vector
2735 period as i32, // period of the ma
2736 &mut out_begin, // set to index of the first close to have an atr value
2737 &mut out_size, // set to number of atr values computed
2738 out.as_mut_ptr(), // pointer to the first element of the output vector
2739 );
2740
2741 match ret_code {
2742 // Indicator was computed correctly, since the vector was filled by TA-lib C library,
2743 // Rust doesn't know what is the new length of the vector, so we set it manually
2744 // to the number of values returned by the TA_ATR call
2745 crate::TA_RetCode_TA_SUCCESS => out.set_len(out_size as usize),
2746 // An error occured
2747 _ => panic!("Could not compute indicator, err: {:?}", ret_code),
2748 }
2749 crate::TA_Shutdown();
2750 }
2751
2752 (out, out_begin)
2753}