diff --git a/strategies/example_manage_positions.strategy.sh b/strategies/example_manage_positions.strategy.sh index afcbe88..f16f4e3 100644 --- a/strategies/example_manage_positions.strategy.sh +++ b/strategies/example_manage_positions.strategy.sh @@ -13,18 +13,40 @@ get_position_array # go through trading symbols for symbol in ${f_symbols_array_trade[@]} do - echo "==== XXXXX $symbol" + asset=${symbol//:$CURRENCY/} + asset=${asset//\//} + + # adjust stoploss from percentage profit + from_profit=1 + if [ -n "$LEVERAGE" ] + then + g_calc "${from_profit}*${LEVERAGE}" + from_profit=$g_calc_result + fi + + # save profit by switching stoploss in profit + if [ -n "${p[${asset}_pnl]}" ] && [[ ${p[${asset}_side]} = long ]] + then + if g_num_is_higher ${p[${asset}_pnl_percentage]} $from_profit + then + # calculate stoploss price with half of current pnl + g_calc "${p[${asset}_current_price]}-((${p[${asset}_current_price]}-${p[${asset}_entry_price]})/2)" + stoploss_price=$g_calc_result + + # check for already existing stoploss + if [ -n "${o[${asset}_sl_close_long_id]}" ] + then + # 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 + # cancel existing stoploss order + order_cancel_id "$symbol" "${o[${asset}_sl_close_long_id]}" || continue + fi + + # create new stoploss + echo "==== New StopLoss for $asset at $stoploss_price" + order "$symbol" 0 long stoploss "$stoploss_price" + + fi + fi done -##### 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 ist remove the next line with return 0 -#return 0 - - -# create stoploss order -#print(exchange.createOrder(symbol='XRP/USDT:USDT', type='Stop', side='sell', amount='0', price='None', params={'posSide': 'Long', 'stopPx':0.5})) -#print(exchange.createOrder(symbol='XRP/USDT:USDT', type='Stop', amount='0', side='sell', price='None', params={'posSide': 'Long', 'stopPx': 0.5})) - -# edit stoploss -#print(exchange.editOrder(id='debc0df8-10c7-4cfd-95f7-b4de9cc60332', symbol='XRP/USDT:USDT', type='Stop', side='sell', amount='101', params={'stopLossPrice': 0.48})) -