Elffuss BraidHub

kikocis/freqtrade-strategies public

5.1.3
Changeset844f22e321900b6c215ce0f8591db4310b8c110d66791fd3db9b531e10135946
AuthorBryan Chain <bryan.chain@cerner.com> · 2021-05-11 01:07 -04:00
CommitterBryan Chain <bryan.chain@cerner.com> · 2021-05-11 01:07 -04:00
Parents28b2bf4d2b8f

Browse the files at this changeset

1 file changed

modified strategies/Solipsis_v5.py +14 −29
@@ -3,7 +3,7 @@
33 import freqtrade.vendor.qtpylib.indicators as qtpylib
44 import arrow
55
6-from freqtrade.strategy import (IStrategy, timeframe_to_prev_date, merge_informative_pair, stoploss_from_open,
6+from freqtrade.strategy import (IStrategy, merge_informative_pair, stoploss_from_open,
77 IntParameter, DecimalParameter, CategoricalParameter)
88
99 from typing import Dict, List, Optional, Tuple, Union
@@ -34,7 +34,7 @@
3434
3535 I take no responsibility for any success or failure you have using this strategy.
3636
37-VERSION: 5.1.2
37+VERSION: 5.1.3
3838 """
3939
4040 class Solipsis5(IStrategy):
@@ -59,7 +59,7 @@
5959 ## Sell Space Params are being used for both custom_stoploss and custom_sell
6060
6161 # Custom Sell Profit (formerly Dynamic ROI)
62- csell_roi_type = CategoricalParameter(['static', 'decay', 'step'], default='decay', space='sell', optimize=True)
62+ csell_roi_type = CategoricalParameter(['static', 'decay', 'step'], default='step', space='sell', optimize=True)
6363 csell_roi_time = IntParameter(720, 1440, default=720, space='sell')
6464 csell_roi_start = DecimalParameter(0.01, 0.05, default=0.01, space='sell')
6565 csell_roi_end = DecimalParameter(0.0, 0.01, default=0, space='sell')
@@ -70,7 +70,7 @@
7070
7171 # Custom Sell Loss (formerly Custom Stoploss)
7272 csell_loss_threshold = DecimalParameter(-0.05, 0, default=-0.03, space='sell')
73- csell_bail_how = CategoricalParameter(['roc', 'time', 'any', 'none'], default='roc', space='sell', optimize=True)
73+ csell_bail_how = CategoricalParameter(['roc', 'time', 'any', 'none'], default='none', space='sell', optimize=True)
7474 csell_bail_roc = DecimalParameter(-5.0, -1.0, default=-3.0, space='sell')
7575 csell_bail_time = IntParameter(720, 1440, default=720, space='sell')
7676 csell_bail_time_trend = CategoricalParameter([True, False], default=True, space='sell', optimize=True)
@@ -133,7 +133,8 @@
133133 def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
134134 if not metadata['pair'] in self.custom_trade_info:
135135 self.custom_trade_info[metadata['pair']] = {}
136- self.custom_trade_info[metadata['pair']]['had-trend'] = False
136+ if not 'had-trend' in self.custom_trade_info[metadata["pair"]]:
137+ self.custom_trade_info[metadata['pair']]['had-trend'] = False
137138
138139 ## Base Timeframe / Pair
139140
@@ -218,13 +219,6 @@
218219 dataframe['BTC_close'] = btc_stake_tf['close']
219220 dataframe['BTC_kama'] = ta.KAMA(btc_stake_tf, length=144)
220221
221- # Slam some indicators into the trade_info dict so we can dynamic roi and custom stoploss in backtest
222- if self.dp.runmode.value in ('backtest', 'hyperopt'):
223- self.custom_trade_info[metadata['pair']]['sroc'] = dataframe[['date', 'sroc']].copy().set_index('date')
224- self.custom_trade_info[metadata['pair']]['ssl-dir'] = dataframe[['date', 'ssl-dir']].copy().set_index('date')
225- self.custom_trade_info[metadata['pair']]['rmi-up-trend'] = dataframe[['date', 'rmi-up-trend']].copy().set_index('date')
226- self.custom_trade_info[metadata['pair']]['candle-up-trend'] = dataframe[['date', 'candle-up-trend']].copy().set_index('date')
227-
228222 return dataframe
229223
230224 """
@@ -303,20 +297,11 @@
303297 Current implementation is meant to behave similar to my original "dynamic_roi" concept when in profit
304298 or like the original "custom_stoploss" when at a loss.
305299 """
306- def custom_sell(self, pair: str, trade: Trade, current_time: datetime, current_rate: float,
307- current_profit: float, **kwargs) -> Optional[Union[str, bool]]:
300+ def custom_sell(self, pair: str, trade: 'Trade', current_time: 'datetime', current_rate: float,
301+ current_profit: float, **kwargs):
308302
309- if self.config['runmode'].value in ('live', 'dry_run'):
310- dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
311- sroc = dataframe['sroc'].iat[-1]
312- rmi_trend = dataframe['rmi-up-trend'].iat[-1]
313- candle_trend = dataframe['candle-up-trend'].iat[-1]
314- ssl_dir = dataframe['ssl-dir'].iat[-1]
315- else:
316- sroc = self.custom_trade_info[trade.pair]['sroc'].loc[current_time]['sroc']
317- rmi_trend = self.custom_trade_info[trade.pair]['rmi-up-trend'].loc[current_time]['rmi-up-trend']
318- candle_trend = self.custom_trade_info[trade.pair]['candle-up-trend'].loc[current_time]['candle-up-trend']
319- ssl_dir = self.custom_trade_info[trade.pair]['ssl-dir'].loc[current_time]['ssl-dir']
303+ dataframe, _ = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe)
304+ current_candle = dataframe.iloc[-1].squeeze()
320305
321306 trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60)
322307 max_profit = max(0, trade.calc_profit_ratio(trade.max_rate))
@@ -336,13 +321,13 @@
336321
337322 # Determine if there is a trend
338323 if self.csell_trend_type.value == 'rmi' or self.csell_trend_type.value == 'any':
339- if rmi_trend == 1:
324+ if current_candle['rmi-up-trend'] == 1:
340325 in_trend = True
341326 if self.csell_trend_type.value == 'ssl' or self.csell_trend_type.value == 'any':
342- if ssl_dir == 'up':
327+ if current_candle['ssl-dir'] == 'up':
343328 in_trend = True
344329 if self.csell_trend_type.value == 'candle' or self.csell_trend_type.value == 'any':
345- if candle_trend == 1:
330+ if current_candle['candle-up-trend'] == 1:
346331 in_trend = True
347332
348333 # Don't sell if we are in a trend unless the pullback threshold is met
@@ -371,7 +356,7 @@
371356 elif current_profit < self.csell_loss_threshold.value:
372357 if self.csell_bail_how.value == 'roc' or self.csell_bail_how.value == 'any':
373358 # Dynamic bailout based on rate of change
374- if sroc <= self.csell_bail_roc.value:
359+ if current_candle['sroc'] <= self.csell_bail_roc.value:
375360 return 'loss_roc'
376361 if self.csell_bail_how.value == 'time' or self.csell_bail_how.value == 'any':
377362 # Dynamic bailout based on time, unless time_trend is true and there is a potential reversal