find range and calculate levels based on fibonacci retracements

This commit is contained in:
olli 2023-10-20 17:43:11 +02:00
parent 54078dc7ad
commit 4f4ffb61a2

View File

@ -0,0 +1,55 @@
#!/bin/bash
#. /etc/bash/gaboshlib.include
function get_range {
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
# get histfile
local f_hist_file="$1"
# find constant range in defined periods
local f_test_periods=1000
# go reverse through periods and look for range
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
# 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_current_price=$(tail -n1 "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1)
# 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./;')
# 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
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}"
}
#get_range /home/docker/dabo-bitpanda.ds9.dedyn.io/data/botdata/asset-histories/SHIBEUR.history.csv