Advertisement
Guest User

Untitled

a guest
Jun 28th, 2019
693
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.98 KB | None | 0 0
  1.  
  2. # --- Do not remove these libs ---
  3. from freqtrade.strategy.interface import IStrategy
  4. from pandas import DataFrame
  5. # --------------------------------
  6.  
  7. # Add your lib to import here
  8. import talib.abstract as ta
  9. import freqtrade.vendor.qtpylib.indicators as qtpylib
  10. import numpy # noqa
  11. # This class is a sample. Feel free to customize it.
  12. class hullmachop(IStrategy):
  13. __test__ = False # pytest expects to find tests here because of the name
  14. """
  15. This is a test strategy to inspire you.
  16. More information in https://github.com/freqtrade/freqtrade/blob/develop/docs/bot-optimization.md
  17.  
  18. You can:
  19. :return: a Dataframe with all mandatory indicators for the strategies
  20. - Rename the class name (Do not forget to update class_name)
  21. - Add any methods you want to build your strategy
  22. - Add any lib you need to build your strategy
  23.  
  24. You must keep:
  25. - the lib in the section "Do not remove these libs"
  26. - the prototype for the methods: minimal_roi, stoploss, populate_indicators, populate_buy_trend,
  27. populate_sell_trend, hyperopt_space, buy_strategy_generator
  28. """
  29.  
  30. # Minimal ROI designed for the strategy.
  31. # This attribute will be overridden if the config file contains "minimal_roi"
  32. minimal_roi = {
  33. #"0": 0.15
  34. "0":0.15
  35. }
  36.  
  37. # Optimal stoploss designed for the strategy
  38. # This attribute will be overridden if the config file contains "stoploss"
  39. stoploss = -0.1
  40.  
  41. # trailing stoploss
  42. trailing_stop = False
  43. trailing_stop_positive = 0.10
  44. trailing_stop_positive_offset = 0.25 # Disabled / not configured
  45. trailing_only_offset_is_reached = True
  46.  
  47. # Optimal ticker interval for the strategy
  48. ticker_interval = '12h'
  49.  
  50. # run "populate_indicators" only for new candle
  51. process_only_new_candles = True
  52.  
  53. # Experimental settings (configuration will overide these if set)
  54. use_sell_signal = True
  55. sell_profit_only = False
  56. ignore_roi_if_buy_signal = False
  57.  
  58. # Optional order type mapping
  59. order_types = {
  60. 'buy': 'market',
  61. 'sell': 'market',
  62. 'stoploss': 'market',
  63. 'stoploss_on_exchange': False
  64. }
  65.  
  66. # Optional order time in force
  67. order_time_in_force = {
  68. 'buy': 'gtc',
  69. 'sell': 'gtc'
  70. }
  71.  
  72. def informative_pairs(self):
  73. """
  74. Define additional, informative pair/interval combinations to be cached from the exchange.
  75. These pair/interval combinations are non-tradeable, unless they are part
  76. of the whitelist as well.
  77. For more information, please consult the documentation
  78. :return: List of tuples in the format (pair, interval)
  79. Sample: return [("ETH/USDT", "5m"),
  80. ("BTC/USDT", "15m"),
  81. ]
  82. """
  83. return []
  84.  
  85. def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  86. """
  87. Adds several different TA indicators to the given DataFrame
  88.  
  89. Performance Note: For the best performance be frugal on the number of indicators
  90. you are using. Let uncomment only the indicator you are using in your strategies
  91. or your hyperopt configuration, otherwise you will waste your memory and CPU usage.
  92. :param dataframe: Raw data from the exchange and parsed by parse_ticker_dataframe()
  93. :param metadata: Additional information, like the currently traded pair
  94. :return: a Dataframe with all mandatory indicators for the strategies
  95. """
  96.  
  97. """dataframe['adx'] = ta.ADX(dataframe)
  98.  
  99. # Chopiness
  100. """
  101. dataframe['chop'] = qtpylib.choppiness(dataframe)
  102. dataframe['hullma'] = qtpylib.hma(dataframe['close'],36)
  103.  
  104. """
  105. # Awesome oscillator
  106. dataframe['ao'] = qtpylib.awesome_oscillator(dataframe)
  107.  
  108. # Commodity Channel Index: values Oversold:<-100, Overbought:>100
  109. dataframe['cci'] = ta.CCI(dataframe)
  110.  
  111. # MACD
  112. macd = ta.MACD(dataframe)
  113. dataframe['macd'] = macd['macd']
  114. dataframe['macdsignal'] = macd['macdsignal']
  115. dataframe['macdhist'] = macd['macdhist']
  116.  
  117. # MFI
  118. dataframe['mfi'] = ta.MFI(dataframe)
  119.  
  120. # Minus Directional Indicator / Movement
  121. dataframe['minus_dm'] = ta.MINUS_DM(dataframe)
  122. dataframe['minus_di'] = ta.MINUS_DI(dataframe)
  123.  
  124. # Plus Directional Indicator / Movement
  125. dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
  126. dataframe['plus_di'] = ta.PLUS_DI(dataframe)
  127. dataframe['minus_di'] = ta.MINUS_DI(dataframe)
  128.  
  129. # ROC
  130. dataframe['roc'] = ta.ROC(dataframe)
  131.  
  132. # RSI
  133. dataframe['rsi'] = ta.RSI(dataframe)
  134. # Inverse Fisher transform on RSI, values [-1.0, 1.0] (https://goo.gl/2JGGoy)
  135. rsi = 0.1 * (dataframe['rsi'] - 50)
  136. dataframe['fisher_rsi'] = (numpy.exp(2 * rsi) - 1) / (numpy.exp(2 * rsi) + 1)
  137.  
  138. # Inverse Fisher transform on RSI normalized, value [0.0, 100.0] (https://goo.gl/2JGGoy)
  139. dataframe['fisher_rsi_norma'] = 50 * (dataframe['fisher_rsi'] + 1)
  140.  
  141. # Stoch
  142. stoch = ta.STOCH(dataframe)
  143. dataframe['slowd'] = stoch['slowd']
  144. dataframe['slowk'] = stoch['slowk']
  145.  
  146. # Stoch fast
  147. stoch_fast = ta.STOCHF(dataframe)
  148. dataframe['fastd'] = stoch_fast['fastd']
  149. dataframe['fastk'] = stoch_fast['fastk']
  150.  
  151. # Stoch RSI
  152. stoch_rsi = ta.STOCHRSI(dataframe)
  153. dataframe['fastd_rsi'] = stoch_rsi['fastd']
  154. dataframe['fastk_rsi'] = stoch_rsi['fastk']
  155.  
  156. # Overlap Studies
  157. # ------------------------------------
  158.  
  159. # Bollinger bands
  160. bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
  161. dataframe['bb_lowerband'] = bollinger['lower']
  162. dataframe['bb_middleband'] = bollinger['mid']
  163. dataframe['bb_upperband'] = bollinger['upper']
  164.  
  165. # EMA - Exponential Moving Average
  166. """
  167. dataframe['ema25'] = ta.EMA(dataframe, timeperiod=25)
  168. dataframe['ema7'] = ta.EMA(dataframe, timeperiod=7)
  169. """
  170. dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
  171. dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
  172. dataframe['ema100'] = ta.EMA(dataframe, timeperiod=100)
  173.  
  174. # SAR Parabol
  175. dataframe['sar'] = ta.SAR(dataframe)
  176. # TEMA - Triple Exponential Moving Average
  177. dataframe['tema'] = ta.TEMA(dataframe, timeperiod=9)
  178.  
  179. # Cycle Indicator
  180. # ------------------------------------
  181. # Hilbert Transform Indicator - SineWave
  182. hilbert = ta.HT_SINE(dataframe)
  183. dataframe['htsine'] = hilbert['sine']
  184. dataframe['htleadsine'] = hilbert['leadsine']
  185.  
  186. # Pattern Recognition - Bullish candlestick patterns
  187. # ------------------------------------
  188. # Hammer: values [0, 100]
  189. dataframe['CDLHAMMER'] = ta.CDLHAMMER(dataframe)
  190. # Inverted Hammer: values [0, 100]
  191. dataframe['CDLINVERTEDHAMMER'] = ta.CDLINVERTEDHAMMER(dataframe)
  192. # Dragonfly Doji: values [0, 100]
  193. dataframe['CDLDRAGONFLYDOJI'] = ta.CDLDRAGONFLYDOJI(dataframe)
  194. # Piercing Line: values [0, 100]
  195. dataframe['CDLPIERCING'] = ta.CDLPIERCING(dataframe) # values [0, 100]
  196. # Morningstar: values [0, 100]
  197. dataframe['CDLMORNINGSTAR'] = ta.CDLMORNINGSTAR(dataframe) # values [0, 100]
  198. # Three White Soldiers: values [0, 100]
  199. dataframe['CDL3WHITESOLDIERS'] = ta.CDL3WHITESOLDIERS(dataframe) # values [0, 100]
  200.  
  201. # Pattern Recognition - Bearish candlestick patterns
  202. # ------------------------------------
  203. # Hanging Man: values [0, 100]
  204. dataframe['CDLHANGINGMAN'] = ta.CDLHANGINGMAN(dataframe)
  205. # Shooting Star: values [0, 100]
  206. dataframe['CDLSHOOTINGSTAR'] = ta.CDLSHOOTINGSTAR(dataframe)
  207. # Gravestone Doji: values [0, 100]
  208. dataframe['CDLGRAVESTONEDOJI'] = ta.CDLGRAVESTONEDOJI(dataframe)
  209. # Dark Cloud Cover: values [0, 100]
  210. dataframe['CDLDARKCLOUDCOVER'] = ta.CDLDARKCLOUDCOVER(dataframe)
  211. # Evening Doji Star: values [0, 100]
  212. dataframe['CDLEVENINGDOJISTAR'] = ta.CDLEVENINGDOJISTAR(dataframe)
  213. # Evening Star: values [0, 100]
  214. dataframe['CDLEVENINGSTAR'] = ta.CDLEVENINGSTAR(dataframe)
  215.  
  216. # Pattern Recognition - Bullish/Bearish candlestick patterns
  217. # ------------------------------------
  218. # Three Line Strike: values [0, -100, 100]
  219. dataframe['CDL3LINESTRIKE'] = ta.CDL3LINESTRIKE(dataframe)
  220. # Spinning Top: values [0, -100, 100]
  221. dataframe['CDLSPINNINGTOP'] = ta.CDLSPINNINGTOP(dataframe) # values [0, -100, 100]
  222. # Engulfing: values [0, -100, 100]
  223. dataframe['CDLENGULFING'] = ta.CDLENGULFING(dataframe) # values [0, -100, 100]
  224. # Harami: values [0, -100, 100]
  225. dataframe['CDLHARAMI'] = ta.CDLHARAMI(dataframe) # values [0, -100, 100]
  226. # Three Outside Up/Down: values [0, -100, 100]
  227. dataframe['CDL3OUTSIDE'] = ta.CDL3OUTSIDE(dataframe) # values [0, -100, 100]
  228. # Three Inside Up/Down: values [0, -100, 100]
  229. dataframe['CDL3INSIDE'] = ta.CDL3INSIDE(dataframe) # values [0, -100, 100]
  230.  
  231. # Chart type
  232. # ------------------------------------
  233. # Heikinashi stategy
  234. heikinashi = qtpylib.heikinashi(dataframe)
  235. dataframe['ha_open'] = heikinashi['open']
  236. dataframe['ha_close'] = heikinashi['close']
  237. dataframe['ha_high'] = heikinashi['high']
  238. dataframe['ha_low'] = heikinashi['low']
  239. """
  240.  
  241. return dataframe
  242.  
  243. def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  244. """
  245. Based on TA indicators, populates the buy signal for the given dataframe
  246. :param dataframe: DataFrame populated with indicators
  247. :param metadata: Additional information, like the currently traded pair
  248. :return: DataFrame with buy column
  249. """
  250. dataframe.loc[
  251. (
  252. (dataframe['close'].shift(1)<dataframe['hullma'].shift(1)) &
  253. (dataframe['close']>=dataframe['hullma']) &
  254. (dataframe['chop'] < 46 )
  255. ),
  256. 'buy'] = 1
  257. #print(dataframe.tail())
  258. return dataframe
  259.  
  260. def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
  261. """
  262. Based on TA indicators, populates the sell signal for the given dataframe
  263. :param dataframe: DataFrame populated with indicators
  264. :param metadata: Additional information, like the currently traded pair
  265. :return: DataFrame with buy column
  266. """
  267. dataframe.loc[
  268. (
  269. ((dataframe['ema7'] < dataframe['ema25']) &
  270. (dataframe['ema7'].shift(1) >= dataframe['ema25'].shift(1)) &
  271. (dataframe['volume'] > 0))
  272. ),
  273. 'sell'] = 1
  274. return dataframe
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement