# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement # flake8: noqa: F401 # isort: skip_file # --- Standard Library Imports --- from datetime import datetime from typing import Optional, Union # --- Third Party Imports --- import numpy as np import pandas as pd from pandas import DataFrame # --- Freqtrade Imports --- from freqtrade.strategy import ( IStrategy, IntParameter ) # --- Technical Analysis Library Imports --- import talib.abstract as ta # --- Custom Strategy Class --- class TrendReversalLabelingStrategy(IStrategy): """ Strategy for labeling trend reversals in trading data for machine learning tasks. """ INTERFACE_VERSION = 3 timeframe = '1m' can_short: bool = True minimal_roi = {"60": 10000} stoploss = -0.003 # 0.3% stoploss trailing_stop = True startup_candle_count: int = 50 def informative_pairs(self): """ Define pairs for additional, informative data. Currently returns an empty list. """ return [] def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Add all necessary technical indicators to the DataFrame. Currently includes Triple Exponential Moving Average (TEMA). """ tema_period = 50 dataframe['tema'] = ta.TEMA(dataframe['close'], timeperiod=tema_period) dataframe['trend'] = np.where(dataframe['tema'] > dataframe['tema'].shift(1), 'UP', 'DOWN') dataframe['trend_duration'] = (dataframe['trend'] != dataframe['trend'].shift(1)).cumsum() dataframe['trend_count'] = dataframe.groupby('trend_duration').cumcount() + 1 return dataframe def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Populate the entry signals based on trend reversal logic. Signals for long and short entries based on trend direction changes. """ dataframe.loc[ (dataframe['trend'] == 'UP') & (dataframe['trend'].shift(1) == 'DOWN'), 'enter_long'] = 1 dataframe.loc[ (dataframe['trend'] == 'DOWN') & (dataframe['trend'].shift(1) == 'UP'), 'enter_short'] = 1 return dataframe def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: """ Populate the exit signals for the strategy. This method is left empty for further customization. """ return dataframe