# source: https://raw.githubusercontent.com/OlegB333/algo-trading-academy/e14d3df79992b3558c15ee24ada5003a897d6e51/user_data/strategies/AcademySampleStrategy.py
# Freqtrade Strategy Template
# This is a minimal sample strategy for the Algo Trading Academy course.
# Use this as a starting point to create your own strategies.

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


class Github_OlegB333_algo_trading_academy__AcademySampleStrategy__20260412_035107(IStrategy):
    """
    Sample strategy using SMA crossover.
    This is a teaching example — NOT for live trading.
    """

    INTERFACE_VERSION = 3

    # Minimal ROI table
    minimal_roi = {
        "60": 0.01,   # 1% profit after 60 minutes
        "30": 0.02,   # 2% profit after 30 minutes
        "0": 0.04     # 4% profit immediately
    }

    # Stoploss
    stoploss = -0.10  # 10% stoploss

    # Timeframe
    timeframe = '1h'

    # Run "populate_indicators()" only for new candle
    process_only_new_candles = True

    # Number of candles the strategy requires before producing valid signals
    startup_candle_count: int = 30

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        if dataframe.empty:
            return dataframe

        """Add technical indicators to the dataframe."""
        dataframe['sma_fast'] = ta.SMA(dataframe, timeperiod=10)
        dataframe['sma_slow'] = ta.SMA(dataframe, timeperiod=30)
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """Define entry (buy) conditions."""
        dataframe.loc[
            (
                (dataframe['sma_fast'] > dataframe['sma_slow']) &  # Fast SMA above slow SMA
                (dataframe['volume'] > 0)
            ),
            'enter_long'] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        """Define exit (sell) conditions."""
        dataframe.loc[
            (
                (dataframe['sma_fast'] < dataframe['sma_slow']) &  # Fast SMA below slow SMA
                (dataframe['volume'] > 0)
            ),
            'exit_long'] = 1
        return dataframe
