fix EMA/SMA
This commit is contained in:
parent
4f3f7fdbec
commit
092bf62581
@ -40,9 +40,6 @@ function calc_ema {
|
|||||||
# check if there is a column (i from loop through array)
|
# check if there is a column (i from loop through array)
|
||||||
[ -z "$f_column" ] && return 3
|
[ -z "$f_column" ] && return 3
|
||||||
|
|
||||||
# check for enough positions/values to calculate (enough values)
|
|
||||||
[ $f_position -ge $f_period ] || return 0
|
|
||||||
|
|
||||||
# get ema column
|
# get ema column
|
||||||
[ -z "$f_target_column" ] && local f_target_column="ema$f_period"
|
[ -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_position=$((f_position-1))
|
||||||
local f_last_ema=${v_csv_array_associative[${f_target_column}_${f_last_ema_position}]}
|
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
|
# check if last EMA is given
|
||||||
if [ -n "$f_last_ema" ]
|
if [ -n "$f_last_ema" ]
|
||||||
then
|
then
|
||||||
@ -94,7 +97,6 @@ function calc_ema {
|
|||||||
fi
|
fi
|
||||||
v_csv_array_associative[${f_target_column}_${f_position}]=$g_calc_result
|
v_csv_array_associative[${f_target_column}_${f_position}]=$g_calc_result
|
||||||
f_ema=$g_calc_result
|
f_ema=$g_calc_result
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user