obsolete code and g_calc for bc
This commit is contained in:
parent
5dbd3ec086
commit
c96a394bbb
@ -51,7 +51,7 @@ function check_buy_conditions {
|
||||
g_echo_note "${f_BUY}"
|
||||
|
||||
# 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}"
|
||||
|
||||
# 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
|
||||
# +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 [ $(echo "${CURRENCY_BALANCE} < ${f_MIN_NOTIONAL}*2" | bc -l) -ne 0 ]
|
||||
if [ $(g_calc "${CURRENCY_BALANCE} < ${f_MIN_NOTIONAL}*2") -ne 0 ]
|
||||
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)"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# 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
|
||||
g_echo_note "BUY ${f_ASSET} not enough balance (${CURRENCY_BALANCE}) for lowest quantity (MIN_NOTIONAL - ${f_INVEST_QUANTITY})"
|
||||
return 1
|
||||
@ -106,7 +106,6 @@ function check_buy_conditions {
|
||||
|
||||
function check_buy_conditions_strategy {
|
||||
|
||||
|
||||
# load strategy
|
||||
local f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
f_do_buy=""
|
||||
@ -127,101 +126,103 @@ function check_buy_conditions_strategy {
|
||||
fi
|
||||
return 1
|
||||
|
||||
if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}BUY market performance ${f_market_performance}% looks bad - Dont buy anything"
|
||||
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_pricediff=$(g_percentage-diff "$f_priceXago" "$f_pricenow")
|
||||
if [ $(echo "${f_pricediff} < ${BUY_MINGROWTH}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}With ${f_pricediff} under ${BUY_MINGROWTH}% growth in the last ${BUY_MINGROWTH_PERIOD} time periods"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check MACD
|
||||
if [ $(echo "${f_macd_histogram_relation} < ${BUY_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% under BUY_MACD_RELATION_FROM ${BUY_MACD_RELATION_FROM}%"
|
||||
return 1
|
||||
fi
|
||||
if [ $(echo "${f_macd_histogram_relation} > ${BUY_MACD_RELATION_TO}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# RSI
|
||||
if \
|
||||
[ ${f_rsi5} -le ${BUY_RSI5_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi14} -le ${BUY_RSI14_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi21} -le ${BUY_RSI21_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi60} -le ${BUY_RSI60_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi120} -le ${BUY_RSI120_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi240} -le ${BUY_RSI240_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi420} -le ${BUY_RSI420_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi720} -le ${BUY_RSI720_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi5} -ge ${BUY_RSI5_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi14} -ge ${BUY_RSI14_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi21} -ge ${BUY_RSI21_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi60} -ge ${BUY_RSI60_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi120} -ge ${BUY_RSI120_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi240} -ge ${BUY_RSI240_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi420} -ge ${BUY_RSI420_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi720} -ge ${BUY_RSI720_SIGNAL_FROM} ]
|
||||
then
|
||||
echo "${f_echo_prefix}RSI conditions met" >/dev/null
|
||||
else
|
||||
echo " ${f_echo_prefix}RSI conditions NOT met"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Price change
|
||||
if \
|
||||
[ $(echo "${f_price_change_1_day} > ${BUY_MIN_PRICE_CHANGE_LAST_1_DAY}" | bc -l) -ne 0 ] && \
|
||||
[ $(echo "${f_price_change_7_day} > ${BUY_MIN_PRICE_CHANGE_LAST_7_DAY}" | bc -l) -ne 0 ] && \
|
||||
[ $(echo "${f_price_change_14_day} > ${BUY_MIN_PRICE_CHANGE_LAST_14_DAY}" | bc -l) -ne 0 ] && \
|
||||
[ $(echo "${f_price_change_30_day} > ${BUY_MIN_PRICE_CHANGE_LAST_30_DAY}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo "${f_echo_prefix}Price change conditions met" >/dev/null
|
||||
else
|
||||
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
|
||||
if [ $(echo "${f_price_change} > ${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN (${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}) met"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -n "${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" ]
|
||||
then
|
||||
if [ $(echo "${f_price_change} < ${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_LOWER_THEN (${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}) met"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# dont buy on negative last result
|
||||
if [ "${BUY_DONT_WHEN_LAST_RATE_NEGATIVE}" = true ]
|
||||
then
|
||||
if echo "${f_price_change}" | grep -q "^-"
|
||||
then
|
||||
echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_NEGATIVE met"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
########## Obsolete Code #############
|
||||
# if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}BUY market performance ${f_market_performance}% looks bad - Dont buy anything"
|
||||
# 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_pricediff=$(g_percentage-diff "$f_priceXago" "$f_pricenow")
|
||||
# if [ $(echo "${f_pricediff} < ${BUY_MINGROWTH}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}With ${f_pricediff} under ${BUY_MINGROWTH}% growth in the last ${BUY_MINGROWTH_PERIOD} time periods"
|
||||
# return 1
|
||||
# fi
|
||||
#
|
||||
#
|
||||
# # Check MACD
|
||||
# if [ $(echo "${f_macd_histogram_relation} < ${BUY_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% under BUY_MACD_RELATION_FROM ${BUY_MACD_RELATION_FROM}%"
|
||||
# return 1
|
||||
# fi
|
||||
# if [ $(echo "${f_macd_histogram_relation} > ${BUY_MACD_RELATION_TO}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%"
|
||||
# return 1
|
||||
# fi
|
||||
#
|
||||
# # RSI
|
||||
# if \
|
||||
# [ ${f_rsi5} -le ${BUY_RSI5_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi14} -le ${BUY_RSI14_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi21} -le ${BUY_RSI21_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi60} -le ${BUY_RSI60_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi120} -le ${BUY_RSI120_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi240} -le ${BUY_RSI240_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi420} -le ${BUY_RSI420_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi720} -le ${BUY_RSI720_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi5} -ge ${BUY_RSI5_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi14} -ge ${BUY_RSI14_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi21} -ge ${BUY_RSI21_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi60} -ge ${BUY_RSI60_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi120} -ge ${BUY_RSI120_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi240} -ge ${BUY_RSI240_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi420} -ge ${BUY_RSI420_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi720} -ge ${BUY_RSI720_SIGNAL_FROM} ]
|
||||
# then
|
||||
# echo "${f_echo_prefix}RSI conditions met" >/dev/null
|
||||
# else
|
||||
# echo " ${f_echo_prefix}RSI conditions NOT met"
|
||||
# return 1
|
||||
# fi
|
||||
#
|
||||
# # Price change
|
||||
# if \
|
||||
# [ $(echo "${f_price_change_1_day} > ${BUY_MIN_PRICE_CHANGE_LAST_1_DAY}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_price_change_7_day} > ${BUY_MIN_PRICE_CHANGE_LAST_7_DAY}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_price_change_14_day} > ${BUY_MIN_PRICE_CHANGE_LAST_14_DAY}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_price_change_30_day} > ${BUY_MIN_PRICE_CHANGE_LAST_30_DAY}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo "${f_echo_prefix}Price change conditions met" >/dev/null
|
||||
# else
|
||||
# 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
|
||||
# if [ $(echo "${f_price_change} > ${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN (${BUY_DONT_WHEN_LAST_RATE_HIGHER_THEN}) met"
|
||||
# return 1
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
# if [ -n "${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" ]
|
||||
# then
|
||||
# if [ $(echo "${f_price_change} < ${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_LOWER_THEN (${BUY_DONT_WHEN_LAST_RATE_LOWER_THEN}) met"
|
||||
# return 1
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
#
|
||||
# # dont buy on negative last result
|
||||
# if [ "${BUY_DONT_WHEN_LAST_RATE_NEGATIVE}" = true ]
|
||||
# then
|
||||
# if echo "${f_price_change}" | grep -q "^-"
|
||||
# then
|
||||
# echo " ${f_echo_prefix}BUY_DONT_WHEN_LAST_RATE_NEGATIVE met"
|
||||
# return 1
|
||||
# fi
|
||||
# fi
|
||||
|
||||
}
|
||||
|
||||
|
@ -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,
|
||||
# echo "${f_SELL}"
|
||||
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}
|
||||
rm -f "${f_TRADE_HIST_FILE}"
|
||||
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_LAST_RATE_DIFF="$6"
|
||||
|
||||
# never occur rsi defaults to suppress error messages if no values from strategy given
|
||||
local SELL_RSI5_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI14_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI21_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI60_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI120_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI240_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI420_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI720_SIGNAL_UNTIL="0"
|
||||
local SELL_RSI5_SIGNAL_FROM="101"
|
||||
local SELL_RSI14_SIGNAL_FROM="101"
|
||||
local SELL_RSI21_SIGNAL_FROM="101"
|
||||
local SELL_RSI60_SIGNAL_FROM="101"
|
||||
local SELL_RSI120_SIGNAL_FROM="101"
|
||||
local SELL_RSI240_SIGNAL_FROM="101"
|
||||
local SELL_RSI420_SIGNAL_FROM="101"
|
||||
local SELL_RSI720_SIGNAL_FROM="101"
|
||||
|
||||
# never occur rsi defaults to suppress error messages if no values from strategy given
|
||||
local SELL_MACD_RELATION_FROM="-101"
|
||||
|
||||
# default
|
||||
local SELL_HOLD_IF_RESULT_NEGATIVE="0"
|
||||
########## Obsolete Code #############
|
||||
#
|
||||
# # never occur rsi defaults to suppress error messages if no values from strategy given
|
||||
# local SELL_RSI5_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI14_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI21_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI60_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI120_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI240_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI420_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI720_SIGNAL_UNTIL="0"
|
||||
# local SELL_RSI5_SIGNAL_FROM="101"
|
||||
# local SELL_RSI14_SIGNAL_FROM="101"
|
||||
# local SELL_RSI21_SIGNAL_FROM="101"
|
||||
# local SELL_RSI60_SIGNAL_FROM="101"
|
||||
# local SELL_RSI120_SIGNAL_FROM="101"
|
||||
# local SELL_RSI240_SIGNAL_FROM="101"
|
||||
# local SELL_RSI420_SIGNAL_FROM="101"
|
||||
# local SELL_RSI720_SIGNAL_FROM="101"
|
||||
#
|
||||
# # never occur rsi defaults to suppress error messages if no values from strategy given
|
||||
# local SELL_MACD_RELATION_FROM="-101"
|
||||
#
|
||||
# # default
|
||||
# local SELL_HOLD_IF_RESULT_NEGATIVE="0"
|
||||
|
||||
f_do_sell=""
|
||||
|
||||
@ -163,119 +165,121 @@ function check_sell_conditions_strategy {
|
||||
return 0
|
||||
fi
|
||||
|
||||
# check if the result (profit/loss until now) is lowering and sell if too low ()
|
||||
if [ -f ${f_TRADE_HIST_FILE_INTERIM} ]
|
||||
then
|
||||
if [ -n "$SELL_IF_LAST_RATE_LOWER_THEN" ]
|
||||
then
|
||||
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
|
||||
|
||||
if [ -n "$SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD" ]
|
||||
then
|
||||
# Sell if the last X time units is lower then FEE
|
||||
if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ]
|
||||
then
|
||||
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${FEE}" | bc -l) -ne 0 ]
|
||||
then
|
||||
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
|
||||
|
||||
# Sell on MACD Condition
|
||||
if [ -n "$SELL_MACD_RELATION_FROM" ]
|
||||
then
|
||||
if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
then
|
||||
f_SELL="MACD condition met"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Sell on RSI conditions
|
||||
if \
|
||||
[ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi14} -le ${SELL_RSI14_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi21} -le ${SELL_RSI21_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi60} -le ${SELL_RSI60_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi120} -le ${SELL_RSI120_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi240} -le ${SELL_RSI240_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi420} -le ${SELL_RSI420_SIGNAL_UNTIL} ] && \
|
||||
[ ${f_rsi720} -le ${SELL_RSI720_SIGNAL_UNTIL} ]&& \
|
||||
[ ${f_rsi5} -ge ${SELL_RSI5_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi14} -ge ${SELL_RSI14_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi21} -ge ${SELL_RSI21_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi60} -ge ${SELL_RSI60_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi120} -ge ${SELL_RSI120_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi240} -ge ${SELL_RSI240_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi420} -ge ${SELL_RSI420_SIGNAL_FROM} ] && \
|
||||
[ ${f_rsi720} -ge ${SELL_RSI720_SIGNAL_FROM} ]
|
||||
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
|
||||
if [ $(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS} ]
|
||||
then
|
||||
# Only if result larger then fee
|
||||
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_PROFIT_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
|
||||
then
|
||||
# Take profit if interim result falls over 20% (/1.25) from the highest result
|
||||
local f_highest_profit=$(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | tail -n1)
|
||||
local f_take_profit=$(echo "${f_highest_profit} / ${TAKE_PROFIT_CHECK_AT_FACTOR}" | bc -l)
|
||||
[ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${f_take_profit}" | bc -l) -ne 0 ] && f_SELL="taking profit"
|
||||
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
|
||||
if [ $(tail -n${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ${f_TRADE_HIST_FILE_INTERIM} | grep "^-" | wc -l) -ge ${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ]
|
||||
then
|
||||
# if result larger then fee
|
||||
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_LOSS_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
|
||||
then
|
||||
f_SELL="taking profit by loss before"
|
||||
else
|
||||
# on loss
|
||||
local f_highest_loss=$(grep "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | head -n1)
|
||||
local f_take_loss=$(echo "${f_highest_loss} / ${TAKE_LOSS_CHECK_AT_FACTOR}" | bc -l)
|
||||
[ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${f_take_loss}" | bc -l) -ne 0 ] && f_SELL="taking loss"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# hold on negative result
|
||||
if [ "${SELL_HOLD_IF_RESULT_NEGATIVE}" -gt 0 ]
|
||||
then
|
||||
if [ $(echo "(${f_BUY_PRICE_LAST_RATE_DIFF} + -${FEE}) < 0" | bc -l) -ne 0 ]
|
||||
then
|
||||
echo " Result negative - holding (INTERIM RESULT ${f_BUY_PRICE_LAST_RATE_DIFF}% - FEE ${FEE}% < 0 --> Ignoring ${f_SELL}"
|
||||
f_SELL=""
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# check for SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE
|
||||
if [ -n "${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" ]
|
||||
then
|
||||
if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" | bc -l) -ne 0 ]
|
||||
then
|
||||
f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)"
|
||||
fi
|
||||
fi
|
||||
########## Obsolete Code #############
|
||||
#
|
||||
# # check if the result (profit/loss until now) is lowering and sell if too low ()
|
||||
# if [ -f ${f_TRADE_HIST_FILE_INTERIM} ]
|
||||
# then
|
||||
# if [ -n "$SELL_IF_LAST_RATE_LOWER_THEN" ]
|
||||
# then
|
||||
# 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
|
||||
#
|
||||
# if [ -n "$SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD" ]
|
||||
# then
|
||||
# # Sell if the last X time units is lower then FEE
|
||||
# if [ $(cat ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${SELL_IF_LOWER_THEN_FEE_AFTER_PERIOD} ]
|
||||
# then
|
||||
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${FEE}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# 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
|
||||
#
|
||||
# # Sell on MACD Condition
|
||||
# if [ -n "$SELL_MACD_RELATION_FROM" ]
|
||||
# then
|
||||
# if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# f_SELL="MACD condition met"
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
# # Sell on RSI conditions
|
||||
# if \
|
||||
# [ ${f_rsi5} -le ${SELL_RSI5_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi14} -le ${SELL_RSI14_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi21} -le ${SELL_RSI21_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi60} -le ${SELL_RSI60_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi120} -le ${SELL_RSI120_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi240} -le ${SELL_RSI240_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi420} -le ${SELL_RSI420_SIGNAL_UNTIL} ] && \
|
||||
# [ ${f_rsi720} -le ${SELL_RSI720_SIGNAL_UNTIL} ]&& \
|
||||
# [ ${f_rsi5} -ge ${SELL_RSI5_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi14} -ge ${SELL_RSI14_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi21} -ge ${SELL_RSI21_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi60} -ge ${SELL_RSI60_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi120} -ge ${SELL_RSI120_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi240} -ge ${SELL_RSI240_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi420} -ge ${SELL_RSI420_SIGNAL_FROM} ] && \
|
||||
# [ ${f_rsi720} -ge ${SELL_RSI720_SIGNAL_FROM} ]
|
||||
# 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
|
||||
# if [ $(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | wc -l) -ge ${TAKE_PROFIT_CHECK_AFTER_POSTITIVE_RESULTS} ]
|
||||
# then
|
||||
# # Only if result larger then fee
|
||||
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_PROFIT_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# # Take profit if interim result falls over 20% (/1.25) from the highest result
|
||||
# local f_highest_profit=$(grep -v "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | tail -n1)
|
||||
# local f_take_profit=$(echo "${f_highest_profit} / ${TAKE_PROFIT_CHECK_AT_FACTOR}" | bc -l)
|
||||
# [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${f_take_profit}" | bc -l) -ne 0 ] && f_SELL="taking profit"
|
||||
# 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
|
||||
# if [ $(tail -n${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ${f_TRADE_HIST_FILE_INTERIM} | grep "^-" | wc -l) -ge ${TAKE_LOSS_CHECK_AFTER_NEGATIVE_RESULTS} ]
|
||||
# then
|
||||
# # if result larger then fee
|
||||
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > (${FEE}+${TAKE_LOSS_CHECK_AT_FEE_PLUS})" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# f_SELL="taking profit by loss before"
|
||||
# else
|
||||
# # on loss
|
||||
# local f_highest_loss=$(grep "^-" ${f_TRADE_HIST_FILE_INTERIM} | LANG=en_US.UTF-8 sort -n | head -n1)
|
||||
# local f_take_loss=$(echo "${f_highest_loss} / ${TAKE_LOSS_CHECK_AT_FACTOR}" | bc -l)
|
||||
# [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} > ${f_take_loss}" | bc -l) -ne 0 ] && f_SELL="taking loss"
|
||||
# fi
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
#
|
||||
#
|
||||
# # hold on negative result
|
||||
# if [ "${SELL_HOLD_IF_RESULT_NEGATIVE}" -gt 0 ]
|
||||
# then
|
||||
# if [ $(echo "(${f_BUY_PRICE_LAST_RATE_DIFF} + -${FEE}) < 0" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# echo " Result negative - holding (INTERIM RESULT ${f_BUY_PRICE_LAST_RATE_DIFF}% - FEE ${FEE}% < 0 --> Ignoring ${f_SELL}"
|
||||
# f_SELL=""
|
||||
# fi
|
||||
# fi
|
||||
#
|
||||
#
|
||||
# # check for SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE
|
||||
# if [ -n "${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" ]
|
||||
# then
|
||||
# if [ $(echo "${f_BUY_PRICE_LAST_RATE_DIFF} < ${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)"
|
||||
# fi
|
||||
# fi
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user