-
Notifications
You must be signed in to change notification settings - Fork 34
/
gumbo1.py
153 lines (130 loc) · 5.14 KB
/
gumbo1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"""
https://github.com/raph92?tab=repositories
"""
import logging
# --- Do not remove these libs ---
import sys
from functools import reduce
from pathlib import Path
import freqtrade.vendor.qtpylib.indicators as qtpylib
import talib.abstract as ta
from freqtrade.constants import ListPairsWithTimeframes
from freqtrade.strategy import (
IntParameter,
DecimalParameter,
merge_informative_pair,
)
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
sys.path.append(str(Path(__file__).parent))
logger = logging.getLogger(__name__)
class Gumbo1(IStrategy):
# region Parameters
ewo_low = DecimalParameter(-20.0, 1, default=0, space="buy", optimize=True)
t3_periods = IntParameter(5, 20, default=5, space="buy", optimize=True)
stoch_high = IntParameter(60, 100, default=80, space="sell", optimize=True)
stock_periods = IntParameter(70, 90, default=80, space="sell", optimize=True)
# endregion
# region Params
minimal_roi = {"0": 0.10, "20": 0.05, "64": 0.03, "168": 0}
stoploss = -0.25
# endregion
timeframe = '5m'
use_custom_stoploss = False
inf_timeframe = '1h'
# Recommended
use_sell_signal = True
sell_profit_only = False
ignore_roi_if_buy_signal = True
startup_candle_count = 200
def informative_pairs(self) -> ListPairsWithTimeframes:
pairs = self.dp.current_whitelist()
informative_pairs = [(pair, '1h') for pair in pairs]
return informative_pairs
def populate_informative_indicators(self, dataframe: DataFrame, metadata):
informative = self.dp.get_pair_dataframe(
pair=metadata['pair'], timeframe=self.inf_timeframe
)
# t3 from custom_indicators
informative['T3'] = T3(informative)
# bollinger bands
bbands = ta.BBANDS(informative, timeperiod=20)
informative['bb_lowerband'] = bbands['lowerband']
informative['bb_middleband'] = bbands['middleband']
informative['bb_upperband'] = bbands['upperband']
dataframe = merge_informative_pair(
dataframe, informative, self.timeframe, self.inf_timeframe
)
return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# ewo
dataframe['EWO'] = EWO(dataframe)
# ema
dataframe['EMA'] = ta.EMA(dataframe)
# t3
for i in self.t3_periods.range:
dataframe[f'T3_{i}'] = T3(dataframe, i)
# bollinger bands 40
bbands = ta.BBANDS(dataframe, timeperiod=40)
dataframe['bb_lowerband_40'] = bbands['lowerband']
dataframe['bb_middleband_40'] = bbands['middleband']
dataframe['bb_upperband_40'] = bbands['upperband']
# stochastic
# stochastic windows
for i in self.stock_periods.range:
dataframe[f'stoch_{i}'] = stoch_sma(dataframe, window=i)
dataframe = self.populate_informative_indicators(dataframe, metadata)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
# ewo < 0
conditions.append(dataframe['EWO'] < self.ewo_low.value)
# middleband 1h >= t3 1h
conditions.append(dataframe['bb_middleband_1h'] >= dataframe['T3_1h'])
# t3 <= ema
conditions.append(dataframe[f'T3_{self.t3_periods.value}'] <= dataframe['EMA'])
if conditions:
dataframe.loc[reduce(lambda x, y: x & y, conditions), 'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
# stoch > 80
conditions.append(
dataframe[f'stoch_{self.stock_periods.value}'] > self.stoch_high.value
)
# t3 >= middleband_40
conditions.append(
dataframe[f'T3_{self.t3_periods.value}'] >= dataframe['bb_middleband_40']
)
if conditions:
dataframe.loc[reduce(lambda x, y: x | y, conditions), 'sell'] = 1
return dataframe
def T3(dataframe, length=5):
"""
T3 Average by HPotter on Tradingview
https://www.tradingview.com/script/qzoC9H1I-T3-Average/
"""
df = dataframe.copy()
df['xe1'] = ta.EMA(df['close'], timeperiod=length)
df['xe2'] = ta.EMA(df['xe1'], timeperiod=length)
df['xe3'] = ta.EMA(df['xe2'], timeperiod=length)
df['xe4'] = ta.EMA(df['xe3'], timeperiod=length)
df['xe5'] = ta.EMA(df['xe4'], timeperiod=length)
df['xe6'] = ta.EMA(df['xe5'], timeperiod=length)
b = 0.7
c1 = -b * b * b
c2 = 3 * b * b + 3 * b * b * b
c3 = -6 * b * b - 3 * b - 3 * b * b * b
c4 = 1 + 3 * b + b * b * b + 3 * b * b
df['T3Average'] = c1 * df['xe6'] + c2 * df['xe5'] + c3 * df['xe4'] + c4 * df['xe3']
return df['T3Average']
def EWO(dataframe, ema_length=5, ema2_length=35):
df = dataframe.copy()
ema1 = ta.EMA(df, timeperiod=ema_length)
ema2 = ta.EMA(df, timeperiod=ema2_length)
emadif = (ema1 - ema2) / df["low"] * 100
return emadif
def stoch_sma(dataframe: DataFrame, window=80):
""""""
stoch = qtpylib.stoch(dataframe, window)
return qtpylib.sma((stoch['slow_k'] + stoch['slow_d']) / 2, 10)