2023-10-20 17:43:11 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function get_range {
|
2023-10-30 14:06:25 +01:00
|
|
|
|
|
|
|
#g_echo_note "RUNNING FUNCTION ${FUNCNAME} $@"
|
|
|
|
|
2023-10-20 17:43:11 +02:00
|
|
|
# get histfile
|
|
|
|
local f_hist_file="$1"
|
|
|
|
|
2023-10-30 16:33:53 +01:00
|
|
|
# Get last days (past day is the usual range for calculationg Levels / Pivot Point) - Should be Tiomezone where most traders on exchange are in
|
|
|
|
# TODO:Add support for timezone
|
2023-10-30 14:06:25 +01:00
|
|
|
local f_latest_date=$(tail -n1 ${f_hist_file} | cut -d, -f1)
|
2023-10-30 16:33:53 +01:00
|
|
|
local f_range_day=$(date "+%F " --date="${f_latest_date} yesterday")
|
|
|
|
local f_range_data=$(grep "^${f_range_day}" ${f_hist_file} | cut -d , -f2 | grep "^[0-9]")
|
|
|
|
|
|
|
|
# Check for new range
|
|
|
|
local f_last_range_day=$(tail -n1 ${f_hist_file} | cut -d, -f24)
|
|
|
|
if echo "${f_latest_date}" | grep -q ${f_last_range_day}
|
|
|
|
then
|
|
|
|
g_echo_note "${FUNCNAME} $@: No new range"
|
|
|
|
return 1
|
|
|
|
fi
|
2023-10-30 14:06:25 +01:00
|
|
|
|
|
|
|
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
|
2023-10-30 16:33:53 +01:00
|
|
|
g_echo_note "${FUNCNAME} $@: Not enough data for calculating range"
|
|
|
|
return 1
|
2023-10-30 14:06:25 +01:00
|
|
|
fi
|
|
|
|
|
|
|
|
# write down in history
|
2023-10-30 16:33:53 +01:00
|
|
|
echo -n ",${f_range_day},${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}"
|
|
|
|
return 0
|
2023-10-30 14:06:25 +01:00
|
|
|
|
2023-10-20 17:43:11 +02:00
|
|
|
}
|
|
|
|
|