summaryrefslogtreecommitdiffstats
path: root/test/candlestick_formations.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
committerEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
commit07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch)
tree2bdeae46973f4bdfce263679a4008ac768011f28 /test/candlestick_formations.c
initial commit: ts time series analysis library v0.1.0
- 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags
Diffstat (limited to 'test/candlestick_formations.c')
-rw-r--r--test/candlestick_formations.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/candlestick_formations.c b/test/candlestick_formations.c
new file mode 100644
index 0000000..300b05e
--- /dev/null
+++ b/test/candlestick_formations.c
@@ -0,0 +1,32 @@
+#include <math.h>
+#include <stddef.h>
+#include "ts.h"
+
+bool ts_test_candlestick_formations( void )
+{
+ fp_t const o[] = { 10, 10, 14, 11, 10, 15, 12, 13, 14, 16 };
+ fp_t const h[] = { 11, 11, 15, 12, 14, 15, 13, 16, 14, 16 };
+ fp_t const l[] = { 9, 9, 13, 10, 10, 13, 11, 12, 12, 14 };
+ fp_t const c[] = { 10, 10, 14, 11, 13, 14, 12, 15, 13, 15 };
+
+ fp_t const * const x[] = { o, h, l, c };
+
+ /* i=1: O=10,C=10,H=11,L=9, body=0, range=2, doji (body/range=0 < 0.1) => 1 */
+ /* i=2: O=14,C=14,H=15,L=13, body=0, range=2, doji => 1 */
+ /* i=3: O=11,C=11,H=12,L=10, body=0, range=2, doji => 1 */
+ /* i=4: O=10,C=13,H=14,L=10, body=3, range=4, upper_wick=1, lower_wick=0, body_abs/range=0.75 */
+ /* prev_body=0, not engulfing. upper_wick=1, lower_wick=0 => not hammer/star => 0 */
+ /* i=5: O=15,C=14,H=15,L=13, body=-1, range=2, upper_wick=0, lower_wick=1 */
+ /* prev_body=3>0, -body=1 < 3, not engulfing. upper_wick=0 < 2*1 => not star. lower_wick=1 < 2*1 => not hammer. 0 */
+ /* i=6: O=12,C=12,H=13,L=11, body=0, range=2, doji => 1 */
+ /* i=7: O=13,C=15,H=16,L=12, body=2, range=4, upper_wick=1, lower_wick=1 */
+ /* prev_body=0, not engulfing. upper_wick=1 < 2*2, lower_wick=1 < 2*2 => 0 */
+ /* i=8: O=14,C=13,H=14,L=12, body=-1, range=2, upper_wick=0, lower_wick=1 */
+ /* prev_body=2>0, -body=1 < 2, not engulfing. not star/hammer => 0 */
+ /* i=9: O=16,C=15,H=16,L=14, body=-1, range=2, upper_wick=0, lower_wick=1 */
+ /* prev_body=-1, same direction, not engulfing. lower_wick=1 < 2*1 => 0 */
+ fp_t const e[] = { 1, 1, 1, 0, 0, 1, 0, 0, 0 };
+ fp_t const * const exp[1] = { e };
+
+ return ts_test(ts_candlestick_formations, ts_candlestick_formations_offset, x, exp, sizeof( o ) / sizeof( *o ), (ts_constant_t *)NULL, &ts_candlestick_formations_p);
+}