last day range fix

This commit is contained in:
olli 2023-10-30 14:06:25 +01:00
parent b6e89aa09c
commit b166582fd3

View File

@ -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}"
}