moving strategies to check_[buy|sell]_conditions.sh
This commit is contained in:
parent
4510794f32
commit
a28b442e5c
@ -38,14 +38,6 @@ function analyze {
|
||||
|
||||
ORIGIFS="$IFS"
|
||||
IFS=$'\n'
|
||||
local f_strategy
|
||||
|
||||
#lines=$(egrep "^${ANALYZE_TIME}" "$file" | grep -v ',,' | wc -l)
|
||||
#if [ $lines -lt 40 ]
|
||||
#then
|
||||
# g_echo "Only $lines lines for given timeframe (${ANALYZE_TIME}) in $file - ignoring files with less then 40!"
|
||||
# return 1
|
||||
#fi
|
||||
|
||||
for line in $(egrep "^${ANALYZE_TIME}" "$file" | grep -v ',,')
|
||||
do
|
||||
@ -55,28 +47,22 @@ function analyze {
|
||||
echo "$line" >>${g_tmp}/${tmpfile}
|
||||
if [ -f "${g_tmp}/open-${tmpfile}" ]
|
||||
then
|
||||
for f_strategy in $(find strategies -name "sell.*.conf" -type f)
|
||||
do
|
||||
if [ "${ANALYZE_VERBOSE}" -eq "0" ]
|
||||
then
|
||||
check_sell_conditions ${g_tmp}/${tmpfile} "${f_strategy}" >>${g_tmp}/output-${tmpfile} 2>&1
|
||||
else
|
||||
check_sell_conditions ${g_tmp}/${tmpfile} "${f_strategy}" 2>&1 | tee -a ${g_tmp}/output-${tmpfile}
|
||||
fi
|
||||
done
|
||||
if [ "${ANALYZE_VERBOSE}" -eq "0" ]
|
||||
then
|
||||
check_sell_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1
|
||||
else
|
||||
check_sell_conditions ${g_tmp}/${tmpfile} 2>&1
|
||||
fi
|
||||
fi
|
||||
if ! [ -f "${g_tmp}/open-${tmpfile}" ]
|
||||
then
|
||||
f_market_performance=$(grep "^$time" data/botdata/MARKET_PERFORMANCE | tail -n1 | cut -d: -f4 | cut -d"%" -f1 | sed 's/ *//')
|
||||
for f_strategy in $(find strategies -name "buy.*.conf" -type f)
|
||||
do
|
||||
if [ "${ANALYZE_VERBOSE}" -eq "0" ]
|
||||
then
|
||||
check_buy_conditions ${g_tmp}/${tmpfile} "${f_strategy}" >>${g_tmp}/output-${tmpfile} 2>&1 || break
|
||||
else
|
||||
check_buy_conditions ${g_tmp}/${tmpfile} "${f_strategy}" 2>&1 | tee -a ${g_tmp}/output-${tmpfile}
|
||||
fi
|
||||
done
|
||||
if [ "${ANALYZE_VERBOSE}" -eq "0" ]
|
||||
then
|
||||
check_buy_conditions ${g_tmp}/${tmpfile} >>${g_tmp}/output-${tmpfile} 2>&1
|
||||
else
|
||||
check_buy_conditions ${g_tmp}/${tmpfile} 2>&1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
|
@ -1,16 +1,18 @@
|
||||
function check_buy_conditions {
|
||||
|
||||
local f_ASSET_HIST_FILE="$1"
|
||||
local f_strategy="$2"
|
||||
f_ASSET=$(basename ${f_ASSET_HIST_FILE} | cut -d\. -f1)
|
||||
|
||||
if [ -n "${BOT}" ]
|
||||
if ! [ "$2" == "SELL" ]
|
||||
then
|
||||
# ignore already invested asset
|
||||
if ls trade-histories/trade-*${f_ASSET}-open.history.csv >/dev/null 2>&1
|
||||
if [ -n "${BOT}" ]
|
||||
then
|
||||
g_echo_note "BUY ${f_ASSET}@${CURRENCY}: $f_ASSET Already invested - ignoring for more diversification"
|
||||
return 0
|
||||
# ignore already invested asset
|
||||
if ls trade-histories/trade-*${f_ASSET}-open.history.csv >/dev/null 2>&1
|
||||
then
|
||||
g_echo_note "BUY ${f_ASSET}@${CURRENCY}: $f_ASSET Already invested - ignoring for more diversification"
|
||||
return 0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -18,141 +20,29 @@ function check_buy_conditions {
|
||||
get_vars_from_csv "${f_ASSET_HIST_FILE}" || return 1
|
||||
|
||||
### from here: check for defined state to buy
|
||||
f_BUY="${f_last_line},${f_market_performance}"
|
||||
f_BUY=""
|
||||
|
||||
# load strategy
|
||||
local f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
if [ -s "${f_strategy}" ]
|
||||
# run strategies
|
||||
local f_strategy_path=../../strategies
|
||||
[ -z "${BOT}" ] && f_strategy_path=strategies
|
||||
for f_strategy in $(find ${f_strategy_path} -name "buy.*.conf" -type f)
|
||||
do
|
||||
f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
if check_buy_conditions_strategy ${f_ASSET_HIST_FILE} ${f_strategy}
|
||||
then
|
||||
f_BUY="${f_echo_prefix} All BUY conditions met!!!
|
||||
$${f_last_line},${f_market_performance}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# if this checks came from sell function
|
||||
if [ "$2" == "SELL" ]
|
||||
then
|
||||
. "${f_strategy}" || return 0
|
||||
else
|
||||
g_echo_note "${f_echo_prefix}Strategy file not found"
|
||||
return 1
|
||||
fi
|
||||
g_echo_note "${f_echo_prefix}Running BUY checks"
|
||||
|
||||
|
||||
# Check market-performance
|
||||
if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ]
|
||||
then
|
||||
g_echo_note "${f_echo_prefix}BUY market performance ${f_market_performance}% looks bad - Dont buy anything"
|
||||
[ -n "$f_BUY" ] && return 1
|
||||
return 0
|
||||
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
|
||||
g_echo_note "${f_echo_prefix}With ${f_pricediff} under ${BUY_MINGROWTH}% growth in the last ${BUY_MINGROWTH_PERIOD} time periods"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# Check MACD
|
||||
if [ $(echo "${f_macd_histogram_relation} < ${BUY_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
then
|
||||
g_echo_note "${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% under BUY_MACD_RELATION_FROM ${BUY_MACD_RELATION_FROM}%"
|
||||
return 0
|
||||
fi
|
||||
if [ $(echo "${f_macd_histogram_relation} > ${BUY_MACD_RELATION_TO}" | bc -l) -ne 0 ]
|
||||
then
|
||||
g_echo_note "${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%"
|
||||
return 0
|
||||
fi
|
||||
|
||||
## no negative or empty values
|
||||
#if echo "${f_macd_histogram_relation}" | grep -q "^[0-9]"
|
||||
#then
|
||||
# # check for conditions
|
||||
# if [ ${f_macd_histogram_relation} -le ${BUY_MACD_RELATION_FROM} ] || [ ${f_macd_histogram_relation} -ge ${BUY_MACD_RELATION_TO} ]
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}MACD conditions NOT met"
|
||||
# return 0
|
||||
# fi
|
||||
#else
|
||||
# g_echo_note "${f_echo_prefix}f_macd_histogram_relation empty or negative"
|
||||
# return 0
|
||||
#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
|
||||
g_echo_note "${f_echo_prefix}RSI conditions NOT met"
|
||||
return 0
|
||||
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
|
||||
g_echo_note "${f_echo_prefix}Price change conditions NOT met"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# if [ -n "$f_BUY" ]
|
||||
# then
|
||||
# # Check for beginning MACD Trend
|
||||
# if ! tail -n3 ${f_ASSET_HIST_FILE} | grep -q '|buy,'
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}MACD Trend not near (3 timeframes) the beginning buy signal"
|
||||
# return 0
|
||||
# fi
|
||||
|
||||
# # Check for continious growing price
|
||||
# local f_price_before=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# local f_price_2before=$(tail -n3 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# local f_price_3before=$(tail -n4 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# if [ $(echo "${f_price} < ${f_price_before}" | bc -l) -ne 0 ] || \
|
||||
# [ $(echo "${f_price_before} < ${f_price_2before}" | bc -l) -ne 0 ] || \
|
||||
# [ $(echo "${f_price_2before} < ${f_price_3before}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}Last 3 prices not continiously growing"
|
||||
# return 0
|
||||
# fi
|
||||
|
||||
|
||||
|
||||
# # Check for growing MACD trend
|
||||
# local f_macd_histogram_before=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_2before=$(tail -n3 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_3before=$(tail -n4 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_4before=$(tail -n5 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_5before=$(tail -n6 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# if \
|
||||
# [ $(echo "${f_macd_histogram} < ${f_macd_histogram_before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_before} < ${f_macd_histogram_2before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_2before} < ${f_macd_histogram_3before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_3before} < ${f_macd_histogram_4before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_4before} < ${f_macd_histogram_5before}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# g_echo_note "BUY ${f_ASSET}@${CURRENCY}:${f_price} MACD Histogram not rising (now ${f_macd_histogram} < 1 before ${f_macd_histogram_before} < 2 before ${f_macd_histogram_2before} < 3 before ${f_macd_histogram_3before} < 4 before ${f_macd_histogram_4before} < 5 before ${f_macd_histogram_5before}) - trend loses strength / not growing - don't buy"
|
||||
# return 0
|
||||
# fi
|
||||
# fi
|
||||
|
||||
### Buy or not buy?
|
||||
# BOT
|
||||
if [ -n "$f_BUY" ] && [ -n "${BOT}" ]
|
||||
@ -209,6 +99,149 @@ echo "${csv_headline}
|
||||
${f_BUY}" | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s,
|
||||
echo "$f_BUY" >${g_tmp}/open-${tmpfile}
|
||||
BUY_PRICE=$current
|
||||
f_BUY=""
|
||||
fi
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function check_buy_conditions_strategy {
|
||||
|
||||
|
||||
# load strategy
|
||||
local f_echo_prefix="BUY ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
if [ -s "${f_strategy}" ]
|
||||
then
|
||||
. "${f_strategy}" || return 0
|
||||
else
|
||||
g_echo_note "${f_echo_prefix}Strategy file not found"
|
||||
return 1
|
||||
fi
|
||||
g_echo_note "${f_echo_prefix}Running BUY checks"
|
||||
|
||||
|
||||
# Check market-performance
|
||||
if [ $(echo "${f_market_performance} > ${GOOD_MARKET_PERFORMANCE_INDEX}" | bc -l) -eq 0 ]
|
||||
then
|
||||
g_echo_note "${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
|
||||
g_echo_note "${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
|
||||
g_echo_note "${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
|
||||
g_echo_note "${f_echo_prefix}MACD Relation with ${f_macd_histogram_relation}% over BUY_MACD_RELATION_TO ${BUY_MACD_RELATION_TO}%"
|
||||
return 1
|
||||
fi
|
||||
|
||||
## no negative or empty values
|
||||
#if echo "${f_macd_histogram_relation}" | grep -q "^[0-9]"
|
||||
#then
|
||||
# # check for conditions
|
||||
# if [ ${f_macd_histogram_relation} -le ${BUY_MACD_RELATION_FROM} ] || [ ${f_macd_histogram_relation} -ge ${BUY_MACD_RELATION_TO} ]
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}MACD conditions NOT met"
|
||||
# return 1
|
||||
# fi
|
||||
#else
|
||||
# g_echo_note "${f_echo_prefix}f_macd_histogram_relation empty or negative"
|
||||
# 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
|
||||
g_echo_note "${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
|
||||
g_echo_note "${f_echo_prefix}Price change conditions NOT met"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# if [ -n "$f_BUY" ]
|
||||
# then
|
||||
# # Check for beginning MACD Trend
|
||||
# if ! tail -n3 ${f_ASSET_HIST_FILE} | grep -q '|buy,'
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}MACD Trend not near (3 timeframes) the beginning buy signal"
|
||||
# return 1
|
||||
# fi
|
||||
|
||||
# # Check for continious growing price
|
||||
# local f_price_before=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# local f_price_2before=$(tail -n3 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# local f_price_3before=$(tail -n4 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f2)
|
||||
# if [ $(echo "${f_price} < ${f_price_before}" | bc -l) -ne 0 ] || \
|
||||
# [ $(echo "${f_price_before} < ${f_price_2before}" | bc -l) -ne 0 ] || \
|
||||
# [ $(echo "${f_price_2before} < ${f_price_3before}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# g_echo_note "${f_echo_prefix}Last 3 prices not continiously growing"
|
||||
# return 1
|
||||
# fi
|
||||
|
||||
|
||||
|
||||
# # Check for growing MACD trend
|
||||
# local f_macd_histogram_before=$(tail -n2 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_2before=$(tail -n3 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_3before=$(tail -n4 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_4before=$(tail -n5 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# local f_macd_histogram_5before=$(tail -n6 ${f_ASSET_HIST_FILE} | head -n1 | cut -d, -f8)
|
||||
# if \
|
||||
# [ $(echo "${f_macd_histogram} < ${f_macd_histogram_before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_before} < ${f_macd_histogram_2before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_2before} < ${f_macd_histogram_3before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_3before} < ${f_macd_histogram_4before}" | bc -l) -ne 0 ] && \
|
||||
# [ $(echo "${f_macd_histogram_4before} < ${f_macd_histogram_5before}" | bc -l) -ne 0 ]
|
||||
# then
|
||||
# g_echo_note "BUY ${f_ASSET}@${CURRENCY}:${f_price} MACD Histogram not rising (now ${f_macd_histogram} < 1 before ${f_macd_histogram_before} < 2 before ${f_macd_histogram_2before} < 3 before ${f_macd_histogram_3before} < 4 before ${f_macd_histogram_4before} < 5 before ${f_macd_histogram_5before}) - trend loses strength / not growing - don't buy"
|
||||
# return 1
|
||||
# fi
|
||||
# fi
|
||||
|
||||
}
|
||||
|
||||
|
@ -30,11 +30,7 @@ function check_for_buy {
|
||||
|
||||
if [ $(tail -n 6 "$f_ASSET_HIST_FILE" | egrep -v ",,|,$" | wc -l) -ge 5 ]
|
||||
then
|
||||
local f_strategy
|
||||
for f_strategy in $(find ../../strategies -name "buy.*.conf" -type f)
|
||||
do
|
||||
check_buy_conditions "${f_ASSET_HIST_FILE}" "${f_strategy}"
|
||||
done
|
||||
check_buy_conditions "${f_ASSET_HIST_FILE}" "${f_strategy}"
|
||||
else
|
||||
g_echo_note "BUY $f_ASSET_HIST_FILE not enough data - waiting for complete values"
|
||||
fi
|
||||
|
@ -22,12 +22,6 @@ function check_for_sell {
|
||||
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_msg}"
|
||||
continue
|
||||
fi
|
||||
|
||||
local f_strategy
|
||||
for f_strategy in $(find ../../strategies -name "sell.*.conf" -type f)
|
||||
do
|
||||
check_sell_conditions "${f_ASSET_HIST_FILE}" "${f_strategy}"
|
||||
done
|
||||
|
||||
check_sell_conditions "${f_ASSET_HIST_FILE}" "${f_strategy}"
|
||||
done
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
function check_sell_conditions {
|
||||
|
||||
local f_ASSET_HIST_FILE="$1"
|
||||
local f_strategy="$2"
|
||||
f_ASSET=$(basename ${f_ASSET_HIST_FILE} | cut -d\. -f1)
|
||||
|
||||
### from here: check for defined state to sell
|
||||
@ -10,7 +9,7 @@ function check_sell_conditions {
|
||||
# get data
|
||||
get_vars_from_csv ${f_ASSET_HIST_FILE} || return 1
|
||||
|
||||
local f_echo_prefix="SELL ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
f_echo_prefix="SELL ${f_ASSET}@${CURRENCY}:${f_price} - "
|
||||
|
||||
### check current result
|
||||
if [ -n "${BOT}" ]
|
||||
@ -39,6 +38,69 @@ function check_sell_conditions {
|
||||
echo ${f_BUY_PRICE_LAST_RATE_DIFF} >>${f_TRADE_HIST_FILE_INTERIM}
|
||||
|
||||
|
||||
# Check for filled buy conditions - if filled don't sell
|
||||
check_buy_conditions ${f_ASSET_HIST_FILE} SELL || return 0
|
||||
|
||||
# run strategies
|
||||
local f_strategy_path=../../strategies
|
||||
[ -z "${BOT}" ] && f_strategy_path=strategies
|
||||
for f_strategy in $(find ${f_strategy_path} -name "sell.*.conf" -type f)
|
||||
do
|
||||
f_echo_prefix="SELL ${f_ASSET}@${CURRENCY}:${f_price}:${f_strategy} - "
|
||||
check_sell_conditions_strategy ${f_ASSET_HIST_FILE} ${f_strategy} ${f_TRADE_HIST_FILE} ${f_TRADE_HIST_FILE_INTERIM} ${f_BUY_PRICE} ${f_BUY_PRICE_LAST_RATE_DIFF}
|
||||
if [ -n "$f_SELL" ]
|
||||
then
|
||||
f_SELL="${f_echo_prefix}${f_SELL}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
### Sell or not sell?
|
||||
# BOT
|
||||
if [ -n "$f_SELL" ] && [ -n "${BOT}" ]
|
||||
then
|
||||
g_echo_note "$f_SELL"
|
||||
echo "${f_last_line},${f_ASSET}" >>trade.log
|
||||
f_ASSET=$(echo ${f_ASSET} | sed "s/${CURRENCY}//")
|
||||
# binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}"
|
||||
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
|
||||
then
|
||||
binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}" ${f_QUANTITY_CURRENCY} || \
|
||||
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
|
||||
else
|
||||
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ANALYZE
|
||||
if [ -n "${f_SELL}" ] && [ -z "${BOT}" ]
|
||||
then
|
||||
echo "SELL: $(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f1)"
|
||||
echo "${csv_headline}
|
||||
${f_last_line}
|
||||
${f_SELL}" | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s,
|
||||
result=$(g_percentage-diff ${BUY_PRICE} ${current})
|
||||
result=$(echo "${result}-${FEE}" | bc | sed 's/^\./0./; s/^-\./-0./')
|
||||
echo "${result}" >>${g_tmp}/result-${tmpfile}
|
||||
rm -f "${f_TRADE_HIST_FILE}"
|
||||
rm -f "${f_TRADE_HIST_FILE_INTERIM}"
|
||||
echo "RESULT: ${result}% (${BUY_PRICE} -> ${current})"
|
||||
fi
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function check_sell_conditions_strategy {
|
||||
|
||||
local f_ASSET_HIST_FILE="$1"
|
||||
local f_strategy="$2"
|
||||
local f_TRADE_HIST_FILE="$3"
|
||||
local f_TRADE_HIST_FILE_INTERIM="$4"
|
||||
local f_BUY_PRICE="$5"
|
||||
local f_BUY_PRICE_LAST_RATE_DIFF="$6"
|
||||
|
||||
# run strategy
|
||||
if [ -s "${f_strategy}" ]
|
||||
then
|
||||
@ -49,11 +111,10 @@ function check_sell_conditions {
|
||||
fi
|
||||
g_echo_note "${f_echo_prefix}Running SELL checks"
|
||||
|
||||
|
||||
# check if the result (profit/loss until now) is lowering and sell if too low ()
|
||||
if [ -f ${f_TRADE_HIST_FILE_INTERIM} ]
|
||||
then
|
||||
local f_BUY_PRICE_2ND_LAST_RATE_DIFF=$(tail -n1 ${f_TRADE_HIST_FILE_INTERIM})
|
||||
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
|
||||
@ -72,7 +133,6 @@ function check_sell_conditions {
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# Sell on MACD Condition
|
||||
if [ $(echo "${f_macd_histogram_relation} < ${SELL_MACD_RELATION_FROM}" | bc -l) -ne 0 ]
|
||||
then
|
||||
@ -120,40 +180,4 @@ function check_sell_conditions {
|
||||
f_SELL="SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE(${SELL_PERCENTAGE_FROM_LAST_PURCHASE_NEGATIVE}%) > Last rate (${f_BUY_PRICE_LAST_RATE_DIFF}%)"
|
||||
fi
|
||||
|
||||
|
||||
|
||||
[ -n "$f_SELL" ] && f_SELL="SELL ${f_ASSET}@${CURRENCY}:${f_price}: $f_SELL"
|
||||
|
||||
### Sell or not sell?
|
||||
# BOT
|
||||
if [ -n "$f_SELL" ] && [ -n "${BOT}" ]
|
||||
then
|
||||
g_echo_note "$f_SELL"
|
||||
echo "${f_last_line},${f_ASSET}" >>trade.log
|
||||
f_ASSET=$(echo ${f_ASSET} | sed "s/${CURRENCY}//")
|
||||
# binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}"
|
||||
if [ ${STOCK_EXCHANGE} = "BINANCE" ]
|
||||
then
|
||||
binance_convert ${f_ASSET} ${CURRENCY} ${f_QUANTITY} sell "${f_SELL}" ${f_QUANTITY_CURRENCY} || \
|
||||
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
|
||||
else
|
||||
do_trade ${f_ASSET} ${CURRENCY} ${f_QUANTITY_CURRENCY} sell "${f_SELL}"
|
||||
fi
|
||||
fi
|
||||
|
||||
# ANALYZE
|
||||
if [ -n "${f_SELL}" ] && [ -z "${BOT}" ]
|
||||
then
|
||||
echo "SELL: $(tail -n1 ${f_ASSET_HIST_FILE} | cut -d, -f1)"
|
||||
echo "${csv_headline}
|
||||
${f_last_line}
|
||||
${f_SELL}" | perl -pe 's/((?<=,)|(?<=^)),/ ,/g;' | column -t -s,
|
||||
result=$(g_percentage-diff ${BUY_PRICE} ${current})
|
||||
result=$(echo "${result}-${FEE}" | bc | sed 's/^\./0./; s/^-\./-0./')
|
||||
echo "${result}" >>${g_tmp}/result-${tmpfile}
|
||||
rm -f "${f_TRADE_HIST_FILE}"
|
||||
rm -f "${f_TRADE_HIST_FILE_INTERIM}"
|
||||
echo "RESULT: ${result}% (${BUY_PRICE} -> ${current})"
|
||||
fi
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user