# source: https://raw.githubusercontent.com/DerSalvador/freqtrade-helm-chart/a669dc11b640b0eb63aa8f8b51e9f181fd7ee43c/chart/deployed_strategies/Simple.py
# --- Do not remove these libs ---
from freqtrade.strategy.interface import IStrategy
from typing import Dict, List
from functools import reduce
from pandas import DataFrame
# --------------------------------
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib

class Github_DerSalvador_freqtrade_helm_chart__Simple__20260115_122204(IStrategy):
    INTERFACE_VERSION = 3
    "\n\n    author@: Gert Wohlgemuth\n\n    idea:\n        this strategy is based on the book, 'The Github_DerSalvador_freqtrade_helm_chart__Simple__20260115_122204 Strategy' and can be found in detail here:\n\n        https://www.amazon.com/Github_DerSalvador_freqtrade_helm_chart__Simple__20260115_122204-Strategy-Powerful-Trading-Futures-ebook/dp/B00E66QPCG/ref=sr_1_1?ie=UTF8&qid=1525202675&sr=8-1&keywords=the+simple+strategy\n    "
    # Minimal ROI designed for the strategy.
    # adjust based on market conditions. We would recommend to keep it low for quick turn arounds
    # This attribute will be overridden if the config file contains "minimal_roi"
    minimal_roi = {'0': 0.01}
    # Optimal stoploss designed for the strategy
    # This attribute will be overridden if the config file contains "stoploss"
    stoploss = -0.25
    # Optimal timeframe for the strategy
    timeframe = '5m'

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        # MACD
        macd = ta.MACD(dataframe)
        dataframe['macd'] = macd['macd']
        dataframe['macdsignal'] = macd['macdsignal']
        dataframe['macdhist'] = macd['macdhist']
        # RSI
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=7)
        # required for graphing
        bollinger = qtpylib.bollinger_bands(dataframe['close'], window=12, stds=2)
        dataframe['bb_lowerband'] = bollinger['lower']
        dataframe['bb_upperband'] = bollinger['upper']
        dataframe['bb_middleband'] = bollinger['mid']
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:  # over 0
        # over signal
        # pointed up
        # optional filter, need to investigate
        dataframe.loc[(dataframe['macd'] > 0) & (dataframe['macd'] > dataframe['macdsignal']) & (dataframe['bb_upperband'] > dataframe['bb_upperband'].shift(1)) & (dataframe['rsi'] > 70), 'enter_long'] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        # different strategy used for exit points, due to be able to duplicate it to 100%
        dataframe.loc[dataframe['rsi'] > 80, 'exit_long'] = 1
        return dataframe