# source: https://raw.githubusercontent.com/scaled-agents/TRADE-md/05171c4570c5c37979f5ae015fade524ac37510f/examples/bbands-rsi/BbandsRsi.py
"""
Auto-generated by trade-md from bbands-rsi@0.1.0.

DO NOT EDIT BY HAND - modify TRADE.md and recompile.
Source strategy: bbands-rsi
Version:         0.1.0
Thesis:          Classic mean-reversion: enter when price is both RSI-oversold (< 30) and below the
"""
from __future__ import annotations

from pandas import DataFrame
import talib.abstract as ta
from freqtrade.strategy import IStrategy, merge_informative_pair


class Github_scaled_agents_TRADE_md__BbandsRsi__20260425_035203(IStrategy):
    """Compiled from TRADE.md. Parent: none"""

    INTERFACE_VERSION = 3
    timeframe = '5m'
    stoploss = -0.1
    minimal_roi = {"0": 0.15, "60": 0.05, "120": 0.01}
    trailing_stop = False
    startup_candle_count = 70
    max_open_trades = 3
    process_only_new_candles = True
    can_short = False

    @property
    def protections(self):
        return []

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe['rsi_14'] = ta.RSI(dataframe, timeperiod=14)
        dataframe['bb_lower_20_2'] = ta.BBANDS(dataframe, timeperiod=20, nbdevup=2, nbdevdn=2)['lowerband']

        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            ((dataframe['rsi_14'] < 30) & (dataframe['close'] < dataframe['bb_lower_20_2']) & (dataframe['volume'] > 0)),
            ['enter_long', 'enter_tag']
        ] = (1, 'rsi_oversold_below_bb')
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (dataframe['rsi_14'] > 70),
            ['exit_long', 'exit_tag']
        ] = (1, 'rsi_overbought')
        return dataframe
