From b6e89aa09cdbe7592d597160f9e035f462782661 Mon Sep 17 00:00:00 2001 From: olli Date: Mon, 30 Oct 2023 13:21:29 +0100 Subject: [PATCH] last day range fix --- dabo/functions/get_range.sh | 57 ++++++++----------------------------- 1 file changed, 12 insertions(+), 45 deletions(-) diff --git a/dabo/functions/get_range.sh b/dabo/functions/get_range.sh index 16aa83e..5e5c875 100644 --- a/dabo/functions/get_range.sh +++ b/dabo/functions/get_range.sh @@ -5,54 +5,21 @@ function get_range { # get histfile local f_hist_file="$1" - # find constant range in defined periods - local f_test_periods=300 + # 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_range_data=$(sed -n "/${f_range_from_date}/,/${f_range_to_date}/p" ${f_hist_file} | cut -d , -f2 | grep "^[0-9]") - # check for range change - local f_current_price=$(tail -n1 "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) - local f_last_lowest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f25) - local f_last_highest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f26) - if [ -n "${f_last_lowest_in_range}" ] - then - if [ -n "${f_last_highest_in_range}" ] - then - if [ $(echo "${f_current_price} > ${f_last_lowest_in_range}" | bc -l) -ne 0 ] - then - if [ $(echo "${f_current_price} < ${f_last_highest_in_range}" | bc -l) -ne 0 ] - then - local f_range_periods=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f24) - f_range_periods=$((f_range_periods+1)) - fi - fi - fi - fi - - # go reverse through periods and look for range - if [ -z "${f_range_periods}" ] - then - for f_test_period in $(seq 1 ${f_test_periods}) - do - # get average from period to now - local f_rangeaverage=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | awk '{ sum += $1; n++ } END { OFMT = "%2.8f"; if (n > 0) print sum / n; }') - # get old price from period - local f_period_price=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1) - # get percentage diff from old price and last average - local f_period_price_diff=$(g_percentage-diff ${f_period_price} ${f_rangeaverage} | sed 's/^-//; s/\..*$//') - # if percentage change is larger then 2% to the average we have an new price range - local f_range_periods=${f_test_period} - if [ ${f_period_price_diff} -gt 2 ] - then - break - fi - done - fi - - # get highest, lowest and current price in period - local f_highest_in_range=$(tail -n${f_range_periods} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | sort -n | tail -n1) - local f_lowest_in_range=$(tail -n${f_range_periods} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | sort -n | head -n1) + 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_current_price})/3" | bc | sed 's/^\./0./;') + 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./;' )