Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.95 KB | None | 0 0
  1. # https://github.com/hroff-1902/freqtrade-strategies/blob/master/user_data/strategies/berlinguyinca/CombinedBinHAndCluc.py
  2. # --- Do not remove these libs ---
  3. import freqtrade.vendor.qtpylib.indicators as qtpylib
  4. import numpy as np
  5. # --------------------------------
  6. import talib.abstract as ta
  7. from freqtrade.strategy.interface import IStrategy
  8. from pandas import DataFrame
  9.  
  10.  
  11. def bollinger_bands(stock_price, window_size, num_of_std):
  12.     rolling_mean = stock_price.rolling(window=window_size).mean()
  13.     rolling_std = stock_price.rolling(window=window_size).std()
  14.     lower_band = rolling_mean - (rolling_std * num_of_std)
  15.     return np.nan_to_num(rolling_mean), np.nan_to_num(lower_band)
  16.  
  17.  
  18. class CombinedBinHAndCluc(IStrategy):
  19.     minimal_roi = {
  20.         "0": 0.05
  21.     }
  22.     stoploss = -0.05
  23.     ticker_interval = '1m'
  24.  
  25.     use_sell_signal = True
  26.     sell_profit_only = True
  27.     ignore_roi_if_buy_signal = False
  28.  
  29.     def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  30.         # strategy BinHV45
  31.         mid, lower = bollinger_bands(dataframe['close'], window_size=40, num_of_std=2)
  32.         dataframe['lower'] = lower
  33.         dataframe['bbdelta'] = (mid - dataframe['lower']).abs()
  34.         dataframe['closedelta'] = (dataframe['close'] - dataframe['close'].shift()).abs()
  35.         dataframe['tail'] = (dataframe['close'] - dataframe['low']).abs()
  36.         # strategy ClucMay72018
  37.         bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
  38.         dataframe['bb_lowerband'] = bollinger['lower']
  39.         dataframe['bb_middleband'] = bollinger['mid']
  40.         dataframe['ema_slow'] = ta.EMA(dataframe, timeperiod=50)
  41.         dataframe['volume_mean_slow'] = dataframe['volume'].rolling(window=30).mean()
  42.  
  43.         return dataframe
  44.  
  45.     def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  46.         dataframe.loc[
  47.             (  # strategy BinHV45
  48.                     dataframe['lower'].shift().gt(0) &
  49.                     dataframe['bbdelta'].gt(dataframe['close'] * 0.008) &
  50.                     dataframe['closedelta'].gt(dataframe['close'] * 0.0175) &
  51.                     dataframe['tail'].lt(dataframe['bbdelta'] * 0.25) &
  52.                     dataframe['close'].lt(dataframe['lower'].shift()) &
  53.                     dataframe['close'].le(dataframe['close'].shift())
  54.             ) |
  55.             (  # strategy ClucMay72018
  56.                     (dataframe['close'] < dataframe['ema_slow']) &
  57.                     (dataframe['close'] < 0.985 * dataframe['bb_lowerband']) &
  58.                     (dataframe['volume'] < (dataframe['volume_mean_slow'].shift(1) * 20))
  59.             ),
  60.             'buy'
  61.         ] = 1
  62.         return dataframe
  63.  
  64.     def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  65.         dataframe.loc[
  66.             (dataframe['close'] > dataframe['bb_middleband']),
  67.             'sell'
  68.         ] = 1
  69.         return dataframe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement