condensed strategy methods down to 2

This commit is contained in:
Sam Germain
2021-08-18 04:19:17 -06:00
parent d4a7d2d444
commit 092780df9d
22 changed files with 451 additions and 773 deletions

View File

@@ -46,7 +46,7 @@ class SampleHyperOpt(IHyperOpt):
"""
@staticmethod
def indicator_space() -> List[Dimension]:
def buy_indicator_space() -> List[Dimension]:
"""
Define your Hyperopt space for searching buy strategy parameters.
"""
@@ -55,11 +55,16 @@ class SampleHyperOpt(IHyperOpt):
Integer(15, 45, name='fastd-value'),
Integer(20, 50, name='adx-value'),
Integer(20, 40, name='rsi-value'),
Integer(75, 90, name='short-mfi-value'),
Integer(55, 85, name='short-fastd-value'),
Integer(50, 80, name='short-adx-value'),
Integer(60, 80, name='short-rsi-value'),
Categorical([True, False], name='mfi-enabled'),
Categorical([True, False], name='fastd-enabled'),
Categorical([True, False], name='adx-enabled'),
Categorical([True, False], name='rsi-enabled'),
Categorical(['bb_lower', 'macd_cross_signal', 'sar_reversal'], name='trigger')
Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger'),
]
@staticmethod
@@ -71,39 +76,61 @@ class SampleHyperOpt(IHyperOpt):
"""
Buy strategy Hyperopt will build and use.
"""
conditions = []
long_conditions = []
short_conditions = []
# GUARDS AND TRENDS
if 'mfi-enabled' in params and params['mfi-enabled']:
conditions.append(dataframe['mfi'] < params['mfi-value'])
long_conditions.append(dataframe['mfi'] < params['mfi-value'])
short_conditions.append(dataframe['mfi'] > params['short-mfi-value'])
if 'fastd-enabled' in params and params['fastd-enabled']:
conditions.append(dataframe['fastd'] < params['fastd-value'])
long_conditions.append(dataframe['fastd'] < params['fastd-value'])
short_conditions.append(dataframe['fastd'] > params['short-fastd-value'])
if 'adx-enabled' in params and params['adx-enabled']:
conditions.append(dataframe['adx'] > params['adx-value'])
long_conditions.append(dataframe['adx'] > params['adx-value'])
short_conditions.append(dataframe['adx'] < params['short-adx-value'])
if 'rsi-enabled' in params and params['rsi-enabled']:
conditions.append(dataframe['rsi'] < params['rsi-value'])
long_conditions.append(dataframe['rsi'] < params['rsi-value'])
short_conditions.append(dataframe['rsi'] > params['short-rsi-value'])
# TRIGGERS
if 'trigger' in params:
if params['trigger'] == 'bb_lower':
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['trigger'] == 'boll':
long_conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
short_conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['trigger'] == 'macd_cross_signal':
conditions.append(qtpylib.crossed_above(
dataframe['macd'], dataframe['macdsignal']
long_conditions.append(qtpylib.crossed_above(
dataframe['macd'],
dataframe['macdsignal']
))
short_conditions.append(qtpylib.crossed_below(
dataframe['macd'],
dataframe['macdsignal']
))
if params['trigger'] == 'sar_reversal':
conditions.append(qtpylib.crossed_above(
dataframe['close'], dataframe['sar']
long_conditions.append(qtpylib.crossed_above(
dataframe['close'],
dataframe['sar']
))
short_conditions.append(qtpylib.crossed_below(
dataframe['close'],
dataframe['sar']
))
# Check that volume is not 0
conditions.append(dataframe['volume'] > 0)
long_conditions.append(dataframe['volume'] > 0)
short_conditions.append(dataframe['volume'] > 0)
if conditions:
if long_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, long_conditions),
'buy'] = 1
if short_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, short_conditions),
'enter_short'] = 1
return dataframe
return populate_buy_trend
@@ -118,13 +145,19 @@ class SampleHyperOpt(IHyperOpt):
Integer(50, 100, name='sell-fastd-value'),
Integer(50, 100, name='sell-adx-value'),
Integer(60, 100, name='sell-rsi-value'),
Integer(1, 25, name='exit-short-mfi-value'),
Integer(1, 50, name='exit-short-fastd-value'),
Integer(1, 50, name='exit-short-adx-value'),
Integer(1, 40, name='exit-short-rsi-value'),
Categorical([True, False], name='sell-mfi-enabled'),
Categorical([True, False], name='sell-fastd-enabled'),
Categorical([True, False], name='sell-adx-enabled'),
Categorical([True, False], name='sell-rsi-enabled'),
Categorical(['sell-bb_upper',
Categorical(['sell-boll',
'sell-macd_cross_signal',
'sell-sar_reversal'], name='sell-trigger')
'sell-sar_reversal'],
name='sell-trigger'
),
]
@staticmethod
@@ -136,161 +169,61 @@ class SampleHyperOpt(IHyperOpt):
"""
Sell strategy Hyperopt will build and use.
"""
conditions = []
exit_long_conditions = []
exit_short_conditions = []
# GUARDS AND TRENDS
if 'sell-mfi-enabled' in params and params['sell-mfi-enabled']:
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
exit_long_conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
exit_short_conditions.append(dataframe['mfi'] < params['exit-short-mfi-value'])
if 'sell-fastd-enabled' in params and params['sell-fastd-enabled']:
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
exit_long_conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
exit_short_conditions.append(dataframe['fastd'] < params['exit-short-fastd-value'])
if 'sell-adx-enabled' in params and params['sell-adx-enabled']:
conditions.append(dataframe['adx'] < params['sell-adx-value'])
exit_long_conditions.append(dataframe['adx'] < params['sell-adx-value'])
exit_short_conditions.append(dataframe['adx'] > params['exit-short-adx-value'])
if 'sell-rsi-enabled' in params and params['sell-rsi-enabled']:
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
exit_long_conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
exit_short_conditions.append(dataframe['rsi'] < params['exit-short-rsi-value'])
# TRIGGERS
if 'sell-trigger' in params:
if params['sell-trigger'] == 'sell-bb_upper':
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['sell-trigger'] == 'sell-boll':
exit_long_conditions.append(dataframe['close'] > dataframe['bb_upperband'])
exit_short_conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['sell-trigger'] == 'sell-macd_cross_signal':
conditions.append(qtpylib.crossed_above(
dataframe['macdsignal'], dataframe['macd']
exit_long_conditions.append(qtpylib.crossed_above(
dataframe['macdsignal'],
dataframe['macd']
))
exit_short_conditions.append(qtpylib.crossed_below(
dataframe['macdsignal'],
dataframe['macd']
))
if params['sell-trigger'] == 'sell-sar_reversal':
conditions.append(qtpylib.crossed_above(
dataframe['sar'], dataframe['close']
exit_long_conditions.append(qtpylib.crossed_above(
dataframe['sar'],
dataframe['close']
))
exit_short_conditions.append(qtpylib.crossed_below(
dataframe['sar'],
dataframe['close']
))
# Check that volume is not 0
conditions.append(dataframe['volume'] > 0)
exit_long_conditions.append(dataframe['volume'] > 0)
exit_short_conditions.append(dataframe['volume'] > 0)
if conditions:
if exit_long_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, exit_long_conditions),
'sell'] = 1
return dataframe
return populate_sell_trend
@staticmethod
def short_strategy_generator(params: Dict[str, Any]) -> Callable:
"""
Define the short strategy parameters to be used by Hyperopt.
"""
def populate_short_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Buy strategy Hyperopt will build and use.
"""
conditions = []
# GUARDS AND TRENDS
if 'mfi-enabled' in params and params['mfi-enabled']:
conditions.append(dataframe['mfi'] > params['mfi-value'])
if 'fastd-enabled' in params and params['fastd-enabled']:
conditions.append(dataframe['fastd'] > params['fastd-value'])
if 'adx-enabled' in params and params['adx-enabled']:
conditions.append(dataframe['adx'] < params['adx-value'])
if 'rsi-enabled' in params and params['rsi-enabled']:
conditions.append(dataframe['rsi'] > params['rsi-value'])
# TRIGGERS
if 'trigger' in params:
if params['trigger'] == 'bb_upper':
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['trigger'] == 'macd_cross_signal':
conditions.append(qtpylib.crossed_below(
dataframe['macd'], dataframe['macdsignal']
))
if params['trigger'] == 'sar_reversal':
conditions.append(qtpylib.crossed_below(
dataframe['close'], dataframe['sar']
))
if conditions:
if exit_short_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'short'] = 1
return dataframe
return populate_short_trend
@staticmethod
def short_indicator_space() -> List[Dimension]:
"""
Define your Hyperopt space for searching short strategy parameters.
"""
return [
Integer(75, 90, name='mfi-value'),
Integer(55, 85, name='fastd-value'),
Integer(50, 80, name='adx-value'),
Integer(60, 80, name='rsi-value'),
Categorical([True, False], name='mfi-enabled'),
Categorical([True, False], name='fastd-enabled'),
Categorical([True, False], name='adx-enabled'),
Categorical([True, False], name='rsi-enabled'),
Categorical(['bb_upper', 'macd_cross_signal', 'sar_reversal'], name='trigger')
]
@staticmethod
def exit_short_strategy_generator(params: Dict[str, Any]) -> Callable:
"""
Define the exit_short strategy parameters to be used by Hyperopt.
"""
def populate_exit_short_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Exit_short strategy Hyperopt will build and use.
"""
conditions = []
# GUARDS AND TRENDS
if 'exit-short-mfi-enabled' in params and params['exit-short-mfi-enabled']:
conditions.append(dataframe['mfi'] < params['exit-short-mfi-value'])
if 'exit-short-fastd-enabled' in params and params['exit-short-fastd-enabled']:
conditions.append(dataframe['fastd'] < params['exit-short-fastd-value'])
if 'exit-short-adx-enabled' in params and params['exit-short-adx-enabled']:
conditions.append(dataframe['adx'] > params['exit-short-adx-value'])
if 'exit-short-rsi-enabled' in params and params['exit-short-rsi-enabled']:
conditions.append(dataframe['rsi'] < params['exit-short-rsi-value'])
# TRIGGERS
if 'exit-short-trigger' in params:
if params['exit-short-trigger'] == 'exit-short-bb_lower':
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['exit-short-trigger'] == 'exit-short-macd_cross_signal':
conditions.append(qtpylib.crossed_below(
dataframe['macdsignal'], dataframe['macd']
))
if params['exit-short-trigger'] == 'exit-short-sar_reversal':
conditions.append(qtpylib.crossed_below(
dataframe['sar'], dataframe['close']
))
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, exit_short_conditions),
'exit_short'] = 1
return dataframe
return populate_exit_short_trend
@staticmethod
def exit_short_indicator_space() -> List[Dimension]:
"""
Define your Hyperopt space for searching exit short strategy parameters.
"""
return [
Integer(1, 25, name='exit_short-mfi-value'),
Integer(1, 50, name='exit_short-fastd-value'),
Integer(1, 50, name='exit_short-adx-value'),
Integer(1, 40, name='exit_short-rsi-value'),
Categorical([True, False], name='exit_short-mfi-enabled'),
Categorical([True, False], name='exit_short-fastd-enabled'),
Categorical([True, False], name='exit_short-adx-enabled'),
Categorical([True, False], name='exit_short-rsi-enabled'),
Categorical(['exit_short-bb_lower',
'exit_short-macd_cross_signal',
'exit_short-sar_reversal'], name='exit_short-trigger')
]
return populate_sell_trend

View File

@@ -70,11 +70,15 @@ class AdvancedSampleHyperOpt(IHyperOpt):
Integer(15, 45, name='fastd-value'),
Integer(20, 50, name='adx-value'),
Integer(20, 40, name='rsi-value'),
Integer(75, 90, name='short-mfi-value'),
Integer(55, 85, name='short-fastd-value'),
Integer(50, 80, name='short-adx-value'),
Integer(60, 80, name='short-rsi-value'),
Categorical([True, False], name='mfi-enabled'),
Categorical([True, False], name='fastd-enabled'),
Categorical([True, False], name='adx-enabled'),
Categorical([True, False], name='rsi-enabled'),
Categorical(['bb_lower', 'macd_cross_signal', 'sar_reversal'], name='trigger')
Categorical(['boll', 'macd_cross_signal', 'sar_reversal'], name='trigger')
]
@staticmethod
@@ -86,38 +90,60 @@ class AdvancedSampleHyperOpt(IHyperOpt):
"""
Buy strategy Hyperopt will build and use
"""
conditions = []
long_conditions = []
short_conditions = []
# GUARDS AND TRENDS
if 'mfi-enabled' in params and params['mfi-enabled']:
conditions.append(dataframe['mfi'] < params['mfi-value'])
long_conditions.append(dataframe['mfi'] < params['mfi-value'])
short_conditions.append(dataframe['mfi'] > params['short-mfi-value'])
if 'fastd-enabled' in params and params['fastd-enabled']:
conditions.append(dataframe['fastd'] < params['fastd-value'])
long_conditions.append(dataframe['fastd'] < params['fastd-value'])
short_conditions.append(dataframe['fastd'] > params['short-fastd-value'])
if 'adx-enabled' in params and params['adx-enabled']:
conditions.append(dataframe['adx'] > params['adx-value'])
long_conditions.append(dataframe['adx'] > params['adx-value'])
short_conditions.append(dataframe['adx'] < params['short-adx-value'])
if 'rsi-enabled' in params and params['rsi-enabled']:
conditions.append(dataframe['rsi'] < params['rsi-value'])
long_conditions.append(dataframe['rsi'] < params['rsi-value'])
short_conditions.append(dataframe['rsi'] > params['short-rsi-value'])
# TRIGGERS
if 'trigger' in params:
if params['trigger'] == 'bb_lower':
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['trigger'] == 'boll':
long_conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
short_conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['trigger'] == 'macd_cross_signal':
conditions.append(qtpylib.crossed_above(
dataframe['macd'], dataframe['macdsignal']
long_conditions.append(qtpylib.crossed_above(
dataframe['macd'],
dataframe['macdsignal']
))
short_conditions.append(qtpylib.crossed_below(
dataframe['macd'],
dataframe['macdsignal']
))
if params['trigger'] == 'sar_reversal':
conditions.append(qtpylib.crossed_above(
dataframe['close'], dataframe['sar']
long_conditions.append(qtpylib.crossed_above(
dataframe['close'],
dataframe['sar']
))
short_conditions.append(qtpylib.crossed_below(
dataframe['close'],
dataframe['sar']
))
# Check that volume is not 0
conditions.append(dataframe['volume'] > 0)
long_conditions.append(dataframe['volume'] > 0)
short_conditions.append(dataframe['volume'] > 0)
if conditions:
if long_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, long_conditions),
'buy'] = 1
if short_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, short_conditions),
'enter_short'] = 1
return dataframe
return populate_buy_trend
@@ -132,13 +158,18 @@ class AdvancedSampleHyperOpt(IHyperOpt):
Integer(50, 100, name='sell-fastd-value'),
Integer(50, 100, name='sell-adx-value'),
Integer(60, 100, name='sell-rsi-value'),
Integer(1, 25, name='exit_short-mfi-value'),
Integer(1, 50, name='exit_short-fastd-value'),
Integer(1, 50, name='exit_short-adx-value'),
Integer(1, 40, name='exit_short-rsi-value'),
Categorical([True, False], name='sell-mfi-enabled'),
Categorical([True, False], name='sell-fastd-enabled'),
Categorical([True, False], name='sell-adx-enabled'),
Categorical([True, False], name='sell-rsi-enabled'),
Categorical(['sell-bb_upper',
Categorical(['sell-boll',
'sell-macd_cross_signal',
'sell-sar_reversal'], name='sell-trigger')
'sell-sar_reversal'],
name='sell-trigger')
]
@staticmethod
@@ -151,163 +182,63 @@ class AdvancedSampleHyperOpt(IHyperOpt):
Sell strategy Hyperopt will build and use
"""
# print(params)
conditions = []
exit_long_conditions = []
exit_short_conditions = []
# GUARDS AND TRENDS
if 'sell-mfi-enabled' in params and params['sell-mfi-enabled']:
conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
exit_long_conditions.append(dataframe['mfi'] > params['sell-mfi-value'])
exit_short_conditions.append(dataframe['mfi'] < params['exit-short-mfi-value'])
if 'sell-fastd-enabled' in params and params['sell-fastd-enabled']:
conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
exit_long_conditions.append(dataframe['fastd'] > params['sell-fastd-value'])
exit_short_conditions.append(dataframe['fastd'] < params['exit-short-fastd-value'])
if 'sell-adx-enabled' in params and params['sell-adx-enabled']:
conditions.append(dataframe['adx'] < params['sell-adx-value'])
exit_long_conditions.append(dataframe['adx'] < params['sell-adx-value'])
exit_short_conditions.append(dataframe['adx'] > params['exit-short-adx-value'])
if 'sell-rsi-enabled' in params and params['sell-rsi-enabled']:
conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
exit_long_conditions.append(dataframe['rsi'] > params['sell-rsi-value'])
exit_short_conditions.append(dataframe['rsi'] < params['exit-short-rsi-value'])
# TRIGGERS
if 'sell-trigger' in params:
if params['sell-trigger'] == 'sell-bb_upper':
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['sell-trigger'] == 'sell-boll':
exit_long_conditions.append(dataframe['close'] > dataframe['bb_upperband'])
exit_short_conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['sell-trigger'] == 'sell-macd_cross_signal':
conditions.append(qtpylib.crossed_above(
dataframe['macdsignal'], dataframe['macd']
exit_long_conditions.append(qtpylib.crossed_above(
dataframe['macdsignal'],
dataframe['macd']
))
exit_long_conditions.append(qtpylib.crossed_below(
dataframe['macdsignal'],
dataframe['macd']
))
if params['sell-trigger'] == 'sell-sar_reversal':
conditions.append(qtpylib.crossed_above(
dataframe['sar'], dataframe['close']
exit_long_conditions.append(qtpylib.crossed_above(
dataframe['sar'],
dataframe['close']
))
exit_long_conditions.append(qtpylib.crossed_below(
dataframe['sar'],
dataframe['close']
))
# Check that volume is not 0
conditions.append(dataframe['volume'] > 0)
exit_long_conditions.append(dataframe['volume'] > 0)
exit_short_conditions.append(dataframe['volume'] > 0)
if conditions:
if exit_long_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, exit_long_conditions),
'sell'] = 1
return dataframe
return populate_sell_trend
@staticmethod
def short_strategy_generator(params: Dict[str, Any]) -> Callable:
"""
Define the short strategy parameters to be used by Hyperopt.
"""
def populate_short_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Buy strategy Hyperopt will build and use.
"""
conditions = []
# GUARDS AND TRENDS
if 'mfi-enabled' in params and params['mfi-enabled']:
conditions.append(dataframe['mfi'] > params['mfi-value'])
if 'fastd-enabled' in params and params['fastd-enabled']:
conditions.append(dataframe['fastd'] > params['fastd-value'])
if 'adx-enabled' in params and params['adx-enabled']:
conditions.append(dataframe['adx'] < params['adx-value'])
if 'rsi-enabled' in params and params['rsi-enabled']:
conditions.append(dataframe['rsi'] > params['rsi-value'])
# TRIGGERS
if 'trigger' in params:
if params['trigger'] == 'bb_upper':
conditions.append(dataframe['close'] > dataframe['bb_upperband'])
if params['trigger'] == 'macd_cross_signal':
conditions.append(qtpylib.crossed_below(
dataframe['macd'], dataframe['macdsignal']
))
if params['trigger'] == 'sar_reversal':
conditions.append(qtpylib.crossed_below(
dataframe['close'], dataframe['sar']
))
if conditions:
if exit_short_conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'short'] = 1
return dataframe
return populate_short_trend
@staticmethod
def short_indicator_space() -> List[Dimension]:
"""
Define your Hyperopt space for searching short strategy parameters.
"""
return [
Integer(75, 90, name='mfi-value'),
Integer(55, 85, name='fastd-value'),
Integer(50, 80, name='adx-value'),
Integer(60, 80, name='rsi-value'),
Categorical([True, False], name='mfi-enabled'),
Categorical([True, False], name='fastd-enabled'),
Categorical([True, False], name='adx-enabled'),
Categorical([True, False], name='rsi-enabled'),
Categorical(['bb_upper', 'macd_cross_signal', 'sar_reversal'], name='trigger')
]
@staticmethod
def exit_short_strategy_generator(params: Dict[str, Any]) -> Callable:
"""
Define the exit_short strategy parameters to be used by Hyperopt.
"""
def populate_exit_short_trend(dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Exit_short strategy Hyperopt will build and use.
"""
conditions = []
# GUARDS AND TRENDS
if 'exit-short-mfi-enabled' in params and params['exit-short-mfi-enabled']:
conditions.append(dataframe['mfi'] < params['exit-short-mfi-value'])
if 'exit-short-fastd-enabled' in params and params['exit-short-fastd-enabled']:
conditions.append(dataframe['fastd'] < params['exit-short-fastd-value'])
if 'exit-short-adx-enabled' in params and params['exit-short-adx-enabled']:
conditions.append(dataframe['adx'] > params['exit-short-adx-value'])
if 'exit-short-rsi-enabled' in params and params['exit-short-rsi-enabled']:
conditions.append(dataframe['rsi'] < params['exit-short-rsi-value'])
# TRIGGERS
if 'exit-short-trigger' in params:
if params['exit-short-trigger'] == 'exit-short-bb_lower':
conditions.append(dataframe['close'] < dataframe['bb_lowerband'])
if params['exit-short-trigger'] == 'exit-short-macd_cross_signal':
conditions.append(qtpylib.crossed_below(
dataframe['macdsignal'], dataframe['macd']
))
if params['exit-short-trigger'] == 'exit-short-sar_reversal':
conditions.append(qtpylib.crossed_below(
dataframe['sar'], dataframe['close']
))
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
reduce(lambda x, y: x & y, exit_short_conditions),
'exit_short'] = 1
return dataframe
return populate_exit_short_trend
@staticmethod
def exit_short_indicator_space() -> List[Dimension]:
"""
Define your Hyperopt space for searching exit short strategy parameters.
"""
return [
Integer(1, 25, name='exit_short-mfi-value'),
Integer(1, 50, name='exit_short-fastd-value'),
Integer(1, 50, name='exit_short-adx-value'),
Integer(1, 40, name='exit_short-rsi-value'),
Categorical([True, False], name='exit_short-mfi-enabled'),
Categorical([True, False], name='exit_short-fastd-enabled'),
Categorical([True, False], name='exit_short-adx-enabled'),
Categorical([True, False], name='exit_short-rsi-enabled'),
Categorical(['exit_short-bb_lower',
'exit_short-macd_cross_signal',
'exit_short-sar_reversal'], name='exit_short-trigger')
]
return populate_sell_trend
@staticmethod
def generate_roi_table(params: Dict) -> Dict[int, float]:

View File

@@ -29,7 +29,7 @@ class SampleStrategy(IStrategy):
You must keep:
- the lib in the section "Do not remove these libs"
- the methods: populate_indicators, populate_buy_trend, populate_sell_trend, populate_short_trend, populate_exit_short_trend
- the methods: populate_indicators, populate_buy_trend, populate_sell_trend
You should keep:
- timeframe, minimal_roi, stoploss, trailing_*
"""
@@ -356,6 +356,16 @@ class SampleStrategy(IStrategy):
),
'buy'] = 1
dataframe.loc[
(
# Signal: RSI crosses above 70
(qtpylib.crossed_above(dataframe['rsi'], self.short_rsi.value)) &
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard: tema above BB middle
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard: tema is falling
(dataframe['volume'] > 0) # Make sure Volume is not 0
),
'enter_short'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
@@ -374,38 +384,13 @@ class SampleStrategy(IStrategy):
(dataframe['volume'] > 0) # Make sure Volume is not 0
),
'sell'] = 1
return dataframe
def populate_short_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the short signal for the given dataframe
:param dataframe: DataFrame populated with indicators
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with short column
"""
dataframe.loc[
(
# Signal: RSI crosses above 70
(qtpylib.crossed_above(dataframe['rsi'], self.short_rsi.value)) &
(dataframe['tema'] > dataframe['bb_middleband']) & # Guard: tema above BB middle
(dataframe['tema'] < dataframe['tema'].shift(1)) & # Guard: tema is falling
(dataframe['volume'] > 0) # Make sure Volume is not 0
),
'short'] = 1
return dataframe
def populate_exit_short_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
"""
Based on TA indicators, populates the exit_short signal for the given dataframe
:param dataframe: DataFrame populated with indicators
:param metadata: Additional information, like the currently traded pair
:return: DataFrame with exit_short column
"""
dataframe.loc[
(
# Signal: RSI crosses above 30
(qtpylib.crossed_above(dataframe['rsi'], self.exit_short_rsi.value)) &
(dataframe['tema'] <= dataframe['bb_middleband']) & # Guard: tema below BB middle
# Guard: tema below BB middle
(dataframe['tema'] <= dataframe['bb_middleband']) &
(dataframe['tema'] > dataframe['tema'].shift(1)) & # Guard: tema is raising
(dataframe['volume'] > 0) # Make sure Volume is not 0
),