summaryrefslogtreecommitdiffstats
path: root/test/ichimoku.c
blob: ea200567bcd599466d17beedeaba4e247415af7c (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
42
43
44
45
46
47
48
49
#include <math.h>
#include <stddef.h>
#include <stdlib.h>
#include "ts.h"

bool ts_test_ichimoku( void )
{
    uint_t n = 55;
    fp_t *o = malloc( n * sizeof( fp_t ) );
    fp_t *h = malloc( n * sizeof( fp_t ) );
    fp_t *l = malloc( n * sizeof( fp_t ) );
    fp_t *cl = malloc( n * sizeof( fp_t ) );

    if ( !o || !h || !l || !cl )
    {
        free( o ); free( h ); free( l ); free( cl );
        return false;
    }

    for ( uint_t i = 0; i < n; ++i )
    {
        o[i] = (fp_t)(100 + i);
        h[i] = (fp_t)(102 + i);
        l[i] = (fp_t)(98 + i);
        cl[i] = (fp_t)(101 + i);
    }

    fp_t const * const x[4] = { o, h, l, cl };

    /* Fixed: include current bar in lookback, Senkou plotted 26 ahead, Chikou 26 behind */
    /* offset=52, y_n=55-52=3 */
    fp_t const et[] = { 148, 149, 150 };
    fp_t const ek[] = { 139.5, 140.5, 141.5 };
    fp_t const esa[] = { 117.75, 118.75, 119.75 };
    fp_t const esb[] = { 0, 0, 0 };
    fp_t const ec[] = { 127, 128, 129 };
    fp_t const * const exp[5] = { et, ek, esa, esb, ec };

    ts_constant_t c;
    memset(&c, 0, sizeof(c));
    bool result = ts_test(ts_ichimoku, ts_ichimoku_offset, x, exp, n, &c, &ts_ichimoku_p);

    free( o );
    free( h );
    free( l );
    free( cl );

    return result;
}