blob: 8fb547107cfaebb192669283a7b6a7c7f254d3e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_twiggs_money_flow( void )
{
fp_t x_data[37] = { 0 };
for( uint_t i = 0; i < 37; ++i )
{
x_data[i] = (fp_t)(10 + i);
}
fp_t const * const x[] = { x_data };
fp_t pos_sum = 0;
fp_t neg_sum = 0;
for( uint_t i = 1; i <= 35; ++i )
{
fp_t change = x_data[i] - x_data[i - 1];
if( change >= 0 ) pos_sum += change;
else neg_sum += fabs( change );
}
fp_t e[2] = { 0 };
fp_t total = pos_sum + neg_sum;
e[0] = ( total != 0 ) ? ( pos_sum - neg_sum ) / total * 100.0 : 0;
fp_t change = x_data[36] - x_data[35];
fp_t old_change = x_data[1] - x_data[0];
if( change >= 0 ) pos_sum += change;
else neg_sum += fabs( change );
if( old_change >= 0 ) pos_sum -= old_change;
else neg_sum -= fabs( old_change );
total = pos_sum + neg_sum;
e[1] = ( total != 0 ) ? ( pos_sum - neg_sum ) / total * 100.0 : 0;
fp_t const * const e_arr[1] = { e };
return ts_test(ts_twiggs_money_flow, ts_twiggs_money_flow_offset, x, e_arr, 37, (ts_constant_t *)NULL, &ts_twiggs_money_flow_p);
}
|