kikocis/freqtrade-strategies public
Changesets · Branches · Tags · Compare
| Changeset | 844f22e321900b6c215ce0f8591db4310b8c110d66791fd3db9b531e10135946 |
|---|---|
| Author | Bryan Chain <bryan.chain@cerner.com> · 2021-05-11 01:07 -04:00 |
| Committer | Bryan Chain <bryan.chain@cerner.com> · 2021-05-11 01:07 -04:00 |
| Parents | 28b2bf4d2b8f |
1 file changed
modified strategies/Solipsis_v5.py +14 −29
| @@ -3,7 +3,7 @@ | ||
| 3 | 3 | import freqtrade.vendor.qtpylib.indicators as qtpylib |
| 4 | 4 | import arrow |
| 5 | 5 | |
| 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, | |
| 7 | 7 | IntParameter, DecimalParameter, CategoricalParameter) |
| 8 | 8 | |
| 9 | 9 | from typing import Dict, List, Optional, Tuple, Union |
| @@ -34,7 +34,7 @@ | ||
| 34 | 34 | |
| 35 | 35 | I take no responsibility for any success or failure you have using this strategy. |
| 36 | 36 | |
| 37 | -VERSION: 5.1.2 | |
| 37 | +VERSION: 5.1.3 | |
| 38 | 38 | """ |
| 39 | 39 | |
| 40 | 40 | class Solipsis5(IStrategy): |
| @@ -59,7 +59,7 @@ | ||
| 59 | 59 | ## Sell Space Params are being used for both custom_stoploss and custom_sell |
| 60 | 60 | |
| 61 | 61 | # 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) | |
| 63 | 63 | csell_roi_time = IntParameter(720, 1440, default=720, space='sell') |
| 64 | 64 | csell_roi_start = DecimalParameter(0.01, 0.05, default=0.01, space='sell') |
| 65 | 65 | csell_roi_end = DecimalParameter(0.0, 0.01, default=0, space='sell') |
| @@ -70,7 +70,7 @@ | ||
| 70 | 70 | |
| 71 | 71 | # Custom Sell Loss (formerly Custom Stoploss) |
| 72 | 72 | 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) | |
| 74 | 74 | csell_bail_roc = DecimalParameter(-5.0, -1.0, default=-3.0, space='sell') |
| 75 | 75 | csell_bail_time = IntParameter(720, 1440, default=720, space='sell') |
| 76 | 76 | csell_bail_time_trend = CategoricalParameter([True, False], default=True, space='sell', optimize=True) |
| @@ -133,7 +133,8 @@ | ||
| 133 | 133 | def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: |
| 134 | 134 | if not metadata['pair'] in self.custom_trade_info: |
| 135 | 135 | 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 | |
| 137 | 138 | |
| 138 | 139 | ## Base Timeframe / Pair |
| 139 | 140 | |
| @@ -218,13 +219,6 @@ | ||
| 218 | 219 | dataframe['BTC_close'] = btc_stake_tf['close'] |
| 219 | 220 | dataframe['BTC_kama'] = ta.KAMA(btc_stake_tf, length=144) |
| 220 | 221 | |
| 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 | - | |
| 228 | 222 | return dataframe |
| 229 | 223 | |
| 230 | 224 | """ |
| @@ -303,20 +297,11 @@ | ||
| 303 | 297 | Current implementation is meant to behave similar to my original "dynamic_roi" concept when in profit |
| 304 | 298 | or like the original "custom_stoploss" when at a loss. |
| 305 | 299 | """ |
| 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): | |
| 308 | 302 | |
| 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() | |
| 320 | 305 | |
| 321 | 306 | trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) |
| 322 | 307 | max_profit = max(0, trade.calc_profit_ratio(trade.max_rate)) |
| @@ -336,13 +321,13 @@ | ||
| 336 | 321 | |
| 337 | 322 | # Determine if there is a trend |
| 338 | 323 | 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: | |
| 340 | 325 | in_trend = True |
| 341 | 326 | 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': | |
| 343 | 328 | in_trend = True |
| 344 | 329 | 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: | |
| 346 | 331 | in_trend = True |
| 347 | 332 | |
| 348 | 333 | # Don't sell if we are in a trend unless the pullback threshold is met |
| @@ -371,7 +356,7 @@ | ||
| 371 | 356 | elif current_profit < self.csell_loss_threshold.value: |
| 372 | 357 | if self.csell_bail_how.value == 'roc' or self.csell_bail_how.value == 'any': |
| 373 | 358 | # 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: | |
| 375 | 360 | return 'loss_roc' |
| 376 | 361 | if self.csell_bail_how.value == 'time' or self.csell_bail_how.value == 'any': |
| 377 | 362 | # Dynamic bailout based on time, unless time_trend is true and there is a potential reversal |