check for empty vars

This commit is contained in:
olli 2023-05-25 15:21:03 +02:00
parent d9398b4fcc
commit 103487790d

View File

@ -114,32 +114,40 @@ function check_sell_conditions_strategy {
# check if the result (profit/loss until now) is lowering and sell if too low () # check if the result (profit/loss until now) is lowering and sell if too low ()
if [ -f ${f_TRADE_HIST_FILE_INTERIM} ] 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./')
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 ]
then then
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}%)" local f_BUY_PRICE_2ND_LAST_RATE_DIFF=$(tail -n2 ${f_TRADE_HIST_FILE_INTERIM} | head -n1)
local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_2ND_LAST_RATE_DIFF})" | bc | sed 's/^\./0./; s/^-\./-0./')
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 ]
then
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
fi fi
# 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
local f_BUY_PRICE_XND_LAST_RATE_DIFF=$(tail -n${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ${f_TRADE_HIST_FILE_INTERIM} | head -n1) # Sell if the last X time units is lower then FEE
local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_XND_LAST_RATE_DIFF})" | bc) if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ]
if [ $(echo "${f_diff_result} < ${FEE}" | bc -l) -ne 0 ]
then then
f_SELL="Loss between last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%) in ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} time units before more then ${FEE} (${f_diff_result}%)" local f_BUY_PRICE_XND_LAST_RATE_DIFF=$(tail -n${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ${f_TRADE_HIST_FILE_INTERIM} | head -n1)
local f_diff_result=$(echo "${f_BUY_PRICE_LAST_RATE_DIFF} - (${f_BUY_PRICE_XND_LAST_RATE_DIFF})" | bc)
if [ $(echo "${f_diff_result} < ${FEE}" | bc -l) -ne 0 ]
then
f_SELL="Loss between last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%) in ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} time units before more then ${FEE} (${f_diff_result}%)"
fi
fi fi
fi fi
fi fi
# Sell on MACD Condition # 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 ]
then
f_SELL="MACD condition met"
fi
fi fi
# Sell on RSI conditions # Sell on RSI conditions
if \ if \
[ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \ [ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \