# source: https://raw.githubusercontent.com/DerSalvador/freqtrade-helm-chart/a669dc11b640b0eb63aa8f8b51e9f181fd7ee43c/chart/deployed_strategies/binance-futures-k8s-namespace/ema.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 datetime
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy as np  # noqa

class Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204(IStrategy):
    INTERFACE_VERSION = 3
    max_open_trades = 10
    stake_amount = 50
    # Minimal ROI designed for the strategy.
    # This attribute will be overridden if the config file contains "minimal_roi"
    # Optimal stoploss designed for the strategy
    # This attribute will be overridden if the config file contains "stoploss"
    stoploss = -1
    minimal_roi = {'0': 10}
    # Optimal timeframe for the strategy
    timeframe = '5m'
    # trailing stoploss
    trailing_stop = False
    trailing_stop_positive = 0.1
    trailing_stop_positive_offset = 0.2
    # run "populate_indicators" only for new candle
    process_only_new_candles = False
    # Experimental settings (configuration will overide these if set)
    use_exit_signal = True
    exit_profit_only = False
    ignore_roi_if_entry_signal = False
    # Optional order type mapping
    order_types = {'entry': 'limit', 'exit': 'limit', 'stoploss': 'market', 'stoploss_on_exchange': False}

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Adds several different TA indicators to the given DataFrame
        Performance Note: For the best performance be frugal on the number of indicators
        you are using. Let uncomment only the indicator you are using in your strategies
        or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
        """
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222046'] = ta.EMA(dataframe, timeperiod=9)
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220424'] = ta.EMA(dataframe, timeperiod=18)
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220411'] = ta.EMA(dataframe, timeperiod=32)
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220425'] = ta.EMA(dataframe, timeperiod=64)
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'] = dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222046'] - dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220424']
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222042'] = dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220411'] - dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_12220425']
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'] = dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'] * 0.6 + dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222042'] * 0.5
        dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222042'] = ta.SMA(dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'], timeperiod=29)
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the entry signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with entry column
        """
        dataframe.loc[qtpylib.crossed_above(dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'], dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222042']), 'entry'] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """
        Based on TA indicators, populates the exit signal for the given dataframe
        :param dataframe: DataFrame
        :return: DataFrame with entry column
        """
        dataframe.loc[qtpylib.crossed_below(dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_122204'], dataframe['Github_DerSalvador_freqtrade_helm_chart__ema__20260115_1222042']), 'exit'] = 1
        return dataframe