This commit is contained in:
olli 2024-12-17 11:37:32 +01:00
parent 5326e3f5bc
commit 705df375c9
2 changed files with 19 additions and 9 deletions

View File

@ -184,6 +184,9 @@ do
[[ $side = long ]] && entry_price=${v[${asset}_levels_1w_next_down]} [[ $side = long ]] && entry_price=${v[${asset}_levels_1w_next_down]}
[[ $side = short ]] && entry_price=${v[${asset}_levels_1w_next_up]} [[ $side = short ]] && entry_price=${v[${asset}_levels_1w_next_up]}
# if entry price not given set to current price
[ -z "$entry_price" ] && entry_price=${v[BTCUSDT_price]}
# check for updates if order with entry price is already defined # check for updates if order with entry price is already defined
if [ -n "${o[${asset}_open_${side}_entry_price]}" ] if [ -n "${o[${asset}_open_${side}_entry_price]}" ]
then then

View File

@ -5,7 +5,7 @@ g_echo_note "EXAMPLE Strategy for managing open positions"
##### WARNING! This strategy is only intended as an example and should not be used with real trades. Please develop your own strategy ###### ##### WARNING! This strategy is only intended as an example and should not be used with real trades. Please develop your own strategy ######
# if you want to use this remove the next line with return 0 # if you want to use this remove the next line with return 0
return 0 #return 0
# get vars with positions # get vars with positions
get_position_array get_position_array
@ -17,7 +17,7 @@ do
asset=${asset//\//} asset=${asset//\//}
# adjust stoploss from percentage profit # adjust stoploss from percentage profit
from_profit=1 from_profit=0.5
if [ -n "$LEVERAGE" ] if [ -n "$LEVERAGE" ]
then then
g_calc "${from_profit}*${LEVERAGE}" g_calc "${from_profit}*${LEVERAGE}"
@ -25,8 +25,14 @@ do
fi fi
# save profit by switching stoploss in profit # save profit by switching stoploss in profit
if [ -n "${p[${asset}_pnl]}" ] && [[ ${p[${asset}_side]} = long ]] if [ -n "${p[${asset}_pnl]}" ]
then then
# what side are we on (long or short)
side=${p[${asset}_side]}
g_echo_note "Checking open $side position for $f_asset"
if g_num_is_higher ${p[${asset}_pnl_percentage]} $from_profit if g_num_is_higher ${p[${asset}_pnl_percentage]} $from_profit
then then
# calculate stoploss price with half of current pnl # calculate stoploss price with half of current pnl
@ -34,19 +40,20 @@ do
stoploss_price=$g_calc_result stoploss_price=$g_calc_result
# check for already existing stoploss # check for already existing stoploss
if [ -n "${o[${asset}_sl_close_long_id]}" ] if [ -n "${o[${asset}_sl_close_${side}_id]}" ]
then then
# do nothing if current stoploss price is already larger/equal then half of current pnl # do nothing if current stoploss price is already larger/equal then half of current pnl
g_num_is_higher_equal ${o[${asset}_sl_close_long_stopprice]} $stoploss_price && continue g_num_is_higher_equal ${o[${asset}_sl_close_${side}_stopprice]} $stoploss_price && continue
# cancel existing stoploss order # cancel existing stoploss order
order_cancel_id "$symbol" "${o[${asset}_sl_close_long_id]}" || continue order_cancel_id "$symbol" "${o[${asset}_sl_close_${side}_id]}" || continue
fi fi
# create new stoploss # create new stoploss
echo "==== New StopLoss for $asset at $stoploss_price" g_echo_ok "==== New StopLoss in profit for $asset at $stoploss_price"
order "$symbol" "${p[${asset}_asset_amount]}" long stoploss "$stoploss_price" order "$symbol" "asset_amount:${p[${asset}_asset_amount]}" ${side} stoploss "$stoploss_price"
fi fi
fi fi
done done