# source: https://raw.githubusercontent.com/TraderAlice/Auto-Quant/42a914a596630a964e3a443a090ec7a979cf8420/versions/0.1.0/strategy.final.py
"""
Github_TraderAlice_Auto_Quant__strategy_final__20260423_055259 — the single file the agent iterates on.

Baseline: plain RSI mean-reversion.
  - Enter long when RSI(14) < 30
  - Exit long when RSI(14) > 70
  - Hard stoploss at -10%, ROI table exits at any profit above 1%

The agent is free to change ANYTHING in this file — indicators, logic, attributes,
imports — as long as the class still exposes an IStrategy-compatible surface that
FreqTrade's Backtesting can load and run.
"""

from pandas import DataFrame
import talib.abstract as ta

from freqtrade.strategy import IStrategy


class Github_TraderAlice_Auto_Quant__strategy_final__20260423_055259(IStrategy):
    INTERFACE_VERSION = 3

    timeframe = "1h"
    can_short = False

    minimal_roi = {"0": 100}
    stoploss = -0.99

    trailing_stop = False
    process_only_new_candles = True

    use_exit_signal = True
    exit_profit_only = True
    ignore_roi_if_entry_signal = False

    startup_candle_count: int = 30

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[dataframe["rsi"] < 21, "enter_long"] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[dataframe["rsi"] > 62, "exit_long"] = 1
        return dataframe
