obsolete code and g_calc for bc

This commit is contained in:
olli 2023-11-07 16:27:19 +01:00
parent 5dbd3ec086
commit c96a394bbb
2 changed files with 243 additions and 238 deletions

View File

@ -51,7 +51,7 @@ function check_buy_conditions {
g_echo_note "${f_BUY}" g_echo_note "${f_BUY}"
# calculate quantity from balance for potentially invest # calculate quantity from balance for potentially invest
local f_INVEST_QUANTITY=$(echo "scale=2; ${CURRENCY_BALANCE}/100*${INVEST}" | bc -l | sed 's/^\./0./;' | cut -d\. -f1) local f_INVEST_QUANTITY=$(g_calc "scale=2; ${CURRENCY_BALANCE}/100*${INVEST}" | cut -d\. -f1)
g_echo_note "BUY current investment quantity is ${f_INVEST_QUANTITY} ${CURRENCY}" g_echo_note "BUY current investment quantity is ${f_INVEST_QUANTITY} ${CURRENCY}"
# remove CURRENCY from asset # remove CURRENCY from asset
@ -64,17 +64,17 @@ function check_buy_conditions {
# use MIN_NOTIONAL+5% as INVEST_QUANTITY if INVEST_QUANTITY is under MIN_NOTIONAL # use MIN_NOTIONAL+5% as INVEST_QUANTITY if INVEST_QUANTITY is under MIN_NOTIONAL
# +5% in spite of MIN_NOTIONAL to be able to sell when the price falls a little bit # +5% in spite of MIN_NOTIONAL to be able to sell when the price falls a little bit
[ $(echo "${f_INVEST_QUANTITY} < ${f_MIN_NOTIONAL}" | bc -l) -eq 0 ] || f_INVEST_QUANTITY=$(echo "scale=2; $f_MIN_NOTIONAL/100*105" | bc -l) [ $(g_calc "${f_INVEST_QUANTITY} < ${f_MIN_NOTIONAL}") -eq 0 ] || f_INVEST_QUANTITY=$(g_calc "scale=2; $f_MIN_NOTIONAL/100*105")
# if there is not enough balance for buying because ${f_MIN_NOTIONAL} needed for buying to sell (workaround) # if there is not enough balance for buying because ${f_MIN_NOTIONAL} needed for buying to sell (workaround)
if [ $(echo "${CURRENCY_BALANCE} < ${f_MIN_NOTIONAL}*2" | bc -l) -ne 0 ] if [ $(g_calc "${CURRENCY_BALANCE} < ${f_MIN_NOTIONAL}*2") -ne 0 ]
then then
g_echo_note "BUY ${f_ASSET} not enough balance ${CURRENCY_BALANCE} for buying because of MIN_NOTIONAL (${f_MIN_NOTIONAL}*2) needed for buying-to-sell (workaround)" g_echo_note "BUY ${f_ASSET} not enough balance ${CURRENCY_BALANCE} for buying because of MIN_NOTIONAL (${f_MIN_NOTIONAL}*2) needed for buying-to-sell (workaround)"
return 1 return 1
fi fi
# continue if not balance enough for lowest quantity (MIN_NOTIONAL) # continue if not balance enough for lowest quantity (MIN_NOTIONAL)
if [ $(echo "${CURRENCY_BALANCE} > ${f_INVEST_QUANTITY}" | bc -l) -eq 0 ] if [ $(g_calc "${CURRENCY_BALANCE} > ${f_INVEST_QUANTITY}") -eq 0 ]
then then
g_echo_note "BUY ${f_ASSET} not enough balance (${CURRENCY_BALANCE}) for lowest quantity (MIN_NOTIONAL - ${f_INVEST_QUANTITY})" g_echo_note "BUY ${f_ASSET} not enough balance (${CURRENCY_BALANCE}) for lowest quantity (MIN_NOTIONAL - ${f_INVEST_QUANTITY})"
return 1 return 1
@ -106,7 +106,6 @@ function check_buy_conditions {
function check_buy_conditions_strategy { function check_buy_conditions_strategy {
# load strategy # load strategy
local f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - " local f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
f_do_buy="" f_do_buy=""
@ -127,101 +126,103 @@ function check_buy_conditions_strategy {
fi fi
return 1 return 1
if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ] ########## Obsolete Code #############
then # if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ]
echo " ${f_echo_prefix}BUY market performance ${f_market_performance}% looks bad - Dont buy anything" # then
return 1 # echo " ${f_echo_prefix}BUY market performance ${f_market_performance}% looks bad - Dont buy anything"
fi # return 1
# fi
local f_priceXago=$(tail -n${BUY_MINGROWTH_PERIOD} ${f_ASSET_HIST_FILE} | grep ^[0-9] | head -n1 | cut -d, -f2) #
local f_pricenow=$(echo ${f_last_line} | grep ^[0-9] | cut -d, -f2) # local f_priceXago=$(tail -n${BUY_MINGROWTH_PERIOD} ${f_ASSET_HIST_FILE} | grep ^[0-9] | head -n1 | cut -d, -f2)
local f_pricediff=$(g_percentage-diff "$f_priceXago" "$f_pricenow") # local f_pricenow=$(echo ${f_last_line} | grep ^[0-9] | cut -d, -f2)
if [ $(echo "${f_pricediff} < ${BUY_MINGROWTH}" | bc -l) -ne 0 ] # local f_pricediff=$(g_percentage-diff "$f_priceXago" "$f_pricenow")
then # if [ $(echo "${f_pricediff} < ${BUY_MINGROWTH}" | bc -l) -ne 0 ]
echo " ${f_echo_prefix}With ${f_pricediff} under ${BUY_MINGROWTH}% growth in the last ${BUY_MINGROWTH_PERIOD} time periods" # then
return 1 # echo " ${f_echo_prefix}With ${f_pricediff} under ${BUY_MINGROWTH}% growth in the last ${BUY_MINGROWTH_PERIOD} time periods"
fi # return 1
# fi
# Check MACD #
if [ $(echo "${f_macd_histogram_relation} < ${BUY_MACD_RELATION_FROM}" | bc -l) -ne 0 ] #
then # # Check MACD
echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% under BUY_MACD_RELATION_FROM ${BUY_MACD_RELATION_FROM}%" # if [ $(echo "${f_macd_histogram_relation} < ${BUY_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
return 1 # then
fi # echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% under BUY_MACD_RELATION_FROM ${BUY_MACD_RELATION_FROM}%"
if [ $(echo "${f_macd_histogram_relation} > ${BUY_MACD_RELATION_TO}" | bc -l) -ne 0 ] # return 1
then # fi
echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%" # if [ $(echo "${f_macd_histogram_relation} > ${BUY_MACD_RELATION_TO}" | bc -l) -ne 0 ]
return 1 # then
fi # echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%"
# return 1
# RSI # fi
if \ #
[ ${f_rsi5} -le ${BUY_RSI5_SIGNAL_UNTIL} ] && \ # # RSI
[ ${f_rsi14} -le ${BUY_RSI14_SIGNAL_UNTIL} ] && \ # if \
[ ${f_rsi21} -le ${BUY_RSI21_SIGNAL_UNTIL} ] && \ # [ ${f_rsi5} -le ${BUY_RSI5_SIGNAL_UNTIL} ] && \
[ ${f_rsi60} -le ${BUY_RSI60_SIGNAL_UNTIL} ] && \ # [ ${f_rsi14} -le ${BUY_RSI14_SIGNAL_UNTIL} ] && \
[ ${f_rsi120} -le ${BUY_RSI120_SIGNAL_UNTIL} ] && \ # [ ${f_rsi21} -le ${BUY_RSI21_SIGNAL_UNTIL} ] && \
[ ${f_rsi240} -le ${BUY_RSI240_SIGNAL_UNTIL} ] && \ # [ ${f_rsi60} -le ${BUY_RSI60_SIGNAL_UNTIL} ] && \
[ ${f_rsi420} -le ${BUY_RSI420_SIGNAL_UNTIL} ] && \ # [ ${f_rsi120} -le ${BUY_RSI120_SIGNAL_UNTIL} ] && \
[ ${f_rsi720} -le ${BUY_RSI720_SIGNAL_UNTIL} ] && \ # [ ${f_rsi240} -le ${BUY_RSI240_SIGNAL_UNTIL} ] && \
[ ${f_rsi5} -ge ${BUY_RSI5_SIGNAL_FROM} ] && \ # [ ${f_rsi420} -le ${BUY_RSI420_SIGNAL_UNTIL} ] && \
[ ${f_rsi14} -ge ${BUY_RSI14_SIGNAL_FROM} ] && \ # [ ${f_rsi720} -le ${BUY_RSI720_SIGNAL_UNTIL} ] && \
[ ${f_rsi21} -ge ${BUY_RSI21_SIGNAL_FROM} ] && \ # [ ${f_rsi5} -ge ${BUY_RSI5_SIGNAL_FROM} ] && \
[ ${f_rsi60} -ge ${BUY_RSI60_SIGNAL_FROM} ] && \ # [ ${f_rsi14} -ge ${BUY_RSI14_SIGNAL_FROM} ] && \
[ ${f_rsi120} -ge ${BUY_RSI120_SIGNAL_FROM} ] && \ # [ ${f_rsi21} -ge ${BUY_RSI21_SIGNAL_FROM} ] && \
[ ${f_rsi240} -ge ${BUY_RSI240_SIGNAL_FROM} ] && \ # [ ${f_rsi60} -ge ${BUY_RSI60_SIGNAL_FROM} ] && \
[ ${f_rsi420} -ge ${BUY_RSI420_SIGNAL_FROM} ] && \ # [ ${f_rsi120} -ge ${BUY_RSI120_SIGNAL_FROM} ] && \
[ ${f_rsi720} -ge ${BUY_RSI720_SIGNAL_FROM} ] # [ ${f_rsi240} -ge ${BUY_RSI240_SIGNAL_FROM} ] && \
then # [ ${f_rsi420} -ge ${BUY_RSI420_SIGNAL_FROM} ] && \
echo "${f_echo_prefix}RSI conditions met" >/dev/null # [ ${f_rsi720} -ge ${BUY_RSI720_SIGNAL_FROM} ]
else # then
echo " ${f_echo_prefix}RSI conditions NOT met" # echo "${f_echo_prefix}RSI conditions met" >/dev/null
return 1 # else
fi # echo " ${f_echo_prefix}RSI conditions NOT met"
# return 1
# Price change # fi
if \ #
[ $(echo "${f_price_change_1_day} > ${BUY_MIN_PRICE_CHANGE_LAST_1_DAY}" | bc -l) -ne 0 ] && \ # # Price change
[ $(echo "${f_price_change_7_day} > ${BUY_MIN_PRICE_CHANGE_LAST_7_DAY}" | bc -l) -ne 0 ] && \ # if \
[ $(echo "${f_price_change_14_day} > ${BUY_MIN_PRICE_CHANGE_LAST_14_DAY}" | bc -l) -ne 0 ] && \ # [ $(echo "${f_price_change_1_day} > ${BUY_MIN_PRICE_CHANGE_LAST_1_DAY}" | bc -l) -ne 0 ] && \
[ $(echo "${f_price_change_30_day} > ${BUY_MIN_PRICE_CHANGE_LAST_30_DAY}" | bc -l) -ne 0 ] # [ $(echo "${f_price_change_7_day} > ${BUY_MIN_PRICE_CHANGE_LAST_7_DAY}" | bc -l) -ne 0 ] && \
then # [ $(echo "${f_price_change_14_day} > ${BUY_MIN_PRICE_CHANGE_LAST_14_DAY}" | bc -l) -ne 0 ] && \
echo "${f_echo_prefix}Price change conditions met" >/dev/null # [ $(echo "${f_price_change_30_day} > ${BUY_MIN_PRICE_CHANGE_LAST_30_DAY}" | bc -l) -ne 0 ]
else # then
echo " ${f_echo_prefix}Price change conditions NOT met" # echo "${f_echo_prefix}Price change conditions met" >/dev/null
return 1 # else
fi # echo " ${f_echo_prefix}Price change conditions NOT met"
# return 1
# fi
# after high change in one period next price often falls #
if [ -n "${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" ] #
then # # after high change in one period next price often falls
if [ $(echo "${f_price_change} > ${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" | bc -l) -ne 0 ] # if [ -n "${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" ]
then # then
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN (${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}) met" # if [ $(echo "${f_price_change} > ${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" | bc -l) -ne 0 ]
return 1 # then
fi # echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN (${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}) met"
fi # return 1
# fi
if [ -n "${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" ] # fi
then #
if [ $(echo "${f_price_change} < ${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ] # if [ -n "${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" ]
then # then
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_LOWER_THEN (${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}) met" # if [ $(echo "${f_price_change} < ${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ]
return 1 # then
fi # echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_LOWER_THEN (${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}) met"
fi # return 1
# fi
# fi
# dont buy on negative last result #
if [ "${BUY_DONT_WHEN_LAST_RATE_NEGATIVE}" = true ] #
then # # dont buy on negative last result
if echo "${f_price_change}" | grep -q "^-" # if [ "${BUY_DONT_WHEN_LAST_RATE_NEGATIVE}" = true ]
then # then
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_NEGATIVE met" # if echo "${f_price_change}" | grep -q "^-"
return 1 # then
fi # echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_NEGATIVE met"
fi # return 1
# fi
# fi
} }

View File

@ -95,7 +95,7 @@ function check_sell_conditions {
#${f_last_line}" | cut -d, -f 2-22 | perl -pe 's/([0-9].[0-9][0-9][0-9][0-9][0-9][0-9])[0-9]+/$1/g' | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s, #${f_last_line}" | cut -d, -f 2-22 | perl -pe 's/([0-9].[0-9][0-9][0-9][0-9][0-9][0-9])[0-9]+/$1/g' | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s,
# echo "${f_SELL}" # echo "${f_SELL}"
result=$(g_percentage-diff ${BUY_PRICE} ${current}) result=$(g_percentage-diff ${BUY_PRICE} ${current})
result=$(echo "${result}-${FEE}" | bc | sed 's/^\./0./; s/^-\./-0./') result=$(g_calc "${result}-${FEE}")
echo "${result}" >>${g_tmp}/result-${tmpfile} echo "${result}" >>${g_tmp}/result-${tmpfile}
rm -f "${f_TRADE_HIST_FILE}" rm -f "${f_TRADE_HIST_FILE}"
rm -f "${f_TRADE_HIST_FILE_INTERIM}" rm -f "${f_TRADE_HIST_FILE_INTERIM}"
@ -115,29 +115,31 @@ function check_sell_conditions_strategy {
local f_BUY_PRICE="$5" local f_BUY_PRICE="$5"
local f_BUY_PRICE_LAST_RATE_DIFF="$6" local f_BUY_PRICE_LAST_RATE_DIFF="$6"
# never occur rsi defaults to suppress error messages if no values from strategy given ########## Obsolete Code #############
local SELL_RSI5_SIGNAL_UNTIL="0" #
local SELL_RSI14_SIGNAL_UNTIL="0" # # never occur rsi defaults to suppress error messages if no values from strategy given
local SELL_RSI21_SIGNAL_UNTIL="0" # local SELL_RSI5_SIGNAL_UNTIL="0"
local SELL_RSI60_SIGNAL_UNTIL="0" # local SELL_RSI14_SIGNAL_UNTIL="0"
local SELL_RSI120_SIGNAL_UNTIL="0" # local SELL_RSI21_SIGNAL_UNTIL="0"
local SELL_RSI240_SIGNAL_UNTIL="0" # local SELL_RSI60_SIGNAL_UNTIL="0"
local SELL_RSI420_SIGNAL_UNTIL="0" # local SELL_RSI120_SIGNAL_UNTIL="0"
local SELL_RSI720_SIGNAL_UNTIL="0" # local SELL_RSI240_SIGNAL_UNTIL="0"
local SELL_RSI5_SIGNAL_FROM="101" # local SELL_RSI420_SIGNAL_UNTIL="0"
local SELL_RSI14_SIGNAL_FROM="101" # local SELL_RSI720_SIGNAL_UNTIL="0"
local SELL_RSI21_SIGNAL_FROM="101" # local SELL_RSI5_SIGNAL_FROM="101"
local SELL_RSI60_SIGNAL_FROM="101" # local SELL_RSI14_SIGNAL_FROM="101"
local SELL_RSI120_SIGNAL_FROM="101" # local SELL_RSI21_SIGNAL_FROM="101"
local SELL_RSI240_SIGNAL_FROM="101" # local SELL_RSI60_SIGNAL_FROM="101"
local SELL_RSI420_SIGNAL_FROM="101" # local SELL_RSI120_SIGNAL_FROM="101"
local SELL_RSI720_SIGNAL_FROM="101" # local SELL_RSI240_SIGNAL_FROM="101"
# local SELL_RSI420_SIGNAL_FROM="101"
# never occur rsi defaults to suppress error messages if no values from strategy given # local SELL_RSI720_SIGNAL_FROM="101"
local SELL_MACD_RELATION_FROM="-101" #
# # never occur rsi defaults to suppress error messages if no values from strategy given
# default # local SELL_MACD_RELATION_FROM="-101"
local SELL_HOLD_IF_RESULT_NEGATIVE="0" #
# # default
# local SELL_HOLD_IF_RESULT_NEGATIVE="0"
f_do_sell="" f_do_sell=""
@ -163,119 +165,121 @@ function check_sell_conditions_strategy {
return 0 return 0
fi fi
# check if the result (profit/loss until now) is lowering and sell if too low () ########## Obsolete Code #############
if [ -f ${f_TRADE_HIST_FILE_INTERIM} ] #
then # # check if the result (profit/loss until now) is lowering and sell if too low ()
if [ -n "$SELL_IF_LAST_RATE_LOWER_THEN" ] # if [ -f ${f_TRADE_HIST_FILE_INTERIM} ]
then # then
local f_BUY_PRICE_2ND_LAST_RATE_DIFF=$(tail -n2 ${f_TRADE_HIST_FILE_INTERIM} | head -n1) # if [ -n "$SELL_IF_LAST_RATE_LOWER_THEN" ]
local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_2ND_LAST_RATE_DIFF})" | bc | sed 's/^\./0./; s/^-\./-0./') # then
if [ $(echo "${f_diff_result} < ${SELL_IF_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ] && [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${FEE}" | bc -l) -ne 0 ] # local f_BUY_PRICE_2ND_LAST_RATE_DIFF=$(tail -n2 ${f_TRADE_HIST_FILE_INTERIM} | head -n1)
then # local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_2ND_LAST_RATE_DIFF})" | bc | sed 's/^\./0./; s/^-\./-0./')
f_SELL="Loss between last (${f_BUY_PRICE_LAST_RATE_DIFF}%) and 2nd last (${f_BUY_PRICE_2ND_LAST_RATE_DIFF}%) rate/result more then ${SELL_IF_LAST_RATE_LOWER_THEN}% (${f_diff_result}%)" # if [ $(echo "${f_diff_result} < ${SELL_IF_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ] && [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${FEE}" | bc -l) -ne 0 ]
fi # then
fi # f_SELL="Loss between last (${f_BUY_PRICE_LAST_RATE_DIFF}%) and 2nd last (${f_BUY_PRICE_2ND_LAST_RATE_DIFF}%) rate/result more then ${SELL_IF_LAST_RATE_LOWER_THEN}% (${f_diff_result}%)"
# fi
if [ -n "$SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD" ] # fi
then #
# Sell if the last X time units is lower then FEE # if [ -n "$SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD" ]
if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ] # then
then # # Sell if the last X time units is lower then FEE
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${FEE}" | bc -l) -ne 0 ] # if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ]
then # then
f_SELL="Result (${f_BUY_PRICE_LAST_RATE_DIFF}%) in more then ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} is under ${FEE}" # if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${FEE}" | bc -l) -ne 0 ]
fi # then
fi # f_SELL="Result (${f_BUY_PRICE_LAST_RATE_DIFF}%) in more then ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} is under ${FEE}"
fi # fi
fi # fi
# fi
# Sell on MACD Condition # fi
if [ -n "$SELL_MACD_RELATION_FROM" ] #
then # # Sell on MACD Condition
if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ] # if [ -n "$SELL_MACD_RELATION_FROM" ]
then # then
f_SELL="MACD condition met" # if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
fi # then
fi # f_SELL="MACD condition met"
# fi
# Sell on RSI conditions # fi
if \ #
[ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \ # # Sell on RSI conditions
[ ${f_rsi14} -le ${SELL_RSI14_SIGNAL_UNTIL} ] && \ # if \
[ ${f_rsi21} -le ${SELL_RSI21_SIGNAL_UNTIL} ] && \ # [ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \
[ ${f_rsi60} -le ${SELL_RSI60_SIGNAL_UNTIL} ] && \ # [ ${f_rsi14} -le ${SELL_RSI14_SIGNAL_UNTIL} ] && \
[ ${f_rsi120} -le ${SELL_RSI120_SIGNAL_UNTIL} ] && \ # [ ${f_rsi21} -le ${SELL_RSI21_SIGNAL_UNTIL} ] && \
[ ${f_rsi240} -le ${SELL_RSI240_SIGNAL_UNTIL} ] && \ # [ ${f_rsi60} -le ${SELL_RSI60_SIGNAL_UNTIL} ] && \
[ ${f_rsi420} -le ${SELL_RSI420_SIGNAL_UNTIL} ] && \ # [ ${f_rsi120} -le ${SELL_RSI120_SIGNAL_UNTIL} ] && \
[ ${f_rsi720} -le ${SELL_RSI720_SIGNAL_UNTIL} ]&& \ # [ ${f_rsi240} -le ${SELL_RSI240_SIGNAL_UNTIL} ] && \
[ ${f_rsi5} -ge ${SELL_RSI5_SIGNAL_FROM} ] && \ # [ ${f_rsi420} -le ${SELL_RSI420_SIGNAL_UNTIL} ] && \
[ ${f_rsi14} -ge ${SELL_RSI14_SIGNAL_FROM} ] && \ # [ ${f_rsi720} -le ${SELL_RSI720_SIGNAL_UNTIL} ]&& \
[ ${f_rsi21} -ge ${SELL_RSI21_SIGNAL_FROM} ] && \ # [ ${f_rsi5} -ge ${SELL_RSI5_SIGNAL_FROM} ] && \
[ ${f_rsi60} -ge ${SELL_RSI60_SIGNAL_FROM} ] && \ # [ ${f_rsi14} -ge ${SELL_RSI14_SIGNAL_FROM} ] && \
[ ${f_rsi120} -ge ${SELL_RSI120_SIGNAL_FROM} ] && \ # [ ${f_rsi21} -ge ${SELL_RSI21_SIGNAL_FROM} ] && \
[ ${f_rsi240} -ge ${SELL_RSI240_SIGNAL_FROM} ] && \ # [ ${f_rsi60} -ge ${SELL_RSI60_SIGNAL_FROM} ] && \
[ ${f_rsi420} -ge ${SELL_RSI420_SIGNAL_FROM} ] && \ # [ ${f_rsi120} -ge ${SELL_RSI120_SIGNAL_FROM} ] && \
[ ${f_rsi720} -ge ${SELL_RSI720_SIGNAL_FROM} ] # [ ${f_rsi240} -ge ${SELL_RSI240_SIGNAL_FROM} ] && \
then # [ ${f_rsi420} -ge ${SELL_RSI420_SIGNAL_FROM} ] && \
f_SELL="RSI conditions met" # [ ${f_rsi720} -ge ${SELL_RSI720_SIGNAL_FROM} ]
fi # then
# f_SELL="RSI conditions met"
# fi
# Take profit after positive results #
if [ -n "${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FACTOR}" ] #
then # # Take profit after positive results
if [ $(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS} ] # if [ -n "${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_PROFIT_CHECK_AT_FACTOR}" ]
then # then
# Only if result larger then fee # if [ $(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS} ]
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_PROFIT_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ] # then
then # # Only if result larger then fee
# Take profit if interim result falls over 20% (/1.25) from the highest result # if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_PROFIT_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
local f_highest_profit=$(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | tail -n1) # then
local f_take_profit=$(echo "${f_highest_profit} / ${TAKE_PROFIT_CHECK_AT_FACTOR}" | bc -l) # # Take profit if interim result falls over 20% (/1.25) from the highest result
[ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${f_take_profit}" | bc -l) -ne 0 ] && f_SELL="taking profit" # local f_highest_profit=$(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | tail -n1)
fi # local f_take_profit=$(echo "${f_highest_profit} / ${TAKE_PROFIT_CHECK_AT_FACTOR}" | bc -l)
fi # [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${f_take_profit}" | bc -l) -ne 0 ] && f_SELL="taking profit"
fi # fi
# fi
# fi
# Take loss #
if [ -n "${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FACTOR}" ] #
then # # Take loss
if [ $(tail -n${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ${f_TRADE_HIST_FILE_INTERIM} | grep "^-" | wc -l) -ge ${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ] # if [ -n "${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FEE_PLUS}" ] && [ -n "${TAKE_LOSS_CHECK_AT_FACTOR}" ]
then # then
# if result larger then fee # if [ $(tail -n${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ${f_TRADE_HIST_FILE_INTERIM} | grep "^-" | wc -l) -ge ${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ]
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_LOSS_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ] # then
then # # if result larger then fee
f_SELL="taking profit by loss before" # if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_LOSS_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
else # then
# on loss # f_SELL="taking profit by loss before"
local f_highest_loss=$(grep "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | head -n1) # else
local f_take_loss=$(echo "${f_highest_loss} / ${TAKE_LOSS_CHECK_AT_FACTOR}" | bc -l) # # on loss
[ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${f_take_loss}" | bc -l) -ne 0 ] && f_SELL="taking loss" # local f_highest_loss=$(grep "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | head -n1)
fi # local f_take_loss=$(echo "${f_highest_loss} / ${TAKE_LOSS_CHECK_AT_FACTOR}" | bc -l)
fi # [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${f_take_loss}" | bc -l) -ne 0 ] && f_SELL="taking loss"
fi # fi
# fi
# fi
#
# hold on negative result #
if [ "${SELL_HOLD_IF_RESULT_NEGATIVE}" -gt 0 ] #
then # # hold on negative result
if [ $(echo "(${f_BUY_PRICE_LAST_RATE_DIFF} + -${FEE}) < 0" | bc -l) -ne 0 ] # if [ "${SELL_HOLD_IF_RESULT_NEGATIVE}" -gt 0 ]
then # then
echo " Result negative - holding (INTERIM RESULT ${f_BUY_PRICE_LAST_RATE_DIFF}% - FEE ${FEE}% < 0 --> Ignoring ${f_SELL}" # if [ $(echo "(${f_BUY_PRICE_LAST_RATE_DIFF} + -${FEE}) < 0" | bc -l) -ne 0 ]
f_SELL="" # then
fi # echo " Result negative - holding (INTERIM RESULT ${f_BUY_PRICE_LAST_RATE_DIFF}% - FEE ${FEE}% < 0 --> Ignoring ${f_SELL}"
fi # f_SELL=""
# fi
# fi
# check for SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE #
if [ -n "${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" ] #
then # # check for SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" | bc -l) -ne 0 ] # if [ -n "${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" ]
then # then
f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)" # if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" | bc -l) -ne 0 ]
fi # then
fi # f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)"
# fi
# fi
} }