# source: https://raw.githubusercontent.com/Bananajoexxc/Solana-Bot-2/dc810625f9b8042aa5b996a0129ecaeacca71129/user_data/strategies/SolanaSimpleMomentum.py
from freqtrade.strategy import IStrategy, DecimalParameter
from pandas import DataFrame
import talib.abstract as ta


class Github_Bananajoexxc_Solana_Bot_2__SolanaSimpleMomentum__20260123_152910(IStrategy):
    """
    Ultra-Simple Momentum Strategy - High Returns
    
    Logic: Buy dips in uptrend, sell rallies in downtrend
    - RSI oversold in bullish market = BUY
    - RSI overbought = SELL
    """
    
    minimal_roi = {
        "0": 0.222,    # 22.2% target
        "141": 0.188,  # 18.8% after 2.3 hours
        "455": 0.059,  # 5.9% after 7.5 hours
        "1595": 0      # Breakeven after 26 hours
    }
    
    stoploss = -0.156  # 15.6% stop with 3x leverage = 46.8% risk
    
    trailing_stop = False
    trailing_stop_positive = 0.02
    trailing_stop_positive_offset = 0.06
    trailing_only_offset_is_reached = True
    
    timeframe = '1h'
    
    # Optimizable parameters (optimized via hyperopt)
    rsi_buy = DecimalParameter(20, 35, default=20, space='buy')
    rsi_sell = DecimalParameter(70, 85, default=79, space='sell')
    
    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """Minimal indicators"""
        dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
        dataframe['ema'] = ta.EMA(dataframe, timeperiod=50)
        dataframe['volume_ma'] = dataframe['volume'].rolling(20).mean()
        return dataframe
    
    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """Buy: RSI deeply oversold + above-average volume"""
        dataframe.loc[
            (
                (dataframe['rsi'] < self.rsi_buy.value) &
                (dataframe['volume'] > dataframe['volume_ma'] * 1.2)  # Above-average volume
            ),
            'enter_long'] = 1
        return dataframe
    
    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """Sell: RSI overbought"""
        dataframe.loc[
            (
                (dataframe['rsi'] > self.rsi_sell.value)
            ),
            'exit_long'] = 1
        return dataframe
