From 8cdae5f56eb02dd7a6541d7016bfff4baa71b45f Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 28 Dec 2024 15:26:27 +0100 Subject: [PATCH] feat: add plot_annotations interface --- freqtrade/strategy/interface.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/freqtrade/strategy/interface.py b/freqtrade/strategy/interface.py index 73d3acfa9..3f3dd83f4 100644 --- a/freqtrade/strategy/interface.py +++ b/freqtrade/strategy/interface.py @@ -26,6 +26,7 @@ from freqtrade.enums import ( ) from freqtrade.exceptions import OperationalException, StrategyError from freqtrade.exchange import timeframe_to_minutes, timeframe_to_next_date, timeframe_to_seconds +from freqtrade.ft_types import MarkArea from freqtrade.misc import remove_entry_exit_signals from freqtrade.persistence import Order, PairLocks, Trade from freqtrade.strategy.hyper import HyperStrategyMixin @@ -734,6 +735,23 @@ class IStrategy(ABC, HyperStrategyMixin): """ return None + def plot_annotations( + self, pair: str, start_date: datetime, end_date: datetime, dataframe: DataFrame, **kwargs + ) -> list[MarkArea]: + """ + Retrieve area annotations for a chart. + Must be returned as array, with label, start, end, y_start, y_end and color. + All settings are optional - though it usually makes sense to include either "start and end" + or "y_start and y_end" for either horizontal or vertical plots (or all 4 for boxes). + :param pair: Pair that's currently analyzed + :param start_date: Start date of the chart data being requested + :param end_date: End date of the chart data being requested + :param dataframe: DataFrame with the analyzed data for the chart + :param **kwargs: Ensure to keep this here so updates to this won't break your strategy. + :return: List of MarkArea objects + """ + return [] + def populate_any_indicators( self, pair: str, @@ -1669,3 +1687,16 @@ class IStrategy(ABC, HyperStrategyMixin): if "exit_long" not in df.columns: df = df.rename({"sell": "exit_long"}, axis="columns") return df + + def ft_plot_annotations(self, pair: str, dataframe: DataFrame) -> list[MarkArea]: + """ + Internal wrapper around plot_dataframe + """ + if len(dataframe) > 0: + return strategy_safe_wrapper(self.plot_annotations)( + pair=pair, + dataframe=dataframe, + start_date=dataframe.iloc[0]["date"].to_pydatetime(), + end_date=dataframe.iloc[-1]["date"].to_pydatetime(), + ) + return []