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
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_supertrend( void )
{
fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
fp_t const l[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
fp_t const c[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 };
fp_t const * const x[] = { o, h, l, c };
/* k=3, mult=2 */
/* TR at i=1: max(3,|13-11|=2,|10-11|=1)=3 */
/* TR at i=2: max(3,|14-12|=2,|11-12|=1)=3 */
/* TR at i=3: max(3,|15-13|=2,|12-13|=1)=3 */
/* ATR = (3+3+3)/3 = 3 */
/* Median at i=3: (15+12)/2 = 13.5 */
/* Upper = 13.5 + 2*3 = 19.5, Lower = 13.5 - 2*3 = 7.5 */
/* C[3]=14 > lower=7.5 => uptrend, supertrend=7.5 */
/* Next: ATR remains 3, Median=15, Upper=21, Lower=9 */
/* C[4]=15 > prev_st=7.5 and > lower=9 => supertrend=9 */
fp_t const est[] = { 7.5, 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5, 16.5, 17.5, 18.5 };
fp_t const etr[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
fp_t const * const exp[2] = { est, etr };
typedef struct { uint_t k; fp_t mult; } c_t;
c_t consts = { .k = 3, .mult = 2.0 };
return ts_test(ts_supertrend, ts_supertrend_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&consts, &ts_supertrend_p);
}
|