Using ROI Rules to Close Open Trades Near Break-Even
Summary
This Freqtrade example is an operational strategy for winding down open positions after stopping new buys. It defines no entry or exit signals; instead, a minimal return-on-investment schedule closes trades that reach a small initial profit threshold, then permits closing at break-even after a short wait. A fixed stop-loss also remains active. The comments describe more aggressive variants that close at any nonnegative return or force an exit regardless of profit.
The approach is intended to clear profitable or recovering positions while limiting new exposure, rather than to identify trades or demonstrate an alpha strategy. The code gives settings but no backtest, execution results, or assurance that positions will promptly reach the exit thresholds. Open losing trades may remain until they recover or hit the stop, and configuration overrides can change the stated ROI schedule.
Key ideas
- The strategy creates no new entries and relies on ROI and stop-loss rules for open trades.
- A staged ROI schedule first seeks a small profit and later allows break-even exits.
- More aggressive variants can exit at any profit level or regardless of profit.
- Losing positions may remain open until they recover or trigger the stop-loss.
- The example provides no performance testing or guarantee of timely closure.
Tags
Full text
# BreakEven.py
```py
# --- 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.