1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
#include <stddef.h>
#include <stdlib.h>
#include <tgmath.h>
#include "ts.h"
static fp_t _ts_min( fp_t const * const *x, uint_t start, uint_t count )
{
fp_t m = ts_l( x, start );
for( uint_t i = 1; i < count; ++i )
{
m = fmin( m, ts_l( x, start - i ) );
}
return m;
}
static fp_t _ts_max_h( fp_t const * const *x, uint_t start, uint_t count )
{
fp_t m = ts_h( x, start );
for( uint_t i = 1; i < count; ++i )
{
m = fmax( m, ts_h( x, start - i ) );
}
return m;
}
bool ts_test_ultimate_oscillator( void )
{
uint_t n = 60;
fp_t o[60], h[60], l[60], c[60];
for (uint_t i = 0; i < n; ++i)
{
o[i] = 10.0 + (fp_t)i;
h[i] = 12.0 + (fp_t)i;
l[i] = 8.0 + (fp_t)i;
c[i] = 11.0 + (fp_t)i;
}
fp_t const * const x[] = { o, h, l, c };
uint_t offset = 54;
uint_t e_n = n - offset;
fp_t *e = calloc(e_n, sizeof(fp_t));
if (!e) return false;
for( uint_t i = offset; i < n; ++i )
{
fp_t bp7 = 0, tr7 = 0;
fp_t bp14 = 0, tr14 = 0;
fp_t bp28 = 0, tr28 = 0;
for( uint_t j = 0; j < 7; ++j )
{
uint_t idx = i - 6 + j;
fp_t ll = _ts_min( x, idx, 7 );
fp_t hh = _ts_max_h( x, idx, 7 );
bp7 += ts_c( x, idx ) - ll;
tr7 += hh - ll;
}
for( uint_t j = 0; j < 14; ++j )
{
uint_t idx = i - 13 + j;
fp_t ll = _ts_min( x, idx, 14 );
fp_t hh = _ts_max_h( x, idx, 14 );
bp14 += ts_c( x, idx ) - ll;
tr14 += hh - ll;
}
for( uint_t j = 0; j < 28; ++j )
{
uint_t idx = i - 27 + j;
fp_t ll = _ts_min( x, idx, 28 );
fp_t hh = _ts_max_h( x, idx, 28 );
bp28 += ts_c( x, idx ) - ll;
tr28 += hh - ll;
}
fp_t denom = 7.0 * tr7 + 3.0 * tr14 + tr28;
fp_t numer = 7.0 * bp7 + 3.0 * bp14 + bp28;
e[i - offset] = ( denom != 0 ) ? 100.0 * numer / denom : 50.0;
}
fp_t const * const e_arr[1] = { e };
bool result = ts_test(ts_ultimate_oscillator, ts_ultimate_oscillator_offset, x, e_arr, n, (ts_constant_t *)NULL, &ts_ultimate_oscillator_p);
free(e);
return result;
}
|