last day range fix
This commit is contained in:
parent
a882640db9
commit
b6e89aa09c
@ -5,54 +5,21 @@ function get_range {
|
|||||||
# get histfile
|
# get histfile
|
||||||
local f_hist_file="$1"
|
local f_hist_file="$1"
|
||||||
|
|
||||||
# find constant range in defined periods
|
# Get range from a day 12h before (past day ist the usual range for calculationg Levels / Pivot Point)
|
||||||
local f_test_periods=300
|
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_orig_ifs=${IFS}
|
||||||
local f_current_price=$(tail -n1 "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1)
|
IFS=\n
|
||||||
local f_last_lowest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f25)
|
# get highest, lowest and closing price in range
|
||||||
local f_last_highest_in_range=$(tail -n2 "${f_hist_file}" | head -n1 | cut -d, -f26)
|
local f_highest_in_range=$(echo ${f_range_data} | sort -n | tail -n1)
|
||||||
if [ -n "${f_last_lowest_in_range}" ]
|
local f_lowest_in_range=$(echo ${f_range_data} | sort -n | head -n1)
|
||||||
then
|
local f_closing_price_in_range=$(echo ${f_range_data} | tail -n1)
|
||||||
if [ -n "${f_last_highest_in_range}" ]
|
IFS=${f_orig_ifs}
|
||||||
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)
|
|
||||||
|
|
||||||
# calculate Pivot Point (PP)
|
# 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
|
# 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_support1=$(echo "scale=8; ${f_pivot_point}-((${f_highest_in_range}-${f_lowest_in_range})*0.382)" | bc | sed 's/^\./0./;' )
|
||||||
|
Loading…
Reference in New Issue
Block a user