# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement

# --- Do not remove these libs ---
import numpy as np  # noqa
import pandas as pd  # noqa
from pandas import DataFrame

from freqtrade.strategy import IStrategy, CategoricalParameter, DecimalParameter, IntParameter

# --------------------------------
# Add your lib to import here
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib



#----------------------------------
#
#
# created by viksal1982 / viktors.s@gmail.com
# discord: https://discord.gg/MA9v74M
#
#
#-----------------------------------

class TakePUMP_052021(IStrategy):
    
    INTERFACE_VERSION = 2
    
    # # Buy hyperspace params:
    buy_params = {
        "proc_buy": 1.153,
        "rolling_day_buy": 29,
        "rsi_buy": 65,
        "rsi_period_buy": 41,
        "shift_days_buy": 50,
    }

    # Sell hyperspace params:
    sell_params = {
        "rsi_period_sell": 38,
        "rsi_sell": 67,
    }

    # ROI table:
    minimal_roi = {
        "0": 0.112,
        "27": 0.042,
        "56": 0.025,
        "149": 0
    }

    # Stoploss:
    stoploss = -0.279


    rsi_period_buy  = IntParameter(5, 80, default=buy_params['rsi_period_buy'], space='buy')
    rsi_buy  = IntParameter(5, 80, default=buy_params['rsi_buy'], space='buy')
    proc_buy = DecimalParameter(0.8, 1.8, default=buy_params['proc_buy'], space='buy')
    rolling_day_buy  = IntParameter(5, 80, default=buy_params['rolling_day_buy'], space='buy')
    shift_days_buy  = IntParameter(5, 80, default=buy_params['shift_days_buy'], space='buy')


    rsi_period_sell = IntParameter(5, 80, default=sell_params['rsi_period_sell'], space='sell')
    rsi_sell = IntParameter(5, 80, default=sell_params['rsi_sell'], space='sell')

    


    # Trailing stoploss
    trailing_stop = False


    # Optimal timeframe for the strategy.
    timeframe = '5m'

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

    # These values can be overridden in the "ask_strategy" section in the config.
    use_sell_signal = True
    sell_profit_only = False
    ignore_roi_if_buy_signal = False

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

    # Optional order type mapping.
    order_types = {
        'buy': 'limit',
        'sell': 'limit',
        'stoploss': 'market',
        'stoploss_on_exchange': False
    }

    # Optional order time in force.
    order_time_in_force = {
        'buy': 'gtc',
        'sell': 'gtc'
    }
    

    def informative_pairs(self):
        return []

    def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
       
        dataframe['rsi_period_buy']  = ta.RSI(dataframe, timeperiod=self.rsi_period_buy.value)
        dataframe['rsi_period_sell']  = ta.RSI(dataframe, timeperiod=self.rsi_period_sell.value)
        return dataframe

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

        dataframe.loc[
            (
                ((dataframe['high'].shift(self.shift_days_buy.value).rolling(self.rolling_day_buy.value).max() / dataframe['low']) > self.proc_buy.value) &
                (dataframe['rsi_period_buy'] < self.rsi_buy.value) &
                (dataframe['volume'] > 0)  
            ),
            'buy'] = 1

        return dataframe

    def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
        
        dataframe.loc[
            (
               (dataframe['rsi_period_sell']  > self.rsi_sell.value) &
               (dataframe['volume'] > 0) 
            ),
            'sell'] = 1
        return dataframe
    
