# source: https://raw.githubusercontent.com/rmallarapu-bc/brahma/9287745fc036c2f4c00c586e598290885c2883b9/archive/Base.py
# --- Do not remove these libs ---
from typing import Optional

from pandas import DataFrame
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from datetime import datetime
from freqtrade.persistence import Trade
from freqtrade.strategy import DecimalParameter, IntParameter, IStrategy
from functools import reduce
import logging
import warnings
import pandas as pd
from datetime import datetime, time

log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
warnings.simplefilter(action='ignore', category=pd.errors.PerformanceWarning)

class Github_rmallarapu_bc_brahma__Base__20240229_213751(IStrategy):
    INTERFACE_VERSION: int = 3
    minimal_roi = {"0": 0.5}
    can_short = False

    # Exit criteria
    use_exit_signal = False
    exit_profit_only = False
    ignore_roi_if_entry_signal = True

    # Trailing stoploss
    trailing_stop = True
    trailing_stop_positive = 0.01
    trailing_stop_positive_offset = 0.10
    trailing_only_offset_is_reached = True

    stoploss = -0.05
    timeframe = '1d'

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

    def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
                (dataframe['date'].dt.hour == 0)
            ),
            'enter_long'] = 1

        return dataframe

    def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        dataframe.loc[
            (
                (dataframe['date'].dt.hour == 23)
            ),
            'exit_long'] = 1

        return dataframe


    # =============
    # from freqtrade.persistence import Trade

    # max_entry_position_adjustment = 10
    # position_adjustment_enable = True
    # initial_order_size = 0.5
    # trigger_half_profit = 0.10
    # trigger_double_captial = 0.05


    # def custom_stake_amount(self, pair: str, current_time: datetime, current_rate: float,
    #                         proposed_stake: float, min_stake: Optional[float], max_stake: float,
    #                         leverage: float, entry_tag: Optional[str], side: str,
    #                         **kwargs) -> float:
    #     return proposed_stake * self.initial_order_size

    # def adjust_trade_position(self, trade: Trade, current_time: datetime,
    #                           current_rate: float, current_profit: float,
    #                           min_stake: Optional[float], max_stake: float,
    #                           current_entry_rate: float, current_exit_rate: float,
    #                           current_entry_profit: float, current_exit_profit: float,
    #                           **kwargs) -> Optional[float]:

    #     # Take half of the profit at +5%
    #     if current_profit > self.trigger_half_profit and trade.nr_of_successful_exits == 0:
    #         return -(trade.stake_amount / 2)

    #     # Double captial if the profit is 1%
    #     if current_profit > self.trigger_double_captial and trade.nr_of_successful_entries <= 1:
    #         return 2.0 * trade.stake_amount

    #     # Double captial if the profit is 1%
    #     if current_profit < -self.trigger_half_profit and trade.nr_of_successful_entries <= 1:
    #         return 2.0 * trade.stake_amount

    #     return None


