Merge pull request #394 from gcarq/more_triggers

More triggers and guards
This commit is contained in:
Samuel Husso 2018-01-17 14:14:33 +02:00 committed by GitHub
commit a799b7d56d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 9 deletions

View File

@ -74,6 +74,8 @@ def populate_indicators(dataframe: DataFrame) -> DataFrame:
# Plus Directional Indicator / Movement # Plus Directional Indicator / Movement
dataframe['plus_dm'] = ta.PLUS_DM(dataframe) dataframe['plus_dm'] = ta.PLUS_DM(dataframe)
dataframe['plus_di'] = ta.PLUS_DI(dataframe) dataframe['plus_di'] = ta.PLUS_DI(dataframe)
dataframe['minus_di'] = ta.MINUS_DI(dataframe)
""" """
# ROC # ROC
dataframe['roc'] = ta.ROC(dataframe) dataframe['roc'] = ta.ROC(dataframe)
@ -114,13 +116,14 @@ def populate_indicators(dataframe: DataFrame) -> DataFrame:
dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband'] dataframe['blower'] = ta.BBANDS(dataframe, nbdevup=2, nbdevdn=2)['lowerband']
""" """
# Bollinger bands # Bollinger bands
"""
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2) bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(dataframe), window=20, stds=2)
dataframe['bb_lowerband'] = bollinger['lower'] dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_middleband'] = bollinger['mid'] dataframe['bb_middleband'] = bollinger['mid']
dataframe['bb_upperband'] = bollinger['upper'] dataframe['bb_upperband'] = bollinger['upper']
"""
# EMA - Exponential Moving Average # EMA - Exponential Moving Average
dataframe['ema3'] = ta.EMA(dataframe, timeperiod=3)
dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5) dataframe['ema5'] = ta.EMA(dataframe, timeperiod=5)
dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10) dataframe['ema10'] = ta.EMA(dataframe, timeperiod=10)
dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50) dataframe['ema50'] = ta.EMA(dataframe, timeperiod=50)
@ -210,14 +213,12 @@ def populate_indicators(dataframe: DataFrame) -> DataFrame:
# Chart type # Chart type
# ------------------------------------ # ------------------------------------
"""
# Heikinashi stategy # Heikinashi stategy
heikinashi = qtpylib.heikinashi(dataframe) heikinashi = qtpylib.heikinashi(dataframe)
dataframe['ha_open'] = heikinashi['open'] dataframe['ha_open'] = heikinashi['open']
dataframe['ha_close'] = heikinashi['close'] dataframe['ha_close'] = heikinashi['close']
dataframe['ha_high'] = heikinashi['high'] dataframe['ha_high'] = heikinashi['high']
dataframe['ha_low'] = heikinashi['low'] dataframe['ha_low'] = heikinashi['low']
"""
return dataframe return dataframe

View File

@ -58,6 +58,10 @@ main._CONF = OPTIMIZE_CONFIG
SPACE = { SPACE = {
'macd_below_zero': hp.choice('macd_below_zero', [
{'enabled': False},
{'enabled': True}
]),
'mfi': hp.choice('mfi', [ 'mfi': hp.choice('mfi', [
{'enabled': False}, {'enabled': False},
{'enabled': True, 'value': hp.quniform('mfi-value', 5, 25, 1)} {'enabled': True, 'value': hp.quniform('mfi-value', 5, 25, 1)}
@ -96,13 +100,15 @@ SPACE = {
]), ]),
'trigger': hp.choice('trigger', [ 'trigger': hp.choice('trigger', [
{'type': 'lower_bb'}, {'type': 'lower_bb'},
{'type': 'lower_bb_tema'},
{'type': 'faststoch10'}, {'type': 'faststoch10'},
{'type': 'ao_cross_zero'}, {'type': 'ao_cross_zero'},
{'type': 'ema5_cross_ema10'}, {'type': 'ema3_cross_ema10'},
{'type': 'macd_cross_signal'}, {'type': 'macd_cross_signal'},
{'type': 'sar_reversal'}, {'type': 'sar_reversal'},
{'type': 'stochf_cross'},
{'type': 'ht_sine'}, {'type': 'ht_sine'},
{'type': 'heiken_reversal_bull'},
{'type': 'di_cross'},
]), ]),
'stoploss': hp.uniform('stoploss', -0.5, -0.02), 'stoploss': hp.uniform('stoploss', -0.5, -0.02),
} }
@ -207,6 +213,8 @@ def buy_strategy_generator(params):
# GUARDS AND TRENDS # GUARDS AND TRENDS
if params['uptrend_long_ema']['enabled']: if params['uptrend_long_ema']['enabled']:
conditions.append(dataframe['ema50'] > dataframe['ema100']) conditions.append(dataframe['ema50'] > dataframe['ema100'])
if params['macd_below_zero']['enabled']:
conditions.append(dataframe['macd'] < 0)
if params['uptrend_short_ema']['enabled']: if params['uptrend_short_ema']['enabled']:
conditions.append(dataframe['ema5'] > dataframe['ema10']) conditions.append(dataframe['ema5'] > dataframe['ema10'])
if params['mfi']['enabled']: if params['mfi']['enabled']:
@ -227,14 +235,17 @@ def buy_strategy_generator(params):
# TRIGGERS # TRIGGERS
triggers = { triggers = {
'lower_bb': dataframe['tema'] <= dataframe['blower'], 'lower_bb': (dataframe['close'] < dataframe['bb_lowerband']),
'lower_bb_tema': (dataframe['tema'] < dataframe['bb_lowerband']),
'faststoch10': (crossed_above(dataframe['fastd'], 10.0)), 'faststoch10': (crossed_above(dataframe['fastd'], 10.0)),
'ao_cross_zero': (crossed_above(dataframe['ao'], 0.0)), 'ao_cross_zero': (crossed_above(dataframe['ao'], 0.0)),
'ema5_cross_ema10': (crossed_above(dataframe['ema5'], dataframe['ema10'])), 'ema3_cross_ema10': (crossed_above(dataframe['ema3'], dataframe['ema10'])),
'macd_cross_signal': (crossed_above(dataframe['macd'], dataframe['macdsignal'])), 'macd_cross_signal': (crossed_above(dataframe['macd'], dataframe['macdsignal'])),
'sar_reversal': (crossed_above(dataframe['close'], dataframe['sar'])), 'sar_reversal': (crossed_above(dataframe['close'], dataframe['sar'])),
'stochf_cross': (crossed_above(dataframe['fastk'], dataframe['fastd'])),
'ht_sine': (crossed_above(dataframe['htleadsine'], dataframe['htsine'])), 'ht_sine': (crossed_above(dataframe['htleadsine'], dataframe['htsine'])),
'heiken_reversal_bull': (crossed_above(dataframe['ha_close'], dataframe['ha_open'])) &
(dataframe['ha_low'] == dataframe['ha_open']),
'di_cross': (crossed_above(dataframe['plus_di'], dataframe['minus_di'])),
} }
conditions.append(triggers.get(params['trigger']['type'])) conditions.append(triggers.get(params['trigger']['type']))

View File

@ -107,6 +107,7 @@ def test_no_log_if_loss_does_not_improve(mocker):
def test_fmin_best_results(mocker, caplog): def test_fmin_best_results(mocker, caplog):
fmin_result = { fmin_result = {
"macd_below_zero": 0,
"adx": 1, "adx": 1,
"adx-value": 15.0, "adx-value": 15.0,
"fastd": 1, "fastd": 1,
@ -136,7 +137,7 @@ def test_fmin_best_results(mocker, caplog):
'"adx": {\n "enabled": true,\n "value": 15.0\n },', '"adx": {\n "enabled": true,\n "value": 15.0\n },',
'"green_candle": {\n "enabled": true\n },', '"green_candle": {\n "enabled": true\n },',
'"mfi": {\n "enabled": false\n },', '"mfi": {\n "enabled": false\n },',
'"trigger": {\n "type": "ao_cross_zero"\n },', '"trigger": {\n "type": "faststoch10"\n },',
'"stoploss": -0.1', '"stoploss": -0.1',
] ]