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
|
#include <math.h>
#include <stddef.h>
#include "ts.h"
bool ts_test_atr_trailing_stops( void )
{
fp_t const o[] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
fp_t const h[] = { 12, 13, 14, 15, 16, 17, 18, 19, 20, 21 };
fp_t const l[] = { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 };
fp_t const cp[] = { 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
fp_t const * const x[] = { o, h, l, cp };
/* k=3, mult=2.0, offset=3, y_n=7 */
/* TR: all 3 => ATR=3.0 */
/* At i=3: Mid=(15+12)/2=13.5, Upper=13.5+6=19.5, Lower=13.5-6=7.5 */
/* At i=4: Mid=14.5, computed U=20.5, L=8.5 => trail: U=fmax(19.5,20.5)=20.5, L=fmin(7.5,8.5)=7.5 */
/* Upper trails up, lower stays at 7.5 (only moves down) */
fp_t const eu[] = { 19.5, 20.5, 21.5, 22.5, 23.5, 24.5, 25.5 };
fp_t const el[] = { 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5 };
fp_t const * const exp[2] = { eu, el };
typedef struct { uint_t k; fp_t mult; } c_t;
c_t my_c = { .k = 3, .mult = 2.0 };
return ts_test(ts_atr_trailing_stops, ts_atr_trailing_stops_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)&my_c, &ts_atr_trailing_stops_p);
}
|