From b166582fd3d51c791a504e35f78bc553ffaf8a16 Mon Sep 17 00:00:00 2001 From: olli Date: Mon, 30 Oct 2023 14:06:25 +0100 Subject: [PATCH] last day range fix --- dabo/functions/get_range.sh | 61 +++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/dabo/functions/get_range.sh b/dabo/functions/get_range.sh index 5e5c875..a0285af 100644 --- a/dabo/functions/get_range.sh +++ b/dabo/functions/get_range.sh @@ -1,37 +1,46 @@ #!/bin/bash function get_range { - g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" + + #g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@" + # get histfile local f_hist_file="$1" # Get range from a day 12h before (past day ist the usual range for calculationg Levels / Pivot Point) - local f_range_to_date=$(date "+%F %H:" --date="-12 hours") - local f_range_from_date=$(date "+%F %H:" --date="-36 hours") + local f_latest_date=$(tail -n1 ${f_hist_file} | cut -d, -f1) + local f_range_to_date=$(date "+%F %H:" --date="${f_latest_date} 12 hours ago") + local f_range_from_date=$(date "+%F %H:" --date="${f_latest_date} 36 hours ago") local f_range_data=$(sed -n "/${f_range_from_date}/,/${f_range_to_date}/p" ${f_hist_file} | cut -d , -f2 | grep "^[0-9]") - - local f_orig_ifs=${IFS} - IFS=\n - # get highest, lowest and closing price in range - local f_highest_in_range=$(echo ${f_range_data} | sort -n | tail -n1) - local f_lowest_in_range=$(echo ${f_range_data} | sort -n | head -n1) - local f_closing_price_in_range=$(echo ${f_range_data} | tail -n1) - IFS=${f_orig_ifs} - - # calculate Pivot Point (PP) - local f_pivot_point=$(echo "scale=8; (${f_highest_in_range}+${f_lowest_in_range}+${f_closing_price_in_range})/3" | bc | sed 's/^\./0./;') - - # calculate support/resist and golden pocket - local f_support1=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.382)" | bc | sed 's/^\./0./;' ) - local f_resist1=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.382)" | bc | sed 's/^\./0./;' ) - local f_golden_pocket_support=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.618)" | bc | sed 's/^\./0./;' ) - local f_golden_pocket_resist=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.618)" | bc | sed 's/^\./0./;' ) - local f_golden_pocket65_support=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.65)" | bc | sed 's/^\./0./;' ) - local f_golden_pocket65_resist=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.65)" | bc | sed 's/^\./0./;' ) - local f_support3=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) - local f_resist3=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) - - # write down in history + + if [ -n "${f_range_data}" ] + then + local f_orig_ifs=${IFS} + IFS=\n + # get highest, lowest and closing price in range + local f_highest_in_range=$(echo ${f_range_data} | sort -n | tail -n1) + local f_lowest_in_range=$(echo ${f_range_data} | sort -n | head -n1) + local f_closing_price_in_range=$(echo ${f_range_data} | tail -n1) + IFS=${f_orig_ifs} + + # calculate Pivot Point (PP) + local f_pivot_point=$(echo "scale=8; (${f_highest_in_range}+${f_lowest_in_range}+${f_closing_price_in_range})/3" | bc | sed 's/^\./0./;') + + # calculate support/resist and golden pocket + local f_support1=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.382)" | bc | sed 's/^\./0./;' ) + local f_resist1=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.382)" | bc | sed 's/^\./0./;' ) + local f_golden_pocket_support=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.618)" | bc | sed 's/^\./0./;' ) + local f_golden_pocket_resist=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.618)" | bc | sed 's/^\./0./;' ) + local f_golden_pocket65_support=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.65)" | bc | sed 's/^\./0./;' ) + local f_golden_pocket65_resist=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*0.65)" | bc | sed 's/^\./0./;' ) + local f_support3=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) + local f_resist3=$(echo "scale=8; ${f_pivot_point}+((${f_highest_in_range}-${f_lowest_in_range})*1)" | bc | sed 's/^\./0./;' ) + else + g_echo_note "Not enough data for calculating range" + fi + + # write down in history echo -n ",${f_range_periods},${f_lowest_in_range},${f_highest_in_range},${f_pivot_point},${f_support1},${f_resist1},${f_golden_pocket_support},${f_golden_pocket_resist},${f_golden_pocket65_support},${f_golden_pocket65_resist},${f_support3},${f_resist3}" >>"${f_hist_file}" + }