optimations
This commit is contained in:
parent
a3e33728e9
commit
0227713b2d
@ -7,8 +7,8 @@ export LANGUAGE="en_US"
|
|||||||
### CONFIG ###
|
### CONFIG ###
|
||||||
|
|
||||||
BASEPATH=/dabo/htdocs
|
BASEPATH=/dabo/htdocs
|
||||||
g_tries=5
|
g_tries=7
|
||||||
g_tries_delay=10
|
g_tries_delay=15
|
||||||
|
|
||||||
### FUNCTIONS ###
|
### FUNCTIONS ###
|
||||||
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
|
for bashfunc in $(find ${BASEPATH}/../functions -type f -name "*.sh")
|
||||||
|
@ -26,12 +26,12 @@ function get_asset {
|
|||||||
|
|
||||||
for f_price in $(tail -n 50 "${f_ASSET_HIST_FILE}" | grep "^[0-9]" | cut -d, -f2)
|
for f_price in $(tail -n 50 "${f_ASSET_HIST_FILE}" | grep "^[0-9]" | cut -d, -f2)
|
||||||
do
|
do
|
||||||
if [ "$f_last_price" == "$f_price" ]
|
if [ "${f_last_price}" == "${f_price}" ]
|
||||||
then
|
then
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
let "f_linecount+=1"
|
let "f_linecount+=1"
|
||||||
f_last_price=$f_price
|
f_last_price=${f_price}
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ ${f_linecount} -le 3 ] && [ ${f_lines} -ge 50 ]
|
if [ ${f_linecount} -le 3 ] && [ ${f_lines} -ge 50 ]
|
||||||
@ -102,10 +102,15 @@ function get_asset {
|
|||||||
do
|
do
|
||||||
local f_calcema=$(echo ${f_calcemanumcolumn} | cut -d: -f1)
|
local f_calcema=$(echo ${f_calcemanumcolumn} | cut -d: -f1)
|
||||||
local f_caclemacolumn=$(echo ${f_calcemanumcolumn} | cut -d: -f2)
|
local f_caclemacolumn=$(echo ${f_calcemanumcolumn} | cut -d: -f2)
|
||||||
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep ^2 | cut -d, -f${f_caclemacolumn})" "${f_price}"
|
local f_last_ema="$(tail -n2 "${f_ASSET_HIST_FILE}" | head -n1 | grep "^[0-9]" | cut -d, -f${f_caclemacolumn})"
|
||||||
|
if [ -z "${f_last_ema}" ] || [ -z "${f_price}" ]
|
||||||
|
then
|
||||||
|
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema}
|
||||||
|
else
|
||||||
|
get_ema "${f_ASSET_HIST_FILE}" 2 ${f_calcema} "${f_last_ema}" "${f_price}"
|
||||||
|
fi
|
||||||
if [ -z "${f_ema}" ]
|
if [ -z "${f_ema}" ]
|
||||||
then
|
then
|
||||||
g_echo_note "${FUNCNAME} $@: Not enough data for calculating EMA - waiting for more values"
|
|
||||||
echo -n "," >>"${f_ASSET_HIST_FILE}"
|
echo -n "," >>"${f_ASSET_HIST_FILE}"
|
||||||
else
|
else
|
||||||
echo -n ",${f_ema}" >>"${f_ASSET_HIST_FILE}"
|
echo -n ",${f_ema}" >>"${f_ASSET_HIST_FILE}"
|
||||||
|
@ -1,36 +1,55 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
#. /etc/bash/gaboshlib.include
|
|
||||||
|
|
||||||
function get_range {
|
function get_range {
|
||||||
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
||||||
# get histfile
|
# get histfile
|
||||||
local f_hist_file="$1"
|
local f_hist_file="$1"
|
||||||
|
|
||||||
# find constant range in defined periods
|
# find constant range in defined periods
|
||||||
local f_test_periods=1000
|
local f_test_periods=300
|
||||||
|
|
||||||
|
# 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
|
# go reverse through periods and look for range
|
||||||
for f_test_period in $(seq 1 ${f_test_periods})
|
if [ -z "${f_range_periods}" ]
|
||||||
do
|
then
|
||||||
# get average from period to now
|
for f_test_period in $(seq 1 ${f_test_periods})
|
||||||
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; }')
|
do
|
||||||
# get old price from period
|
# get average from period to now
|
||||||
local f_period_price=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1)
|
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 percentage diff from old price and last average
|
# get old price from period
|
||||||
local f_period_price_diff=$(g_percentage-diff ${f_period_price} ${f_rangeaverage} | sed 's/^-//; s/\..*$//')
|
local f_period_price=$(tail -n${f_test_period} "${f_hist_file}" | cut -d, -f2 | grep "^[0-9]" | head -n1)
|
||||||
# if percentage change is larger then 2% to the average we have an new price range
|
# get percentage diff from old price and last average
|
||||||
local f_range_periods=${f_test_period}
|
local f_period_price_diff=$(g_percentage-diff ${f_period_price} ${f_rangeaverage} | sed 's/^-//; s/\..*$//')
|
||||||
if [ ${f_period_price_diff} -gt 2 ]
|
# if percentage change is larger then 2% to the average we have an new price range
|
||||||
then
|
local f_range_periods=${f_test_period}
|
||||||
break
|
if [ ${f_period_price_diff} -gt 2 ]
|
||||||
fi
|
then
|
||||||
done
|
break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# get highest, lowest and current price in period
|
# 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_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_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)
|
# 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_current_price})/3" | bc | sed 's/^\./0./;')
|
||||||
@ -47,9 +66,5 @@ function get_range {
|
|||||||
|
|
||||||
# write down in history
|
# 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}"
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user