freqtrade icon indicating copy to clipboard operation
freqtrade copied to clipboard

Change per trade positions with current rate

Open Zzzyc0528 opened this issue 2 months ago • 7 comments

Describe your environment

  • Operating system: Windows
  • Python Version: 3.12.7 (python -V)
  • CCXT version: 4.4.31 (pip freeze | grep ccxt)
  • Freqtrade Version: 2024.11-dev-b637e7dd (freqtrade -V or docker compose run --rm freqtrade -V for Freqtrade running in docker)

Your question

Ask the question you have not been able to find an answer in the Documentation

HI, I want to sell half or a quarter of the initial trade amount for each trade when the current price meets certain conditions. But once I change the initial wallet amount, I get different backtest results. I thought there must be something wrong with the code. The code is wrote based on the documentation's example. But I cannot find more information in the documentation. I would be really grateful for your help!

def adjust_trade_position(self, trade: Trade, current_time: datetime,
                            current_rate: float, current_profit: float,
                            min_stake: float | None, max_stake: float,
                            current_entry_rate: float, current_exit_rate: float,
                            current_entry_profit: float, current_exit_profit: float,
                            **kwargs
                            ) -> float | None | tuple[float | None, str | None]:

        dataframe, _ = self.dp.get_analyzed_dataframe(trade.pair, self.timeframe)
        last_candle = dataframe.iloc[-1].squeeze()
        width_candle=last_candle["resistance"]-last_candle["support"]
        filled_entries = trade.select_filled_orders(trade.entry_side)
        stake_amount = filled_entries[0].stake_amount_filled 
        trailing_stop = last_candle["resistance"]
        if current_rate >= 1*width_candle+last_candle["resistance"]:
            trailing_stop = 1*width_candle+last_candle["resistance"]

        if current_rate >= 1*width_candle+last_candle["resistance"]:
            return  -0.5* stake_amount
        if  current_rate <0.98*last_candle["resistance"]:
            return  -0.25* stake_amount

Zzzyc0528 avatar Dec 10 '24 13:12 Zzzyc0528