diff --git a/NostalgiaForInfinityX.py b/NostalgiaForInfinityX.py index 920e48ee80..a5ab4e95c7 100644 --- a/NostalgiaForInfinityX.py +++ b/NostalgiaForInfinityX.py @@ -15,6 +15,7 @@ from typing import Dict from freqtrade.persistence import Trade from datetime import datetime, timedelta +from decimal import Decimal from technical.util import resample_to_interval, resampled_merge from technical.indicators import RMI, zema, VIDYA, ichimoku import time @@ -110,7 +111,7 @@ class NostalgiaForInfinityX(IStrategy): INTERFACE_VERSION = 2 def version(self) -> str: - return "v11.0.269" + return "v11.0.270" # ROI table: minimal_roi = { @@ -127,6 +128,8 @@ def version(self) -> str: use_custom_stoploss = False + custom_info = {} + # Optimal timeframe for the strategy. timeframe = '5m' res_timeframe = 'none' @@ -2293,6 +2296,10 @@ def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: f else: return proposed_stake + def calc_profit_ratio2(self, open_rate: float, current_rate: float, trade: Trade) ->float: + return float(( Decimal(1-trade.fee_close)* Decimal(current_rate) )/ + (Decimal(1+trade.fee_open)* Decimal(open_rate) )-1) + def adjust_trade_position(self, trade: Trade, current_time: datetime, current_rate: float, current_profit: float, min_stake: float, max_stake: float, **kwargs): @@ -2317,6 +2324,21 @@ def adjust_trade_position(self, trade: Trade, current_time: datetime, if (self.position_adjustment_enable == False) or (current_profit > -0.03): return None + filled_buys = trade.select_filled_orders('buy') + count_of_buys = len(filled_buys) + max_profit2=self.custom_info.get(trade.pair,0) + last_buy_order = filled_buys[-1] + last_open_rate = last_buy_order.average or last_buy_order.price + current_profit2=self.calc_profit_ratio2(last_open_rate, current_rate, trade) + # if current_time.second %10 == 0: log.info('partial_sell ' + ', '.join(map(str,(trade.pair, max_profit2, current_profit2, last_open_rate, current_rate)))) + if max_profit2.005-0.0025*(count_of_buys-2) and current_profit2 > 0 and count_of_buys > 1: + self.custom_info[trade.pair]=0 + last_stake_amt=last_buy_order.amount + return -last_stake_amt + + if count_of_buys > self.max_rebuy_orders and self.dp.runmode.value not in ('backtest','dry_run'): + return dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe) last_candle = dataframe.iloc[-1].squeeze() previous_candle = dataframe.iloc[-2].squeeze() @@ -2328,12 +2350,9 @@ def adjust_trade_position(self, trade: Trade, current_time: datetime, ): return None - filled_buys = trade.select_filled_orders('buy') - count_of_buys = len(filled_buys) - if (count_of_buys == 1): if ( - (current_profit > -0.08) + (current_profit > -0.03) or ( (last_candle['crsi'] < 12.0) ) @@ -2341,7 +2360,7 @@ def adjust_trade_position(self, trade: Trade, current_time: datetime, return None elif (count_of_buys == 2): if ( - (current_profit > -0.14) + (current_profit > -0.04) or ( (last_candle['crsi'] < 20.0) or (last_candle['crsi_1h'] < 11.0) @@ -2362,17 +2381,18 @@ def adjust_trade_position(self, trade: Trade, current_time: datetime, # Log if the last candle triggered a buy signal, even if max rebuys reached if last_candle['buy'] == 1 and self.dp.runmode.value in ('backtest','dry_run'): log.info(f"Rebuy: a buy tag found for pair {trade.pair}") + if count_of_buys > self.max_rebuy_orders: + return # Maximum 2 rebuys. Half the stake of the original. - if 0 < count_of_buys <= self.max_rebuy_orders: - try: - # This returns first order stake size - stake_amount = filled_buys[0].cost - # This then calculates current safety order size - stake_amount = stake_amount * (0.35 + (count_of_buys * 0.005)) - return stake_amount - except Exception as exception: - return None + try: + # This returns first order stake size + stake_amount = filled_buys[0].cost + # This then calculates current safety order size + stake_amount = stake_amount * (0.35 + (count_of_buys * 0.005)) + return stake_amount + except Exception as exception: + return None return None