Skip to content
All library documents

Using ROI Rules to Exit Profitable Bot Positions at Break-Even

Article Strategy library · Author: freqtrade

Summary

This Freqtrade example shows how to wind down open positions without immediately realizing losses. It uses a strategy with no entry or exit signals, leaving exit decisions to the minimal return on investment (ROI) schedule and stop loss. The default schedule seeks at least a small profit early, then permits exit at break-even after a delay; an alternative schedule permits selling at any positive return. The accompanying text suggests switching to this strategy through a restart or configuration reload.

The approach is an operational exit tool, not a method for selecting trades. Its outcome depends on the configured ROI schedule, stop loss, and bot behavior; positions below the permitted return may remain open while waiting to recover. The example also notes that configuration can override the strategy’s ROI setting, so the effective settings should be checked before use. It provides no backtest or performance evidence, and it does not guarantee that positions will close promptly or avoid losses.

Key ideas

  • An empty-signal strategy can let ROI rules manage exits without opening new positions.
  • A staged ROI schedule can allow profitable positions to close first and losing positions to wait for break-even.
  • The example offers alternative ROI schedules for faster exits, including one that permits exits at a loss.
  • Configuration settings may override the strategy’s ROI schedule.
  • This is a bot wind-down procedure, not evidence of a profitable trading strategy.

Tags

Full text
# BreakEven


# BreakEven









author@: lenik

    Sometimes I want to close the bot ASAP, but not have the positions floating around.

    I can "/stopbuy" and wait for the positions to get closed by the bot rules, which is
    waiting for some profit, etc -- this usually takes too long...

    What I would prefer is to close everything that is over 0% profit to avoid the losses.

    Here's a simple strategy with empty buy/sell signals and "minimal_roi = { 0 : 0 }" that
    sells everything already at profit and wait until the positions at loss will come to break
    even point (or the small profit you provide in ROI table).

    You may restart the bot with the new strategy as a command-line parameter.

    Another way would be to specify the original strategy in the config file, then change to
    this one and simply "/reload_config" from the Telegram bot.

## Source (GPL-3.0)

```python
# --- Do not remove these libs ---
from freqtrade.strategy import IStrategy
from pandas import DataFrame

# --------------------------------


class BreakEven(IStrategy):
    """
    author@: lenik

    Sometimes I want to close the bot ASAP, but not have the positions floating around.

    I can "/stopbuy" and wait for the positions to get closed by the bot rules, which is
    waiting for some profit, etc -- this usually takes too long...

    What I would prefer is to close everything that is over 0% profit to avoid the losses.

    Here's a simple strategy with empty buy/sell signals and "minimal_roi = { 0 : 0 }" that
    sells everything already at profit and wait until the positions at loss will come to break
    even point (or the small profit you provide in ROI table).

    You may restart the bot with the new strategy as a command-line parameter.

    Another way would be to specify the original strategy in the config file, then change to
    this one and simply "/reload_config" from the Telegram bot.

    """

    INTERFACE_VERSION: int = 3
    # This attribute will be overridden if the config file contains "minimal_roi"
    minimal_roi = {
        "0": 0.01,      # at least 1% at first
        "10": 0         # after 10min, everything goes
    }

    # This is more radical version that sells everything above the profit level
#    minimal_roi = {
#        "0": 0
#    }

    # And this is basically "/forcesell all", that sells no matter what profit
#    minimal_roi = {
#        "0": -1
#    }

    # Optimal stoploss designed for the strategy
    stoploss = -0.05

    # Optimal timeframe for the strategy
    timeframe = '5m'

    # don't generate any buy or sell signals, everything is handled by ROI and stop_loss
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
            ),
            'enter_long'] = 0
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
            ),
            'exit_long'] = 0
        return dataframe

```

Shown in full with attribution under the source's licence. Licence: GPL-3.0

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.