summaryrefslogtreecommitdiffstats
path: root/lib/atr_trailing_stops.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
committerEthan Werner <mail@ethanwerner.com>2026-08-09 15:02:21 +0400
commit3d92926a902017e7cf1f5738e99ff62da596ce12 (patch)
tree2b55422c26a48759d56fa91f06df24449e9dfa88 /lib/atr_trailing_stops.c
parent07e18043145f3d91c8ea7ec3ad41b3c905585277 (diff)
refactormain
Diffstat (limited to 'lib/atr_trailing_stops.c')
-rw-r--r--lib/atr_trailing_stops.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/atr_trailing_stops.c b/lib/atr_trailing_stops.c
index 2c7cd73..46628a2 100644
--- a/lib/atr_trailing_stops.c
+++ b/lib/atr_trailing_stops.c
@@ -24,7 +24,7 @@ ts_parameter_t const ts_atr_trailing_stops_p = { .n_inputs = 4, .n_outputs = 2,
uint_t ts_atr_trailing_stops_offset( ts_constant_t const *c )
{
( void )c;
- return ( c ? ((ts_atr_trailing_stops_params_t *)c)->k : 0 );
+ return ( c ? ((ts_atr_trailing_stops_params_t const *)c)->k : 0 );
}
int ts_atr_trailing_stops(
@@ -35,11 +35,19 @@ int ts_atr_trailing_stops(
{
TS_PROLOGUE( ts_atr_trailing_stops_p );
if ( !c ) return -1;
- uint_t k = ((ts_atr_trailing_stops_params_t *)c)->k;
+ TS_CHECK_INPUT(x, x_n, n);
+ uint_t k = ((ts_atr_trailing_stops_params_t const *)c)->k;
if (k == 0) return -1;
if (n < k + 1) return -1;
- fp_t mult = ((ts_atr_trailing_stops_params_t *)c)->mult;
+ fp_t mult = ((ts_atr_trailing_stops_params_t const *)c)->mult;
+ if (mult < 0 || isnan(mult) || isinf(mult)) return -1;
+
+ for ( uint_t i = 0; i < k; ++i )
+ {
+ y[0][i] = NAN;
+ y[1][i] = NAN;
+ }
fp_t tr_sum = 0;
fp_t atr = 0;