# source: https://raw.githubusercontent.com/A5bhinav/tradingBot/3ad340041e788bfd72f1a19a75737662f56dc9c7/docs/examples/freqtrade_SmaMomentum.py
"""Sample Freqtrade strategy — SMA trend + momentum (DRY-RUN ONLY).

Port of the engine's "momentum-core" idea to crypto: be long only when price is above its
long SMA (trend filter) and short-term momentum is positive. Educational; not tuned.
Place this file in Freqtrade's ``user_data/strategies/`` and run in DRY-RUN. No real keys.
"""
from freqtrade.strategy import IStrategy
from pandas import DataFrame
import talib.abstract as ta


class Github_A5bhinav_tradingBot__freqtrade_SmaMomentum__20260706_015407(IStrategy):
    timeframe = "1h"
    can_short = False
    startup_candle_count = 200

    # Conservative exits; dry-run only so these are illustrative.
    minimal_roi = {"0": 0.10, "240": 0.05, "720": 0.02}
    stoploss = -0.10
    trailing_stop = True

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe["sma200"] = ta.SMA(dataframe, timeperiod=200)
        dataframe["mom10"] = ta.MOM(dataframe, timeperiod=10)
        return dataframe

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (dataframe["close"] > dataframe["sma200"])   # uptrend
            & (dataframe["mom10"] > 0)                    # positive momentum
            & (dataframe["volume"] > 0),
            "enter_long",
        ] = 1
        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (dataframe["close"] < dataframe["sma200"]) | (dataframe["mom10"] < 0),
            "exit_long",
        ] = 1
        return dataframe
