From 092bf62581bb54ebb7d273a97360efa0b8b58cdb Mon Sep 17 00:00:00 2001 From: olli Date: Tue, 5 Nov 2024 12:38:12 +0100 Subject: [PATCH] fix EMA/SMA --- dabo/functions/calc_ema.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/dabo/functions/calc_ema.sh b/dabo/functions/calc_ema.sh index 8019674..9bfd931 100644 --- a/dabo/functions/calc_ema.sh +++ b/dabo/functions/calc_ema.sh @@ -40,9 +40,6 @@ function calc_ema { # check if there is a column (i from loop through array) [ -z "$f_column" ] && return 3 - # check for enough positions/values to calculate (enough values) - [ $f_position -ge $f_period ] || return 0 - # get ema column [ -z "$f_target_column" ] && local f_target_column="ema$f_period" @@ -58,6 +55,12 @@ function calc_ema { local f_last_ema_position=$((f_position-1)) local f_last_ema=${v_csv_array_associative[${f_target_column}_${f_last_ema_position}]} + # check for enough positions/values to calculate (enough values) if SMA needed + if [ -z "$f_last_ema" ] + then + [ $f_position -ge $f_period ] || return 5 + fi + # check if last EMA is given if [ -n "$f_last_ema" ] then @@ -94,7 +97,6 @@ function calc_ema { fi v_csv_array_associative[${f_target_column}_${f_position}]=$g_calc_result f_ema=$g_calc_result - return 0 }