# source: https://raw.githubusercontent.com/illufluo/TradeFoundry/30ff3150075ee3f2babcea5a678f466159133de6/user_data/strategies/BaselineTrend.py
# directory_url: https://github.com/illufluo/TradeFoundry/blob/main/user_data/strategies/
# User: illufluo
# Repository: TradeFoundry
# --------------------from pandas import DataFrame

from freqtrade.strategy import IStrategy


class Github_illufluo_TradeFoundry__BaselineTrend__20261004_163521(IStrategy):
    """System validation only: SMA20/SMA50 trend, long and short at default 1x."""

    INTERFACE_VERSION = 3
    timeframe = "1h"
    can_short = True
    process_only_new_candles = True
    startup_candle_count = 50
    minimal_roi = {}
    stoploss = -0.05
    use_exit_signal = True

    # FreqUI reads this from the active strategy; UI/API config stays generic.
    plot_config = {
        "main_plot": {
            "sma_fast": {"color": "#f59e0b"},
            "sma_slow": {"color": "#3b82f6"},
        },
        "subplots": {},
    }

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe["sma_fast"] = dataframe["close"].rolling(20).mean()
        dataframe["sma_slow"] = dataframe["close"].rolling(50).mean()
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        active = dataframe["volume"] > 0
        dataframe.loc[
            active & (dataframe["sma_fast"] > dataframe["sma_slow"]),
            ["enter_long", "enter_tag"],
        ] = (1, "sma_up")
        dataframe.loc[
            active & (dataframe["sma_fast"] < dataframe["sma_slow"]),
            ["enter_short", "enter_tag"],
        ] = (1, "sma_down")
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        active = dataframe["volume"] > 0
        dataframe.loc[
            active & (dataframe["sma_fast"] < dataframe["sma_slow"]),
            ["exit_long", "exit_tag"],
        ] = (1, "trend_reversed")
        dataframe.loc[
            active & (dataframe["sma_fast"] > dataframe["sma_slow"]),
            ["exit_short", "exit_tag"],
        ] = (1, "trend_reversed")
        return dataframe
