kikocis/freqtrade-strategies public
Changesets · Branches · Tags · Compare
| Changeset | 8f12c041ed6dd64de3bd924c11c7c29feca1150bde5c186d40957959b0f96355 |
|---|---|
| Author | Bryan Chain <bryan.chain@cerner.com> · 2021-03-29 00:37 -04:00 |
| Committer | Bryan Chain <bryan.chain@cerner.com> · 2021-03-29 00:37 -04:00 |
| Parents | d989c07249bd |
1 file changed
modified strategies/old/Schism.py +127 −117
| @@ -2,6 +2,7 @@ | ||
| 2 | 2 | import talib.abstract as ta |
| 3 | 3 | import freqtrade.vendor.qtpylib.indicators as qtpylib |
| 4 | 4 | import arrow |
| 5 | + | |
| 5 | 6 | from freqtrade.strategy.interface import IStrategy |
| 6 | 7 | from freqtrade.strategy import merge_informative_pair |
| 7 | 8 | from typing import Dict, List, Optional, Tuple |
| @@ -13,9 +14,42 @@ | ||
| 13 | 14 | from statistics import mean |
| 14 | 15 | from cachetools import TTLCache |
| 15 | 16 | |
| 17 | +import pandas as pd | |
| 18 | +pd.options.mode.chained_assignment = None | |
| 19 | + | |
| 16 | 20 | |
| 17 | 21 | """ |
| 18 | -TODO: | |
| 22 | +*** THIS IS YOUR LIVE TRADING COPY *** | |
| 23 | + | |
| 24 | +CURRENTLY MAPS TO DEV STRATEGY: Schism-v2 | |
| 25 | + | |
| 26 | +LAST UPDATED: | |
| 27 | + | |
| 28 | +USD - 03/18/2021 | |
| 29 | +BTC - 03/19/2021 | |
| 30 | +ETH - 03/19/2021 | |
| 31 | + | |
| 32 | +HYPEROPT RESULT: | |
| 33 | + | |
| 34 | +USD - | |
| 35 | + 5m / 1h | |
| 36 | + 2785 trades. 2537/204/44 Wins/Draws/Losses. Avg profit 0.82%. Total profit 1973.03736697 USD ( 2281.86Σ%). Avg duration 657.0 min. Objective: -173.38994 | |
| 37 | +BTC - | |
| 38 | + 15m / 1h | |
| 39 | + 354 trades. 330/24/0 Wins/Draws/Losses. Avg profit 1.26%. Total profit 0.00474543 BTC ( 447.08Σ%). Avg duration 840.0 min. Objective: -129.98745 | |
| 40 | +ETH - | |
| 41 | + 15m / 4h | |
| 42 | + 1402 trades. 1292/78/32 Wins/Draws/Losses. Avg profit 1.11%. Total profit 0.27495824 ETH ( 1460.97Σ%). Avg duration 1249.1 min. Objective: -103.97574 | |
| 43 | + | |
| 44 | +CHANGES FROM DEV DEFAULTS: | |
| 45 | + | |
| 46 | +ROI - NONE | |
| 47 | + | |
| 48 | +STOPLOSS - NONE | |
| 49 | + | |
| 50 | +GENERAL SETTINGS | |
| 51 | +Temporarily setting this to stem some recent losses: | |
| 52 | +use_sell_signal = False | |
| 19 | 53 | |
| 20 | 54 | """ |
| 21 | 55 | |
| @@ -23,46 +57,34 @@ | ||
| 23 | 57 | """ |
| 24 | 58 | Strategy Configuration Items |
| 25 | 59 | """ |
| 60 | + timeframe = '5m' | |
| 61 | + inf_timeframe = '1h' | |
| 26 | 62 | |
| 27 | - # Global Buy/Sell Params | |
| 28 | 63 | buy_params = { |
| 29 | - 'bounce-lookback': 5, | |
| 30 | - 'down-inf-rsi': 64, | |
| 31 | - 'down-mp': 55, | |
| 32 | - 'down-rmi-fast': 31, | |
| 33 | - 'down-rmi-slow': 16, | |
| 34 | - 'up-inf-rsi': 64, | |
| 35 | - 'up-rmi-fast': 31, | |
| 36 | - 'up-rmi-slow': 16, | |
| 37 | - 'xinf-stake-rmi': 67, | |
| 38 | - 'xtf-fiat-rsi': 17, | |
| 39 | - 'xtf-stake-rsi': 57 | |
| 64 | + 'inf-pct-adr': 0.83534, | |
| 65 | + 'inf-rsi': 57, | |
| 66 | + 'mp': 64, | |
| 67 | + 'rmi-fast': 49, | |
| 68 | + 'rmi-slow': 24, | |
| 69 | + 'xinf-stake-rmi': 45, | |
| 70 | + 'xtf-fiat-rsi': 28, | |
| 71 | + 'xtf-stake-rsi': 90 | |
| 40 | 72 | } |
| 41 | 73 | |
| 42 | - sell_params = { | |
| 43 | - 'rmi-high': 50, | |
| 44 | - 'rmi-low': 10 | |
| 45 | - } | |
| 46 | - | |
| 47 | - # Pair Specific Buy/Sell Params | |
| 48 | - buy_params_FOO = {} | |
| 49 | - sell_params_FOO = {} | |
| 50 | - | |
| 51 | - | |
| 52 | - # Other Global Settings | |
| 53 | - timeframe = '5m' | |
| 54 | - inf_timeframe = '1h' | |
| 74 | + sell_params = {} | |
| 55 | 75 | |
| 56 | 76 | minimal_roi = { |
| 57 | - "0": 0.10, | |
| 58 | - "10": 0.05, | |
| 59 | - "30": 0.025, | |
| 60 | - "60": 0.01, | |
| 77 | + "0": 0.05, | |
| 78 | + "10": 0.025, | |
| 79 | + "20": 0.015, | |
| 80 | + "30": 0.01, | |
| 81 | + "720": 0.005, | |
| 61 | 82 | "1440": 0 |
| 62 | 83 | } |
| 63 | 84 | |
| 64 | 85 | stoploss = -0.30 |
| 65 | 86 | |
| 87 | + # Recommended | |
| 66 | 88 | use_sell_signal = False |
| 67 | 89 | sell_profit_only = False |
| 68 | 90 | ignore_roi_if_buy_signal = True |
| @@ -82,7 +104,6 @@ | ||
| 82 | 104 | pairs = self.dp.current_whitelist() |
| 83 | 105 | informative_pairs = [(pair, self.inf_timeframe) for pair in pairs] |
| 84 | 106 | |
| 85 | - """ | |
| 86 | 107 | # add additional informative pairs based on certain stakes |
| 87 | 108 | if self.config['stake_currency'] in ('BTC', 'ETH'): |
| 88 | 109 | for pair in pairs: |
| @@ -95,7 +116,6 @@ | ||
| 95 | 116 | stake_fiat = f"{self.config['stake_currency']}/{self.custom_fiat}" |
| 96 | 117 | informative_pairs += [(stake_fiat, self.timeframe)] |
| 97 | 118 | informative_pairs += [(stake_fiat, self.inf_timeframe)] |
| 98 | - """ | |
| 99 | 119 | |
| 100 | 120 | return informative_pairs |
| 101 | 121 | |
| @@ -103,9 +123,10 @@ | ||
| 103 | 123 | Indicator Definitions |
| 104 | 124 | """ |
| 105 | 125 | def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: |
| 126 | + # Populate/update the trade data if there is any, set trades to false if not live/dry | |
| 106 | 127 | self.custom_trade_info[metadata['pair']] = self.populate_trades(metadata['pair']) |
| 107 | 128 | |
| 108 | - # Relative Momentum Index | |
| 129 | + # Set up primary indicators | |
| 109 | 130 | dataframe['rmi-slow'] = RMI(dataframe, length=21, mom=5) |
| 110 | 131 | dataframe['rmi-fast'] = RMI(dataframe, length=8, mom=4) |
| 111 | 132 | |
| @@ -119,7 +140,6 @@ | ||
| 119 | 140 | dataframe['rmi-up-trend'] = np.where(dataframe['rmi-up'].rolling(3, min_periods=1).sum() >= 2,1,0) |
| 120 | 141 | dataframe['rmi-dn-trend'] = np.where(dataframe['rmi-dn'].rolling(3, min_periods=1).sum() >= 2,1,0) |
| 121 | 142 | |
| 122 | - """ | |
| 123 | 143 | # Informative for STAKE/FIAT and COIN/FIAT on default timeframe, only relevant if stake currency is BTC or ETH |
| 124 | 144 | if self.config['stake_currency'] in ('BTC', 'ETH'): |
| 125 | 145 | coin, stake = metadata['pair'].split('/') |
| @@ -137,12 +157,15 @@ | ||
| 137 | 157 | |
| 138 | 158 | dataframe[f"{stake}_rsi"] = ta.RSI(stake_fiat_tf, timeperiod=14) |
| 139 | 159 | dataframe[f"{stake}_rmi_{self.inf_timeframe}"] = RMI(stake_fiat_inf_tf, length=21, mom=5) |
| 140 | - """ | |
| 141 | 160 | |
| 142 | 161 | # Informative indicators for current pair on inf_timeframe |
| 143 | 162 | informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe) |
| 144 | 163 | informative['rsi'] = ta.RSI(informative, timeperiod=14) |
| 145 | 164 | |
| 165 | + informative['1d_high'] = informative['close'].rolling(24).max() | |
| 166 | + informative['3d_low'] = informative['close'].rolling(72).min() | |
| 167 | + informative['adr'] = informative['1d_high'] - informative['3d_low'] | |
| 168 | + | |
| 146 | 169 | dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True) |
| 147 | 170 | |
| 148 | 171 | return dataframe |
| @@ -155,26 +178,6 @@ | ||
| 155 | 178 | trade_data = self.custom_trade_info[metadata['pair']] |
| 156 | 179 | conditions = [] |
| 157 | 180 | |
| 158 | - # Set up a pre-buy condition that we sort of "cache" | |
| 159 | - dataframe['bounce-pending'] = np.where( | |
| 160 | - (dataframe[f"rsi_{self.inf_timeframe}"] < params['down-inf-rsi']) & | |
| 161 | - (dataframe['rmi-dn-trend'] == 1) & | |
| 162 | - (dataframe['rmi-slow'] > params['down-rmi-slow']) & | |
| 163 | - (dataframe['rmi-fast'] < params['down-rmi-fast']) & | |
| 164 | - (dataframe['mp'] <= params['down-mp']), | |
| 165 | - 1,0 | |
| 166 | - ) | |
| 167 | - | |
| 168 | - # Capture the price where we got the signal that a bounce would happen | |
| 169 | - dataframe['bounce-price'] = np.where( | |
| 170 | - dataframe['bounce-pending'] == 1, | |
| 171 | - dataframe['close'], | |
| 172 | - dataframe['close'].rolling(params['bounce-lookback'], min_periods=1).func() # 4 min/max/mean? | |
| 173 | - ) | |
| 174 | - | |
| 175 | - # Count how many times our pre-bounce happned in the last X candles | |
| 176 | - dataframe['bounce-range'] = np.where(dataframe['bounce-pending'].rolling(params['bounce-lookback'], min_periods=1).sum() >= 1,1,0) | |
| 177 | - | |
| 178 | 181 | # Persist a buy signal for existing trades to make use of ignore_roi_if_buy_signal = True |
| 179 | 182 | # when this buy signal is not present a sell can happen according to the defined ROI table |
| 180 | 183 | if trade_data['active_trade']: |
| @@ -191,25 +194,24 @@ | ||
| 191 | 194 | else: |
| 192 | 195 | # Primary buy triggers |
| 193 | 196 | conditions.append( |
| 194 | - (dataframe[f"rsi_{self.inf_timeframe}"] > params['up-inf-rsi']) & | |
| 195 | - (dataframe['bounce-range'] == 1) & | |
| 196 | - (dataframe['rmi-up-trend'] == 1) & | |
| 197 | - # 3(dataframe['rmi-slow'] < params['up-rmi-slow']) & | |
| 198 | - # 3(dataframe['rmi-fast'] > params['up-rmi-fast']) & | |
| 199 | - (dataframe['close'] > dataframe['bounce-price']) | |
| 197 | + # "buy the dip" based buy signal using momentum pinball and downward RMI | |
| 198 | + (dataframe['close'] <= dataframe[f"3d_low_{self.inf_timeframe}"] + (params['inf-pct-adr'] * dataframe[f"adr_{self.inf_timeframe}"])) & | |
| 199 | + (dataframe[f"rsi_{self.inf_timeframe}"] >= params['inf-rsi']) & | |
| 200 | + (dataframe['rmi-dn-trend'] == 1) & | |
| 201 | + (dataframe['rmi-slow'] >= params['rmi-slow']) & | |
| 202 | + (dataframe['rmi-fast'] <= params['rmi-fast']) & | |
| 203 | + (dataframe['mp'] <= params['mp']) | |
| 200 | 204 | ) |
| 201 | 205 | |
| 202 | - """ | |
| 203 | 206 | # If the stake is BTC or ETH apply additional conditions |
| 204 | 207 | if self.config['stake_currency'] in ('BTC', 'ETH'): |
| 205 | 208 | # default timeframe conditions |
| 206 | 209 | conditions.append( |
| 207 | - (dataframe[f"{self.config['stake_currency']}_rsi"] > params['xtf-stake-rsi']) | | |
| 208 | - (dataframe[f"{self.custom_fiat}_rsi"] < params['xtf-fiat-rsi']) | |
| 210 | + (dataframe[f"{self.config['stake_currency']}_rsi"] < params['xtf-stake-rsi']) | | |
| 211 | + (dataframe[f"{self.custom_fiat}_rsi"] > params['xtf-fiat-rsi']) | |
| 209 | 212 | ) |
| 210 | 213 | # informative timeframe conditions |
| 211 | 214 | conditions.append(dataframe[f"{self.config['stake_currency']}_rmi_{self.inf_timeframe}"] < params['xinf-stake-rmi']) |
| 212 | - """ | |
| 213 | 215 | |
| 214 | 216 | # Anything below here applies to persisting and new buy signal |
| 215 | 217 | conditions.append(dataframe['volume'].gt(0)) |
| @@ -222,28 +224,38 @@ | ||
| 222 | 224 | return dataframe |
| 223 | 225 | |
| 224 | 226 | """ |
| 225 | - Sell Trigger Signals: | |
| 226 | - In this strategy all sells for profit happen according to ROI | |
| 227 | - This sell signal is designed only as a "dynamic stoploss" | |
| 227 | + Sell Trigger Signals | |
| 228 | 228 | """ |
| 229 | 229 | def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: |
| 230 | 230 | params = self.get_pair_params(metadata['pair'], 'sell') |
| 231 | 231 | trade_data = self.custom_trade_info[metadata['pair']] |
| 232 | 232 | conditions = [] |
| 233 | 233 | |
| 234 | - # add additional conditions based on time and profit | |
| 234 | + # In this strategy all sells for profit happen according to ROI | |
| 235 | + # This sell signal is designed only as a "dynamic stoploss" | |
| 236 | + | |
| 237 | + # if we are in an active trade for this pair | |
| 235 | 238 | if trade_data['active_trade']: |
| 236 | - # give some wiggle room for the trade to go negative a little bit before selling | |
| 237 | 239 | # grow from -0.03 -> 0 after 300 minutes starting immediately |
| 238 | 240 | loss_cutoff = self.linear_growth(-0.03, 0, 0, 300, trade_data['open_minutes']) |
| 239 | 241 | |
| 240 | 242 | # if we are at a loss, consider what the trend looks and preempt the stoploss |
| 241 | 243 | conditions.append( |
| 242 | 244 | (trade_data['current_profit'] < loss_cutoff) & |
| 243 | - (trade_data['current_profit'] > self.stoploss) | |
| 245 | + (trade_data['current_profit'] > self.stoploss) & | |
| 246 | + (dataframe['rmi-dn-trend'] == 1) & | |
| 247 | + (dataframe['volume'].gt(0)) | |
| 244 | 248 | ) |
| 249 | + | |
| 250 | + # if the peak profit was positive at some point but never reached ROI, set a higher cross point for exit | |
| 251 | + if trade_data['peak_profit'] > 0: | |
| 252 | + conditions.append(qtpylib.crossed_below(dataframe['rmi-slow'], 50)) | |
| 253 | + # if the trade was always negative, the bounce we expected didn't happen | |
| 254 | + else: | |
| 255 | + conditions.append(qtpylib.crossed_below(dataframe['rmi-slow'], 10)) | |
| 245 | 256 | |
| 246 | - # if we have other trades, consider their profit and the # of free slots in the sell | |
| 257 | + # if there are other open trades in addition to this one, consider the average profit | |
| 258 | + # across them all and how many free slots we have in our sell decision | |
| 247 | 259 | if trade_data['other_trades']: |
| 248 | 260 | if trade_data['free_slots'] > 0: |
| 249 | 261 | """ |
| @@ -252,21 +264,16 @@ | ||
| 252 | 264 | 1 slot = 1/1 * -0.04 = -0.04 -> only allow sells if avg_other_proift above -0.04 |
| 253 | 265 | 4 slot = 1/4 * -0.04 = -0.01 -> only allow sells is avg_other_profit above -0.01 |
| 254 | 266 | """ |
| 255 | - max_market_down = -0.04 # 5% | |
| 267 | + max_market_down = -0.04 | |
| 256 | 268 | hold_pct = (1/trade_data['free_slots']) * max_market_down |
| 257 | 269 | conditions.append(trade_data['avg_other_profit'] >= hold_pct) |
| 258 | 270 | else: |
| 259 | 271 | # if were out of slots, allow the biggest losing trade to sell regardless of avg profit |
| 260 | 272 | conditions.append(trade_data['biggest_loser'] == True) |
| 261 | 273 | |
| 262 | - conditions.append((dataframe['rmi-dn-trend'] == 1)) | |
| 263 | - # provide multiple cross thresholds in case we are coming from a higher point | |
| 264 | - conditions.append( | |
| 265 | - qtpylib.crossed_below(dataframe['rmi-slow'], params['rmi-high']) | | |
| 266 | - qtpylib.crossed_below(dataframe['rmi-slow'], params['rmi-low']) | |
| 267 | - ) | |
| 268 | - | |
| 269 | - conditions.append(dataframe['volume'].gt(0)) | |
| 274 | + # Impossible condition to satisfy the bot when it looks here and theres no active trade | |
| 275 | + else: | |
| 276 | + conditions.append(dataframe['volume'].lt(0)) | |
| 270 | 277 | |
| 271 | 278 | if conditions: |
| 272 | 279 | dataframe.loc[ |
| @@ -276,7 +283,7 @@ | ||
| 276 | 283 | return dataframe |
| 277 | 284 | |
| 278 | 285 | """ |
| 279 | - Custom Methods | |
| 286 | + Super Legit Custom Methods | |
| 280 | 287 | """ |
| 281 | 288 | # Populate trades_data from the database |
| 282 | 289 | def populate_trades(self, pair: str) -> dict: |
| @@ -355,11 +362,8 @@ | ||
| 355 | 362 | self.custom_current_price_cache[pair] = rate |
| 356 | 363 | return rate |
| 357 | 364 | |
| 358 | - """ | |
| 359 | - Simple linear growth function: | |
| 360 | - Starts at X and grows to Y after A minutes (starting after B miniutes) | |
| 361 | - f(t) = X + (rate * t), where rate = (Y - X) / (B - A) | |
| 362 | - """ | |
| 365 | + # linear growth, starts at X and grows to Y after A minutes (starting after B miniutes) | |
| 366 | + # f(t) = X + (rate * t), where rate = (Y - X) / (A - B) | |
| 363 | 367 | def linear_growth(self, start: float, end: float, start_time: int, end_time: int, trade_time: int) -> float: |
| 364 | 368 | time = max(0, trade_time - start_time) |
| 365 | 369 | rate = (end - start) / (end_time - start_time) |
| @@ -369,7 +373,7 @@ | ||
| 369 | 373 | Allow for buy/sell override parameters per pair. Testing, might remove. |
| 370 | 374 | TODO: |
| 371 | 375 | If good: make this more robust so you never have to edit this method. |
| 372 | - Consider: per-pair ROI work if it seems worthwhile? | |
| 376 | + Consider: per-pair ROI if it seems worthwhile? | |
| 373 | 377 | """ |
| 374 | 378 | def get_pair_params(self, pair: str, side: str) -> Dict: |
| 375 | 379 | buy_params = self.buy_params |
| @@ -426,24 +430,27 @@ | ||
| 426 | 430 | # Sub-strategy with parameters specific to BTC stake |
| 427 | 431 | class Schism_BTC(Schism): |
| 428 | 432 | |
| 429 | - timeframe = '1h' | |
| 430 | - inf_timeframe = '4h' | |
| 431 | - | |
| 432 | - buy_params = { | |
| 433 | - 'inf-rsi': 64, | |
| 434 | - 'mp': 55, | |
| 435 | - 'rmi-fast': 31, | |
| 436 | - 'rmi-slow': 16, | |
| 437 | - 'xinf-stake-rmi': 67, | |
| 438 | - 'xtf-fiat-rsi': 17, | |
| 439 | - 'xtf-stake-rsi': 57 | |
| 440 | - } | |
| 433 | + timeframe = '15m' | |
| 434 | + inf_timeframe = '1h' | |
| 441 | 435 | |
| 442 | 436 | minimal_roi = { |
| 443 | 437 | "0": 0.05, |
| 444 | - "240": 0.025, | |
| 445 | - "1440": 0.01, | |
| 446 | - "4320": 0 | |
| 438 | + "30": 0.025, | |
| 439 | + "60": 0.015, | |
| 440 | + "90": 0.01, | |
| 441 | + "1440": 0.005, | |
| 442 | + "2880": 0 | |
| 443 | + } | |
| 444 | + | |
| 445 | + buy_params = { | |
| 446 | + 'inf-pct-adr': 0.80616, | |
| 447 | + 'inf-rsi': 14, | |
| 448 | + 'mp': 43, | |
| 449 | + 'rmi-fast': 33, | |
| 450 | + 'rmi-slow': 16, | |
| 451 | + 'xinf-stake-rmi': 29, | |
| 452 | + 'xtf-fiat-rsi': 49, | |
| 453 | + 'xtf-stake-rsi': 53 | |
| 447 | 454 | } |
| 448 | 455 | |
| 449 | 456 | use_sell_signal = False |
| @@ -451,24 +458,27 @@ | ||
| 451 | 458 | # Sub-strategy with parameters specific to ETH stake |
| 452 | 459 | class Schism_ETH(Schism): |
| 453 | 460 | |
| 454 | - timeframe = '1h' | |
| 461 | + timeframe = '15m' | |
| 455 | 462 | inf_timeframe = '4h' |
| 456 | 463 | |
| 457 | - buy_params = { | |
| 458 | - 'inf-rsi': 13, | |
| 459 | - 'inf-stake-rmi': 69, | |
| 460 | - 'mp': 40, | |
| 461 | - 'rmi-fast': 42, | |
| 462 | - 'rmi-slow': 17, | |
| 463 | - 'tf-fiat-rsi': 15, | |
| 464 | - 'tf-stake-rsi': 92 | |
| 465 | - } | |
| 466 | - | |
| 467 | 464 | minimal_roi = { |
| 468 | 465 | "0": 0.05, |
| 469 | - "240": 0.025, | |
| 470 | - "1440": 0.01, | |
| 471 | - "4320": 0 | |
| 466 | + "30": 0.025, | |
| 467 | + "60": 0.015, | |
| 468 | + "90": 0.01, | |
| 469 | + "1440": 0.005, | |
| 470 | + "2880": 0 | |
| 471 | + } | |
| 472 | + | |
| 473 | + buy_params = { | |
| 474 | + 'inf-pct-adr': 0.74476, | |
| 475 | + 'inf-rsi': 43, | |
| 476 | + 'mp': 44, | |
| 477 | + 'rmi-fast': 32, | |
| 478 | + 'rmi-slow': 29, | |
| 479 | + 'xinf-stake-rmi': 49, | |
| 480 | + 'xtf-fiat-rsi': 45, | |
| 481 | + 'xtf-stake-rsi': 67 | |
| 472 | 482 | } |
| 473 | 483 | |
| 474 | 484 | use_sell_signal = False |
| No newline at the end of the file |