Elffuss BraidHub

kikocis/freqtrade-strategies public

retired Schism from live
Changeset8f12c041ed6dd64de3bd924c11c7c29feca1150bde5c186d40957959b0f96355
AuthorBryan Chain <bryan.chain@cerner.com> · 2021-03-29 00:37 -04:00
CommitterBryan Chain <bryan.chain@cerner.com> · 2021-03-29 00:37 -04:00
Parentsd989c07249bd

Browse the files at this changeset

1 file changed

modified strategies/old/Schism.py +127 −117
@@ -2,6 +2,7 @@
22 import talib.abstract as ta
33 import freqtrade.vendor.qtpylib.indicators as qtpylib
44 import arrow
5+
56 from freqtrade.strategy.interface import IStrategy
67 from freqtrade.strategy import merge_informative_pair
78 from typing import Dict, List, Optional, Tuple
@@ -13,9 +14,42 @@
1314 from statistics import mean
1415 from cachetools import TTLCache
1516
17+import pandas as pd
18+pd.options.mode.chained_assignment = None
19+
1620
1721 """
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
1953
2054 """
2155
@@ -23,46 +57,34 @@
2357 """
2458 Strategy Configuration Items
2559 """
60+ timeframe = '5m'
61+ inf_timeframe = '1h'
2662
27- # Global Buy/Sell Params
2863 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
4072 }
4173
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 = {}
5575
5676 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,
6182 "1440": 0
6283 }
6384
6485 stoploss = -0.30
6586
87+ # Recommended
6688 use_sell_signal = False
6789 sell_profit_only = False
6890 ignore_roi_if_buy_signal = True
@@ -82,7 +104,6 @@
82104 pairs = self.dp.current_whitelist()
83105 informative_pairs = [(pair, self.inf_timeframe) for pair in pairs]
84106
85- """
86107 # add additional informative pairs based on certain stakes
87108 if self.config['stake_currency'] in ('BTC', 'ETH'):
88109 for pair in pairs:
@@ -95,7 +116,6 @@
95116 stake_fiat = f"{self.config['stake_currency']}/{self.custom_fiat}"
96117 informative_pairs += [(stake_fiat, self.timeframe)]
97118 informative_pairs += [(stake_fiat, self.inf_timeframe)]
98- """
99119
100120 return informative_pairs
101121
@@ -103,9 +123,10 @@
103123 Indicator Definitions
104124 """
105125 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
106127 self.custom_trade_info[metadata['pair']] = self.populate_trades(metadata['pair'])
107128
108- # Relative Momentum Index
129+ # Set up primary indicators
109130 dataframe['rmi-slow'] = RMI(dataframe, length=21, mom=5)
110131 dataframe['rmi-fast'] = RMI(dataframe, length=8, mom=4)
111132
@@ -119,7 +140,6 @@
119140 dataframe['rmi-up-trend'] = np.where(dataframe['rmi-up'].rolling(3, min_periods=1).sum() >= 2,1,0)
120141 dataframe['rmi-dn-trend'] = np.where(dataframe['rmi-dn'].rolling(3, min_periods=1).sum() >= 2,1,0)
121142
122- """
123143 # Informative for STAKE/FIAT and COIN/FIAT on default timeframe, only relevant if stake currency is BTC or ETH
124144 if self.config['stake_currency'] in ('BTC', 'ETH'):
125145 coin, stake = metadata['pair'].split('/')
@@ -137,12 +157,15 @@
137157
138158 dataframe[f"{stake}_rsi"] = ta.RSI(stake_fiat_tf, timeperiod=14)
139159 dataframe[f"{stake}_rmi_{self.inf_timeframe}"] = RMI(stake_fiat_inf_tf, length=21, mom=5)
140- """
141160
142161 # Informative indicators for current pair on inf_timeframe
143162 informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe)
144163 informative['rsi'] = ta.RSI(informative, timeperiod=14)
145164
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+
146169 dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True)
147170
148171 return dataframe
@@ -155,26 +178,6 @@
155178 trade_data = self.custom_trade_info[metadata['pair']]
156179 conditions = []
157180
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-
178181 # Persist a buy signal for existing trades to make use of ignore_roi_if_buy_signal = True
179182 # when this buy signal is not present a sell can happen according to the defined ROI table
180183 if trade_data['active_trade']:
@@ -191,25 +194,24 @@
191194 else:
192195 # Primary buy triggers
193196 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'])
200204 )
201205
202- """
203206 # If the stake is BTC or ETH apply additional conditions
204207 if self.config['stake_currency'] in ('BTC', 'ETH'):
205208 # default timeframe conditions
206209 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'])
209212 )
210213 # informative timeframe conditions
211214 conditions.append(dataframe[f"{self.config['stake_currency']}_rmi_{self.inf_timeframe}"] < params['xinf-stake-rmi'])
212- """
213215
214216 # Anything below here applies to persisting and new buy signal
215217 conditions.append(dataframe['volume'].gt(0))
@@ -222,28 +224,38 @@
222224 return dataframe
223225
224226 """
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
228228 """
229229 def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
230230 params = self.get_pair_params(metadata['pair'], 'sell')
231231 trade_data = self.custom_trade_info[metadata['pair']]
232232 conditions = []
233233
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
235238 if trade_data['active_trade']:
236- # give some wiggle room for the trade to go negative a little bit before selling
237239 # grow from -0.03 -> 0 after 300 minutes starting immediately
238240 loss_cutoff = self.linear_growth(-0.03, 0, 0, 300, trade_data['open_minutes'])
239241
240242 # if we are at a loss, consider what the trend looks and preempt the stoploss
241243 conditions.append(
242244 (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))
244248 )
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))
245256
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
247259 if trade_data['other_trades']:
248260 if trade_data['free_slots'] > 0:
249261 """
@@ -252,21 +264,16 @@
252264 1 slot = 1/1 * -0.04 = -0.04 -> only allow sells if avg_other_proift above -0.04
253265 4 slot = 1/4 * -0.04 = -0.01 -> only allow sells is avg_other_profit above -0.01
254266 """
255- max_market_down = -0.04 # 5%
267+ max_market_down = -0.04
256268 hold_pct = (1/trade_data['free_slots']) * max_market_down
257269 conditions.append(trade_data['avg_other_profit'] >= hold_pct)
258270 else:
259271 # if were out of slots, allow the biggest losing trade to sell regardless of avg profit
260272 conditions.append(trade_data['biggest_loser'] == True)
261273
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))
270277
271278 if conditions:
272279 dataframe.loc[
@@ -276,7 +283,7 @@
276283 return dataframe
277284
278285 """
279- Custom Methods
286+ Super Legit Custom Methods
280287 """
281288 # Populate trades_data from the database
282289 def populate_trades(self, pair: str) -> dict:
@@ -355,11 +362,8 @@
355362 self.custom_current_price_cache[pair] = rate
356363 return rate
357364
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)
363367 def linear_growth(self, start: float, end: float, start_time: int, end_time: int, trade_time: int) -> float:
364368 time = max(0, trade_time - start_time)
365369 rate = (end - start) / (end_time - start_time)
@@ -369,7 +373,7 @@
369373 Allow for buy/sell override parameters per pair. Testing, might remove.
370374 TODO:
371375 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?
373377 """
374378 def get_pair_params(self, pair: str, side: str) -> Dict:
375379 buy_params = self.buy_params
@@ -426,24 +430,27 @@
426430 # Sub-strategy with parameters specific to BTC stake
427431 class Schism_BTC(Schism):
428432
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'
441435
442436 minimal_roi = {
443437 "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
447454 }
448455
449456 use_sell_signal = False
@@ -451,24 +458,27 @@
451458 # Sub-strategy with parameters specific to ETH stake
452459 class Schism_ETH(Schism):
453460
454- timeframe = '1h'
461+ timeframe = '15m'
455462 inf_timeframe = '4h'
456463
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-
467464 minimal_roi = {
468465 "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
472482 }
473483
474484 use_sell_signal = False
No newline at the end of the file