from freqtrade.strategy.interface import IStrategy from typing import Dict, List from hyperopt import hp from functools import reduce from pandas import DataFrame import talib.abstract as ta import freqtrade.vendor.qtpylib.indicators as qtpylib from typing import Dict, List from hyperopt import hp from functools import reduce from pandas import DataFrame, DatetimeIndex, merge import talib.abstract as ta import freqtrade.vendor.qtpylib.indicators as qtpylib import numpy # noqa class ReinforcedSmoothScalp_3(IStrategy): """ this strategy is based around the idea of generating a lot of potentatils buys and make tiny profits on each trade we recommend to have at least 60 parallel trades at any time to cover non avoidable losses """ minimal_roi = { "0": 0.02 } stoploss = -0.8 ticker_interval = '1m' resample_factor = 5 def populate_indicators(self, dataframe: DataFrame) -> DataFrame: dataframe = ReinforcedSmoothScalp.resample(dataframe, self.ticker_interval, self.resample_factor) dataframe['ema_high'] = ta.EMA(dataframe, timeperiod=5, price='high') dataframe['ema_close'] = ta.EMA(dataframe, timeperiod=5, price='close') dataframe['ema_low'] = ta.EMA(dataframe, timeperiod=5, price='low') stoch_fast = ta.STOCHF(dataframe, 5.0, 3.0, 0.0, 3.0, 0.0) dataframe['fastd'] = stoch_fast['fastd'] dataframe['fastk'] = stoch_fast['fastk'] dataframe['adx'] = ta.ADX(dataframe) dataframe['cci'] = ta.CCI(dataframe, timeperiod=20) dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14) dataframe['mfi'] = ta.MFI(dataframe) bollinger = qtpylib.bollinger_bands(dataframe['close'], window=20, stds=2) dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_middleband'] = bollinger['mid'] return dataframe def populate_buy_trend(self, dataframe: DataFrame) -> DataFrame: dataframe.loc[ ( ( (dataframe['open'] < dataframe['ema_low']) & (dataframe['adx'] > 30) & (dataframe['mfi'] < 30) & ( (dataframe['fastk'] < 30) & (dataframe['fastd'] < 30) & (qtpylib.crossed_above(dataframe['fastk'], dataframe['fastd'])) ) & (dataframe['resample_sma'] < dataframe['close']) ) ), 'buy'] = 1 return dataframe def populate_sell_trend(self, dataframe: DataFrame) -> DataFrame: dataframe.loc[ ( ( ( (dataframe['open'] >= dataframe['ema_high']) ) | ( (qtpylib.crossed_above(dataframe['fastk'], 70)) | (qtpylib.crossed_above(dataframe['fastd'], 70)) ) ) & (dataframe['cci'] > 100) ) , 'sell'] = 1 return dataframe @staticmethod def resample(dataframe, interval, factor): df = dataframe.copy() df = df.set_index(DatetimeIndex(df['date'])) ohlc_dict = { 'open': 'first', 'high': 'max', 'low': 'min', 'close': 'last' } df = df.resample(str(int(interval[:-1]) * factor) + 'min', how=ohlc_dict).dropna( how='any') df['resample_sma'] = ta.SMA(df, timeperiod=50, price='close') df = df.drop(columns=['open', 'high', 'low', 'close']) df = df.resample(interval[:-1] + 'min') df = df.interpolate(method='time') df['date'] = df.index df.index = range(len(df)) dataframe = merge(dataframe, df, on='date', how='left') return dataframe