kikocis/freqtrade-strategies public
Changesets · Branches · Tags · Compare
| Changeset | dd8fdd3433c10db34bab3a356c2216980e54f1873a5026af0f649c8c6ddb37d6 |
|---|---|
| Author | Bryan Chain <bryan.chain@cerner.com> · 2021-04-29 12:29 -04:00 |
| Committer | Bryan Chain <bryan.chain@cerner.com> · 2021-04-29 12:29 -04:00 |
| Parents | 579adb4b8330 |
6 files changed
modified README.md +55 −28
| @@ -17,23 +17,22 @@ | ||
| 17 | 17 | ### TODO |
| 18 | 18 | |
| 19 | 19 | - Continue to improve buy signal. Ideas are welcome! |
| 20 | -- Continue to optimize and innovate around dynamic ROI idea. | |
| 21 | -- Further enchance and optimize custom stop loss | |
| 20 | +- Continue to optimize and innovate around dynamic ROI idea (now custom_sell!) | |
| 21 | +- Further enchance and optimize custom stop loss (now part of custom_sell!) | |
| 22 | 22 | - Continue to evaluate good circumstances to bail and sell vs hold on for recovery |
| 23 | 23 | - Curent implementation seems to work pretty well but feel like there is room for improvement. |
| 24 | 24 | - Consider some factors for how "strong" the buy signal is and consider a way to evaluate informative pairs/timeframes for how careful we should be when entering. For example, if BTC oracle says to be cautious, require a stronger buy signal for entry? |
| 25 | 25 | |
| 26 | 26 | ### Features |
| 27 | 27 | |
| 28 | -- **Dynamic ROI** | |
| 29 | - - Essentially the idea is to override the static ROI table when there is a trend to allow for larger profits. | |
| 30 | -- **Custom Stoploss** | |
| 31 | - - Generally a vanilla implementation of Freqtrade custom stoploss but tries to do some clever things. Uses indicator data. (Thanks @JoeSchr!) | |
| 28 | +- **Custom Sell** *(previously Dynamic ROI)* | |
| 29 | + - In profit the idea is to override the static ROI table when there is a trend to allow for larger profits. | |
| 30 | + - In loss the idea is to behave like a "dynamic bailout" that preempts the stoploss when certain criteria are met. | |
| 32 | 31 | - **Dynamic informative indicators** based on certain stake currences and whitelist contents. |
| 33 | 32 | - If BTC/STAKE is not in whitelist, make sure to use that for an informative. (This is important for strategy performance) |
| 34 | 33 | - If your stake is BTC or ETH, use COIN/FIAT and BTC/FIAT as informatives. |
| 35 | -- Custom indicator file to keep primary strategy clean(ish). | |
| 36 | -- Child strategy for stake specific settings and different settings for different instances, hoping to keep this strategy file relatively clutter-free from the extensive options available. I personally use the child strategy to also document the current optimization results the strategy is running off of so I can reference them easily in subsequent optimization runs. | |
| 34 | +- **Custom indicator file** to keep primary strategy clean(ish). | |
| 35 | +- **Child strategy** for stake specific settings and different settings for different instances, hoping to keep this strategy file relatively clutter-free from the extensive options available. I personally use the child strategy to also document the current optimization results the strategy is running off of so I can reference them easily in subsequent optimization runs. | |
| 37 | 36 | |
| 38 | 37 | ## Overview and Theory |
| 39 | 38 | |
| @@ -44,42 +43,72 @@ | ||
| 44 | 43 | - Based on my testing when removing BTC/STAKE from the whitelist and using it as an informative provides a significant positive impact on strategy performance. *This feature can be disabled simply by having BTC/STAKE in your whitelist.* |
| 45 | 44 | - When stake is BTC or ETH, lets say we have XLM/BTC in our whitelist and our chosen stablecoin/fiat is USD. In this case XLM/USD and BTC/USD will be used as informative pairs for the XLM/BTC trade. Idea is if XLM/USD is strong, or BTC/USD is weak, then XLM/BTC is likely to go up. Conversely, if BTC/USD is very strong and XLM/USD is weak or neutral, then XLM/BTC is likely to go down. |
| 46 | 45 | |
| 47 | -- **Dynamic ROI** | |
| 48 | - - To enable dynamic_roi for use you must set `use_dynamic_roi` to `True` | |
| 49 | - - Fundamentally, the idea is to override the base ROI table when an upward trend is present. This has been enhanced/extended in several ways. | |
| 50 | - - A sell will not happen when a strong enough upward trend is present, but a sell can happen when either the trend disappears or profit has retreated too far from the peak observed point and we are above the current `minimal_roi` table point. | |
| 51 | - | |
| 52 | -- **Custom Stoploss** | |
| 53 | - - To enable the custom_stoploss for use you must set `use_custom_stoploss` to `True` | |
| 54 | - - The stoploss is static as defined usually but a sell will happen if certain conditions are met. This is able to be hyperopted. | |
| 55 | - - If profit is below our defined threshold, and some conditions are met, sell. | |
| 56 | - - This is essentially just a sell trigger that uses an amount of profit (loss) as the primary guard. | |
| 46 | +- **Custom Sell** *(combined previous Dynamic ROI and Custom Stoploss)* | |
| 47 | + - Logic is enclosed in the `custom_sell` method but the goal is to behave like a dynamic ROI table in line with my previous `dynamic_roi` implementation. | |
| 48 | + - **In Profit** (formerly Dynamic ROI): | |
| 49 | + - Fundamentally, we do not use the standard `minimal_roi` table at all (by setting "0": 100) and instead use the `custom_sell` method combined with defined ROI values and trends to identify when to sell. | |
| 50 | + - You can define how the base ROI value works by setting the type to either `static`, `decay` or `step`. This is the effective "minimum_roi" value at any given time which will still be overridden in a trend, producing the "dynamic" nature of the signal. | |
| 51 | + - `static` will use the `csell_roi_start` value as the minimum_roi value and never change | |
| 52 | + - `decay` will decay in a linear manner between `csell_roi_start` to `csell_roi_end` over `csell_roi_time`. | |
| 53 | + - `step` will start at `csell_roi_start` and then become `csell_roi_end` after `csell_roi_time` | |
| 54 | + - You can disable the custom_sell by setting `use_custom_sell` to `False` and putting a standard `minimal_roi` table in the config. | |
| 55 | + - Again, this will function similar to the previous dynamic_roi, meaning: | |
| 56 | + - The `csell_roi_type` is effectively setting the `minimum_roi` just like the table, if there is a trend, we will not sell. If there is not a trend, we will fall back to this value to decide if we sell or not. | |
| 57 | + - Similarly, if we are in a trend, but the price pulls back from the max too much (as defined by our variables), we will also sell. | |
| 58 | + - Outside of a trend, the static, decaying, or stepped `minimal_roi` value is how a sell is determined. | |
| 59 | + - `custom_sell` will produce the following sell reasons to backtesting and telegram (a sell happened because...): | |
| 60 | + - `trend_roi` - There was a trend we were in and it has ended, ROI point was met and we sold (no pullback) | |
| 61 | + - `notrend_roi` - There was no trend and our desired ROI point was met | |
| 62 | + - `intrend_pullback_roi` - We are in a trend but the profit pulled back too far from the peak, min_roi was still met | |
| 63 | + - `intrend_pullback_noroi` - We are in a trend but the profit pulled back too far from the peak, min_roi was NOT met | |
| 64 | + - **In Loss** (formerly Custom Stoploss): | |
| 65 | + - The stoploss is static as defined usually but a sell will happen in a loss, prior to the stoploss, if certain conditions are met. This is able to be hyperopted. | |
| 66 | + - If **profit is below our defined threshold**, and some conditions are met, sell at a loss, for example: | |
| 67 | + - Depending on the `bail_how` setting, we will sell out of what is considered a bad trade based on either the `sroc` value, or a `timeout` value. In the case of the timeout it is also possible to override the timeout in the case of a positive trend. The idea there is that if the time has passed, but the trade is on its way back up, don't bail out unless the trend disappears. | |
| 57 | 68 | |
| 58 | 69 | ## Notes and Recommendations |
| 59 | 70 | |
| 60 | -- For whatever reason, hyperopt will not run from the child strategy, so point at SolipsisX (where X is the current version) directly in your hyperopt command. | |
| 71 | +- If using a standard looking `minimal_roi` dict, instead of the one I have provided, sells **can** and **will** happen as per standard freqtrade ROI functionality and the `custom_sell` will very likely not do anything. This is fine if this is your desired functionality, just be aware of it. Using a standard `minimal_roi` table is **not** recommended. | |
| 61 | 72 | - If trading on a stablecoin or fiat stake (such as USD, EUR, USDT, etc.) it is *highly recommended* that you remove BTC/STAKE from your whitelist as this strategy performs much better on alts when using BTC as an informative but does not buy any BTC itself. |
| 62 | 73 | - It is recommended to configure protections *if/as* you will use them in live and run *some* hyperopt/backtest with "--enable-protections" as this strategy will hit a lot of stoplosses (as we use it like a sell) so the stoploss protection is helpful to test. *However* - this option makes hyperopt very slow, so run your initial backtest/hyperopts without this option. Once you settle on a baseline set of options, do some final optimizations with protections on. |
| 63 | -- It is *not* recommended to use freqtrades built-in trailing stop, nor to hyperopt for that. | |
| 74 | +- It is *probably not* recommended to use freqtrades built-in trailing stop, nor to hyperopt for that, although feel free to experiment. | |
| 64 | 75 | - It is *highly* recommended to hyperopt this with '--spaces buy sell' only and at least 1000 total epochs several times. There are a lot of variables being hyperopted and it may take a lot of epochs to find the right settings. |
| 65 | -- It is possible to hyperopt the custom stoploss and dynamic ROI settings, this is done by including the 'sell' space in your hyperopt. | |
| 66 | 76 | - Hyperopt Notes: |
| 67 | - - `custom_stoploss` and `dynamic_roi` are hyperopted as part of the `sell` space. | |
| 68 | - - You need to set either (or both) `use_custom_stoploss` / `use_dynamic_roi` to `True` to make the sell space hyperopt these spaces, as well keep them enabled to have those settings impact a backtest or running strategy. You can hyperopt one space at a time by using different combinations of true/false here. | |
| 69 | - - Just food for thought, hyperopting buy/custom-stoploss/dynamic-roi together takes a LOT of repeat 1000 epoch runs to get optimal results. There are a ton of variables moving around and often times the **reported best epoch is not always desirable**, so make sure to look through the results and not just assume the "best" one is actually the best. | |
| 77 | + - Just food for thought, hyperopting buy and custom-sell together takes a LOT of repeat 1000 epoch runs to get optimal results. There are a ton of variables moving around and often times the **reported best epoch is not always desirable**, so make sure to look through the results and not just assume the "best" one is actually the best. | |
| 70 | 78 | - Avoid hyperopt results with very small avg. profit and avg. duration of < 60m (in my opinion.) - This is best done by setting --min-trades to something as to prevent the loss function from going toward very small numbers of trades that inflate the loss function result. |
| 71 | 79 | - The hyperopt loss function you use will have a massive impact on how aggressive the strategy is. I find `Sharpe` to lean towards pretty aggresive buys and `SortinoDaily` to produce the most conservative results. |
| 72 | 80 | - I personally re-run it until I find epochs with at least 0.5% avg profit and a 10:1 w/l ratio as my personal preference. |
| 73 | -- It is *recommended* to leave the base strategy file untouched and do your configuration from the child strategy Solipsis.py. | |
| 81 | +- It is *recommended* to leave the base strategy file untouched and do your configuration/paste hyperopt params into the child strategy Solipsis.py. | |
| 74 | 82 | - You can adjust how aggressive/conservative the buy is by changing/restricting the hyperopt ranges, for example: |
| 75 | 83 | - Setting the minimum `base_ma_streak` value > 1 dramatically reduces the # of trades |
| 76 | 84 | - Changing optimize to False on the `base_trigger` and `xbtc_guard` and using default of `pcc` and `strict` respectively |
| 77 | -- You might consider playing with some of the indicator periods defined, especially the `T3`, `mastreak`, and `pcc` as they have a rather dramatic impact. | |
| 85 | +- You might consider playing with some of the indicator periods defined, especially the `kama`, `mastreak`, and `pcc` as they have a rather dramatic impact. | |
| 78 | 86 | |
| 79 | 87 | ## Changelog |
| 80 | 88 | |
| 81 | 89 | **Note:** Comprehensive changelog has only been kept since v3, April 03, 2021 release. Prior change details are summary only. |
| 82 | 90 | |
| 91 | +### v5 | |
| 92 | + | |
| 93 | +April 29, 2021 (version 5.0): | |
| 94 | +- **General Changes** | |
| 95 | + - **ATTENTION** The strategy will *appear* to work fine even if you are not on the latest develop branch which includes the `custom_sell` functionality. Unless you see custom sell reasons in the sell table after backtesting, you need to make sure you pull the latest develop code to your installation or pull the latest :develop container! | |
| 96 | + - I know v4 wasn't out for very long before this jump but the new `custom_sell` method in current freqtrade develop created an opportunity to change/improve a lot of things. | |
| 97 | + - Updated the child strategy such that you can call hyperopt from it now without errors. | |
| 98 | + - Removed the "default" `buy_params` and `sell_params` to force users to hyperopt prior to testing. This strategy **requires** hyperopting and there is no one-size-fits-all set of parameters. I wanted to discourage people from downloading this, backtesting with my base set of params and complaining. | |
| 99 | + - I also hope this might encourage folks to keep their specific optimized settings in the child-strategy and use that. | |
| 100 | + - Changed out `dynamic_roi` and `custom_stoploss` to use the new `custom_sell` feature in the latest freqtrade develop branch, functionally it should be very similar but is more compliant / supported by freqtrade as I am no longer overloading the roi methods. This should be a much better path forward. | |
| 101 | + - Consequently, this means you **must** be on the latest freqtrade develop branch on your local installation or container. | |
| 102 | + - Added a version tag in the header of the strategy for sub-releases, (e.g. 4.1, 4.2, etc.), major versions will still be held in the file name. This will help me/us know what version you are using as it evolves. | |
| 103 | + - Dataframe is now natively accessible in `custom_sell` and `custom_stoploss` so the code used to force that behavior has been removed. | |
| 104 | + - The SROC comparission is now done using the percentage value as the indicator uses, rather than dividing by 100. | |
| 105 | +- **Dynamic ROI** | |
| 106 | + - Dynamic ROI as it was, has been removed in favor of the new `custom_sell` method. | |
| 107 | + - See the **custom_sell** area in the "Overview and Theory" section for additional details. | |
| 108 | +- **Custom Stoploss** | |
| 109 | + - Custom Stoploss as it was, has been removed in favor of the new `custom_sell` method. | |
| 110 | + - See the **custom_sell** area in the "Overview and Theory" section for addtional details. | |
| 111 | + | |
| 83 | 112 | ### v4 |
| 84 | 113 | |
| 85 | 114 | April 18, 2021: |
| @@ -167,6 +196,4 @@ | ||
| 167 | 196 | - Moved extranneous code and indicators out to custom_indicators helper file |
| 168 | 197 | - Added / Removed several indicators looking for a better buy signal, ultimately ended up keeping the primary Schism buy as it was. |
| 169 | 198 | |
| 170 | - | |
| 171 | - | |
| 172 | 199 |  |
modified strategies/Solipsis.py +48 −15
| @@ -3,12 +3,12 @@ | ||
| 3 | 3 | from pathlib import Path |
| 4 | 4 | sys.path.append(str(Path(__file__).parent)) |
| 5 | 5 | |
| 6 | -from Solipsis_v4 import Solipsis4 as Solipsis | |
| 6 | +from Solipsis_v5 import Solipsis5 as Solipsis | |
| 7 | 7 | |
| 8 | 8 | """ |
| 9 | 9 | *** THIS IS YOUR LIVE TRADING COPY *** |
| 10 | 10 | *** THIS IS A CHILD STRATEGY, REQUIRES IMPORT OF PARENT STRATEGY ** |
| 11 | -*** CURRENTLY MAPS TO PARENT STRATEGY: Solipsis_v4 *** | |
| 11 | +*** CURRENTLY MAPS TO PARENT STRATEGY: Solipsis_v5 *** | |
| 12 | 12 | |
| 13 | 13 | LAST OPTIMIZED: |
| 14 | 14 | |
| @@ -34,15 +34,26 @@ | ||
| 34 | 34 | inf_timeframe = '1h' |
| 35 | 35 | |
| 36 | 36 | minimal_roi = { |
| 37 | - "0": 0.01, | |
| 38 | - "1440": 0 | |
| 37 | + "0": 100 | |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | - use_dynamic_roi = True | |
| 42 | - use_custom_stoploss = True | |
| 40 | + buy_params = {} | |
| 41 | + | |
| 42 | + sell_params = {} | |
| 43 | 43 | |
| 44 | 44 | stoploss = -0.10 |
| 45 | 45 | |
| 46 | + use_sell_signal = True | |
| 47 | + sell_profit_only = False | |
| 48 | + ignore_roi_if_buy_signal = False | |
| 49 | + | |
| 50 | + startup_candle_count: int = 233 | |
| 51 | + process_only_new_candles = False | |
| 52 | + | |
| 53 | + custom_trade_info = {} | |
| 54 | + custom_fiat = "USD" | |
| 55 | + custom_btc_inf = False | |
| 56 | + | |
| 46 | 57 | """ |
| 47 | 58 | Optimization / Backtest Results for Current Live Instance Settings |
| 48 | 59 | BTC |
| @@ -56,14 +67,25 @@ | ||
| 56 | 67 | inf_timeframe = '1h' |
| 57 | 68 | |
| 58 | 69 | minimal_roi = { |
| 59 | - "0": 0.01, | |
| 60 | - "1440": 0 | |
| 70 | + "0": 100 | |
| 61 | 71 | } |
| 62 | 72 | |
| 63 | - use_dynamic_roi = True | |
| 64 | - use_custom_stoploss = True | |
| 73 | + buy_params = {} | |
| 74 | + | |
| 75 | + sell_params = {} | |
| 65 | 76 | |
| 66 | 77 | stoploss = -0.10 |
| 78 | + | |
| 79 | + use_sell_signal = True | |
| 80 | + sell_profit_only = False | |
| 81 | + ignore_roi_if_buy_signal = False | |
| 82 | + | |
| 83 | + startup_candle_count: int = 233 | |
| 84 | + process_only_new_candles = False | |
| 85 | + | |
| 86 | + custom_trade_info = {} | |
| 87 | + custom_fiat = "USD" | |
| 88 | + custom_btc_inf = False | |
| 67 | 89 | |
| 68 | 90 | """ |
| 69 | 91 | Optimization / Backtest Results for Current Live Instance Settings |
| @@ -78,11 +100,22 @@ | ||
| 78 | 100 | inf_timeframe = '1h' |
| 79 | 101 | |
| 80 | 102 | minimal_roi = { |
| 81 | - "0": 0.01, | |
| 82 | - "1440": 0 | |
| 103 | + "0": 100 | |
| 83 | 104 | } |
| 84 | 105 | |
| 85 | - use_dynamic_roi = True | |
| 86 | - use_custom_stoploss = True | |
| 106 | + buy_params = {} | |
| 107 | + | |
| 108 | + sell_params = {} | |
| 109 | + | |
| 110 | + stoploss = -0.10 | |
| 111 | + | |
| 112 | + use_sell_signal = True | |
| 113 | + sell_profit_only = False | |
| 114 | + ignore_roi_if_buy_signal = False | |
| 115 | + | |
| 116 | + startup_candle_count: int = 233 | |
| 117 | + process_only_new_candles = False | |
| 87 | 118 | |
| 88 | - stoploss = -0.10 | |
| No newline at the end of the file | ||
| 119 | + custom_trade_info = {} | |
| 120 | + custom_fiat = "USD" | |
| 121 | + custom_btc_inf = False | |
| No newline at the end of the file |
deleted strategies/Solipsis_v4.py +0 −443
| @@ -1,443 +0,0 @@ | ||
| 1 | -import numpy as np | |
| 2 | -import talib.abstract as ta | |
| 3 | -import freqtrade.vendor.qtpylib.indicators as qtpylib | |
| 4 | -import arrow | |
| 5 | - | |
| 6 | -from freqtrade.strategy.interface import IStrategy | |
| 7 | -from freqtrade.strategy import merge_informative_pair, stoploss_from_open, IntParameter, DecimalParameter, CategoricalParameter | |
| 8 | -from typing import Dict, List, Optional, Tuple | |
| 9 | -from pandas import DataFrame, Series | |
| 10 | -from functools import reduce | |
| 11 | -from datetime import datetime, timedelta | |
| 12 | -from freqtrade.persistence import Trade | |
| 13 | - | |
| 14 | -# Get rid of pandas warnings during backtesting | |
| 15 | -import pandas as pd | |
| 16 | -pd.options.mode.chained_assignment = None # default='warn' | |
| 17 | - | |
| 18 | -# Strategy specific imports, files must reside in same folder as strategy | |
| 19 | -import sys | |
| 20 | -from pathlib import Path | |
| 21 | -sys.path.append(str(Path(__file__).parent)) | |
| 22 | - | |
| 23 | -import custom_indicators as cta | |
| 24 | - | |
| 25 | -""" | |
| 26 | -Solipsis - By @werkkrew | |
| 27 | - | |
| 28 | -Credits - | |
| 29 | -@JimmyNixx for many of the ideas used throughout as well as helping me stay motivated throughout development! | |
| 30 | -@JoeSchr for documenting and doing the legwork of getting indicators to be available in the custom_stoploss | |
| 31 | - | |
| 32 | -We ask for nothing in return except that if you make changes which bring you greater success than what has been provided, you share those ideas back to us | |
| 33 | -and the rest of the community. Also, please don't nag us with a million questions and especially don't blame us if you lose a ton of money using this. | |
| 34 | - | |
| 35 | -We take no responsibility for any success or failure you have using this strategy. | |
| 36 | -""" | |
| 37 | - | |
| 38 | -class Solipsis4(IStrategy): | |
| 39 | - | |
| 40 | - ## Buy Space Hyperopt Variables | |
| 41 | - | |
| 42 | - # Base Pair Params | |
| 43 | - base_mp = IntParameter(10, 50, default=30, space='buy') | |
| 44 | - base_rmi_max = IntParameter(30, 60, default=50, space='buy') | |
| 45 | - base_rmi_min = IntParameter(0, 30, default=20, space='buy') | |
| 46 | - base_ma_streak = IntParameter(1, 4, default=1, space='buy') | |
| 47 | - base_rmi_streak = IntParameter(3, 8, default=3, space='buy') | |
| 48 | - base_trigger = CategoricalParameter(['pcc', 'rmi', 'none'], default='rmi', space='buy', optimize=False) | |
| 49 | - inf_pct_adr = DecimalParameter(0.70, 0.99, default=0.80, space='buy') | |
| 50 | - # BTC Informative | |
| 51 | - xbtc_guard = CategoricalParameter(['strict', 'lazy', 'none'], default='lazy', space='buy', optimize=True) | |
| 52 | - xbtc_base_rmi = IntParameter(20, 70, default=40, space='buy') | |
| 53 | - # BTC / ETH Stake Parameters | |
| 54 | - xtra_base_stake_rmi = IntParameter(10, 50, default=50, space='buy') | |
| 55 | - xtra_base_fiat_rmi = IntParameter(30, 70, default=50, space='buy') | |
| 56 | - | |
| 57 | - ## Sell Space Params are being "hijacked" for custom_stoploss and dynamic_roi | |
| 58 | - | |
| 59 | - # Dynamic ROI | |
| 60 | - droi_trend_type = CategoricalParameter(['rmi', 'ssl', 'candle', 'any'], default='any', space='sell', optimize=True) | |
| 61 | - droi_pullback = CategoricalParameter([True, False], default=True, space='sell', optimize=True) | |
| 62 | - droi_pullback_amount = DecimalParameter(0.005, 0.02, default=0.005, space='sell') | |
| 63 | - droi_pullback_respect_table = CategoricalParameter([True, False], default=False, space='sell', optimize=True) | |
| 64 | - | |
| 65 | - # Custom Stoploss | |
| 66 | - cstp_threshold = DecimalParameter(-0.05, 0, default=-0.03, space='sell') | |
| 67 | - cstp_bail_how = CategoricalParameter(['roc', 'time', 'any'], default='roc', space='sell', optimize=True) | |
| 68 | - cstp_bail_roc = DecimalParameter(-0.05, -0.01, default=-0.03, space='sell') | |
| 69 | - cstp_bail_time = IntParameter(720, 1440, default=720, space='sell') | |
| 70 | - | |
| 71 | - timeframe = '5m' | |
| 72 | - inf_timeframe = '1h' | |
| 73 | - | |
| 74 | - buy_params = { | |
| 75 | - 'base_ma_streak': 1, | |
| 76 | - 'base_mp': 12, | |
| 77 | - 'base_rmi_max': 50, | |
| 78 | - 'base_rmi_min': 20, | |
| 79 | - 'base_rmi_streak': 3, | |
| 80 | - 'inf_pct_adr': 950, | |
| 81 | - 'xbtc_base_rmi': 20, | |
| 82 | - 'xbtc_guard': 'none', | |
| 83 | - 'xtra_base_fiat_rmi': 45, | |
| 84 | - 'xtra_base_stake_rmi': 13 | |
| 85 | - } | |
| 86 | - | |
| 87 | - sell_params = { | |
| 88 | - 'droi_pullback': True, | |
| 89 | - 'droi_pullback_amount': 0.006, | |
| 90 | - 'droi_pullback_respect_table': False, | |
| 91 | - 'droi_trend_type': 'any' | |
| 92 | - } | |
| 93 | - | |
| 94 | - minimal_roi = { | |
| 95 | - "0": 0.01, | |
| 96 | - "1440": 0 | |
| 97 | - } | |
| 98 | - | |
| 99 | - # Enable or disable these as desired | |
| 100 | - # Must be enabled when hyperopting the respective spaces | |
| 101 | - use_dynamic_roi = True | |
| 102 | - use_custom_stoploss = True | |
| 103 | - | |
| 104 | - stoploss = -0.10 | |
| 105 | - | |
| 106 | - # Recommended | |
| 107 | - use_sell_signal = False | |
| 108 | - sell_profit_only = False | |
| 109 | - ignore_roi_if_buy_signal = False | |
| 110 | - | |
| 111 | - # Required | |
| 112 | - startup_candle_count: int = 233 | |
| 113 | - process_only_new_candles = False | |
| 114 | - | |
| 115 | - # Strategy Specific Variable Storage | |
| 116 | - custom_trade_info = {} | |
| 117 | - custom_fiat = "USD" # Only relevant if stake is BTC or ETH | |
| 118 | - custom_btc_inf = False # Don't change this. | |
| 119 | - | |
| 120 | - """ | |
| 121 | - Informative Pair Definitions | |
| 122 | - """ | |
| 123 | - def informative_pairs(self): | |
| 124 | - # add all whitelisted pairs on informative timeframe | |
| 125 | - pairs = self.dp.current_whitelist() | |
| 126 | - informative_pairs = [(pair, self.inf_timeframe) for pair in pairs] | |
| 127 | - | |
| 128 | - # add extra informative pairs if the stake is BTC or ETH | |
| 129 | - if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 130 | - for pair in pairs: | |
| 131 | - coin, stake = pair.split('/') | |
| 132 | - coin_fiat = f"{coin}/{self.custom_fiat}" | |
| 133 | - informative_pairs += [(coin_fiat, self.timeframe)] | |
| 134 | - | |
| 135 | - stake_fiat = f"{self.config['stake_currency']}/{self.custom_fiat}" | |
| 136 | - informative_pairs += [(stake_fiat, self.timeframe)] | |
| 137 | - # if BTC/STAKE is not in whitelist, add it as an informative pair on both timeframes | |
| 138 | - else: | |
| 139 | - btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 140 | - if not btc_stake in pairs: | |
| 141 | - informative_pairs += [(btc_stake, self.timeframe)] | |
| 142 | - | |
| 143 | - return informative_pairs | |
| 144 | - | |
| 145 | - """ | |
| 146 | - Indicator Definitions | |
| 147 | - """ | |
| 148 | - def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 149 | - if not metadata['pair'] in self.custom_trade_info: | |
| 150 | - self.custom_trade_info[metadata['pair']] = {} | |
| 151 | - | |
| 152 | - ## Base Timeframe / Pair | |
| 153 | - | |
| 154 | - dataframe['kama'] = ta.KAMA(dataframe, length=233) | |
| 155 | - | |
| 156 | - # RMI: https://www.tradingview.com/script/kwIt9OgQ-Relative-Momentum-Index/ | |
| 157 | - dataframe['rmi'] = cta.RMI(dataframe, length=24, mom=5) | |
| 158 | - | |
| 159 | - # Momentum Pinball: https://www.tradingview.com/script/fBpVB1ez-Momentum-Pinball-Indicator/ | |
| 160 | - dataframe['roc-mp'] = ta.ROC(dataframe, timeperiod=1) | |
| 161 | - dataframe['mp'] = ta.RSI(dataframe['roc-mp'], timeperiod=3) | |
| 162 | - | |
| 163 | - # MA Streak: https://www.tradingview.com/script/Yq1z7cIv-MA-Streak-Can-Show-When-a-Run-Is-Getting-Long-in-the-Tooth/ | |
| 164 | - dataframe['mastreak'] = cta.mastreak(dataframe, period=4) | |
| 165 | - | |
| 166 | - # Percent Change Channel: https://www.tradingview.com/script/6wwAWXA1-MA-Streak-Change-Channel/ | |
| 167 | - upper, mid, lower = cta.pcc(dataframe, period=40, mult=3) | |
| 168 | - dataframe['pcc-lowerband'] = lower | |
| 169 | - dataframe['pcc-upperband'] = upper | |
| 170 | - | |
| 171 | - lookup_idxs = dataframe.index.values - (abs(dataframe['mastreak'].values) + 1) | |
| 172 | - valid_lookups = lookup_idxs >= 0 | |
| 173 | - dataframe['sbc'] = np.nan | |
| 174 | - dataframe.loc[valid_lookups, 'sbc'] = dataframe['close'].to_numpy()[lookup_idxs[valid_lookups].astype(int)] | |
| 175 | - | |
| 176 | - dataframe['streak-roc'] = 100 * (dataframe['close'] - dataframe['sbc']) / dataframe['sbc'] | |
| 177 | - | |
| 178 | - # Trends, Peaks and Crosses | |
| 179 | - dataframe['candle-up'] = np.where(dataframe['close'] >= dataframe['close'].shift(),1,0) | |
| 180 | - dataframe['candle-up-trend'] = np.where(dataframe['candle-up'].rolling(5).sum() >= 3,1,0) | |
| 181 | - | |
| 182 | - dataframe['rmi-up'] = np.where(dataframe['rmi'] >= dataframe['rmi'].shift(),1,0) | |
| 183 | - dataframe['rmi-up-trend'] = np.where(dataframe['rmi-up'].rolling(5).sum() >= 3,1,0) | |
| 184 | - | |
| 185 | - dataframe['rmi-dn'] = np.where(dataframe['rmi'] <= dataframe['rmi'].shift(),1,0) | |
| 186 | - dataframe['rmi-dn-count'] = dataframe['rmi-dn'].rolling(8).sum() | |
| 187 | - | |
| 188 | - dataframe['streak-bo'] = np.where(dataframe['streak-roc'] < dataframe['pcc-lowerband'],1,0) | |
| 189 | - dataframe['streak-bo-count'] = dataframe['streak-bo'].rolling(8).sum() | |
| 190 | - | |
| 191 | - # Indicators used only for ROI and Custom Stoploss | |
| 192 | - ssldown, sslup = cta.SSLChannels_ATR(dataframe, length=21) | |
| 193 | - dataframe['sroc'] = cta.SROC(dataframe, roclen=21, emalen=13, smooth=21) | |
| 194 | - dataframe['ssl-dir'] = np.where(sslup > ssldown,'up','down') | |
| 195 | - | |
| 196 | - # Base pair informative timeframe indicators | |
| 197 | - informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe) | |
| 198 | - | |
| 199 | - # Get the "average day range" between the 1d high and 1d low to set up guards | |
| 200 | - informative['1d-high'] = informative['close'].rolling(24).max() | |
| 201 | - informative['1d-low'] = informative['close'].rolling(24).min() | |
| 202 | - informative['adr'] = informative['1d-high'] - informative['1d-low'] | |
| 203 | - | |
| 204 | - dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True) | |
| 205 | - | |
| 206 | - # Other stake specific informative indicators | |
| 207 | - # e.g if stake is BTC and current coin is XLM (pair: XLM/BTC) | |
| 208 | - if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 209 | - coin, stake = metadata['pair'].split('/') | |
| 210 | - fiat = self.custom_fiat | |
| 211 | - coin_fiat = f"{coin}/{fiat}" | |
| 212 | - stake_fiat = f"{stake}/{fiat}" | |
| 213 | - | |
| 214 | - # Informative COIN/FIAT e.g. XLM/USD - Base Timeframe | |
| 215 | - coin_fiat_tf = self.dp.get_pair_dataframe(pair=coin_fiat, timeframe=self.timeframe) | |
| 216 | - dataframe[f"{fiat}_rmi"] = cta.RMI(coin_fiat_tf, length=55, mom=5) | |
| 217 | - | |
| 218 | - # Informative STAKE/FIAT e.g. BTC/USD - Base Timeframe | |
| 219 | - stake_fiat_tf = self.dp.get_pair_dataframe(pair=stake_fiat, timeframe=self.timeframe) | |
| 220 | - dataframe[f"{stake}_rmi"] = cta.RMI(stake_fiat_tf, length=55, mom=5) | |
| 221 | - | |
| 222 | - # Informatives for BTC/STAKE if not in whitelist | |
| 223 | - else: | |
| 224 | - pairs = self.dp.current_whitelist() | |
| 225 | - btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 226 | - if not btc_stake in pairs: | |
| 227 | - self.custom_btc_inf = True | |
| 228 | - # BTC/STAKE - Base Timeframe | |
| 229 | - btc_stake_tf = self.dp.get_pair_dataframe(pair=btc_stake, timeframe=self.timeframe) | |
| 230 | - dataframe['BTC_rmi'] = cta.RMI(btc_stake_tf, length=55, mom=5) | |
| 231 | - dataframe['BTC_close'] = btc_stake_tf['close'] | |
| 232 | - dataframe['BTC_kama'] = ta.KAMA(btc_stake_tf, length=144) | |
| 233 | - | |
| 234 | - # Slam some indicators into the trade_info dict so we can dynamic roi and custom stoploss in backtest | |
| 235 | - if self.dp.runmode.value in ('backtest', 'hyperopt'): | |
| 236 | - self.custom_trade_info[metadata['pair']]['sroc'] = dataframe[['date', 'sroc']].copy().set_index('date') | |
| 237 | - self.custom_trade_info[metadata['pair']]['ssl-dir'] = dataframe[['date', 'ssl-dir']].copy().set_index('date') | |
| 238 | - self.custom_trade_info[metadata['pair']]['rmi-up-trend'] = dataframe[['date', 'rmi-up-trend']].copy().set_index('date') | |
| 239 | - self.custom_trade_info[metadata['pair']]['candle-up-trend'] = dataframe[['date', 'candle-up-trend']].copy().set_index('date') | |
| 240 | - | |
| 241 | - return dataframe | |
| 242 | - | |
| 243 | - """ | |
| 244 | - Buy Signal | |
| 245 | - """ | |
| 246 | - def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 247 | - conditions = [] | |
| 248 | - | |
| 249 | - # Informative Timeframe Guards | |
| 250 | - conditions.append( | |
| 251 | - (dataframe['close'] <= dataframe[f"1d-low_{self.inf_timeframe}"] + | |
| 252 | - (self.inf_pct_adr.value * dataframe[f"adr_{self.inf_timeframe}"])) | |
| 253 | - ) | |
| 254 | - | |
| 255 | - # Base Timeframe Guards | |
| 256 | - conditions.append( | |
| 257 | - (dataframe['rmi-dn-count'] >= self.base_rmi_streak.value) & | |
| 258 | - (dataframe['streak-bo-count'] >= self.base_ma_streak.value) & | |
| 259 | - (dataframe['rmi'] <= self.base_rmi_max.value) & | |
| 260 | - (dataframe['rmi'] >= self.base_rmi_min.value) & | |
| 261 | - (dataframe['mp'] <= self.base_mp.value) | |
| 262 | - ) | |
| 263 | - | |
| 264 | - # Base Timeframe Trigger | |
| 265 | - if self.base_trigger.value == 'pcc': | |
| 266 | - conditions.append(qtpylib.crossed_above(dataframe['streak-roc'], dataframe['pcc-lowerband'])) | |
| 267 | - | |
| 268 | - if self.base_trigger.value == 'rmi': | |
| 269 | - conditions.append(dataframe['rmi-up-trend'] == 1) | |
| 270 | - | |
| 271 | - # Extra conditions for */BTC and */ETH stakes on additional informative pairs | |
| 272 | - if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 273 | - conditions.append( | |
| 274 | - (dataframe[f"{self.custom_fiat}_rmi"] > self.xtra_base_fiat_rmi.value) | | |
| 275 | - (dataframe[f"{self.config['stake_currency']}_rmi"] < self.xtra_base_stake_rmi.value) | |
| 276 | - ) | |
| 277 | - # Extra conditions for BTC/STAKE if not in whitelist | |
| 278 | - else: | |
| 279 | - if self.custom_btc_inf: | |
| 280 | - if self.xbtc_guard.value == 'strict': | |
| 281 | - conditions.append( | |
| 282 | - ( | |
| 283 | - (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 284 | - (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 285 | - ) | |
| 286 | - ) | |
| 287 | - if self.xbtc_guard.value == 'lazy': | |
| 288 | - conditions.append( | |
| 289 | - (dataframe['close'] > dataframe['kama']) | | |
| 290 | - ( | |
| 291 | - (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 292 | - (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 293 | - ) | |
| 294 | - ) | |
| 295 | - | |
| 296 | - conditions.append(dataframe['volume'].gt(0)) | |
| 297 | - | |
| 298 | - if conditions: | |
| 299 | - dataframe.loc[ | |
| 300 | - reduce(lambda x, y: x & y, conditions), | |
| 301 | - 'buy'] = 1 | |
| 302 | - | |
| 303 | - return dataframe | |
| 304 | - | |
| 305 | - """ | |
| 306 | - Sell Signal | |
| 307 | - """ | |
| 308 | - def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 309 | - | |
| 310 | - dataframe['sell'] = 0 | |
| 311 | - | |
| 312 | - return dataframe | |
| 313 | - | |
| 314 | - """ | |
| 315 | - Custom Stoploss | |
| 316 | - """ | |
| 317 | - def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime, current_rate: float, current_profit: float, **kwargs) -> float: | |
| 318 | - | |
| 319 | - trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) | |
| 320 | - | |
| 321 | - if self.config['runmode'].value in ('live', 'dry_run'): | |
| 322 | - dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe) | |
| 323 | - sroc = dataframe['sroc'].iat[-1] | |
| 324 | - # If in backtest or hyperopt, get the indicator values out of the trades dict (Thanks @JoeSchr!) | |
| 325 | - else: | |
| 326 | - sroc = self.custom_trade_info[trade.pair]['sroc'].loc[current_time]['sroc'] | |
| 327 | - | |
| 328 | - if current_profit < self.cstp_threshold.value: | |
| 329 | - if self.cstp_bail_how.value == 'roc' or self.cstp_bail_how.value == 'any': | |
| 330 | - # Dynamic bailout based on rate of change | |
| 331 | - if (sroc/100) <= self.cstp_bail_roc.value: | |
| 332 | - return 0.001 | |
| 333 | - if self.cstp_bail_how.value == 'time' or self.cstp_bail_how.value == 'any': | |
| 334 | - # Dynamic bailout based on time | |
| 335 | - if trade_dur > self.cstp_bail_time.value: | |
| 336 | - return 0.001 | |
| 337 | - | |
| 338 | - return 1 | |
| 339 | - | |
| 340 | - """ | |
| 341 | - Freqtrade ROI Overload for dynamic ROI functionality | |
| 342 | - """ | |
| 343 | - def min_roi_reached_dynamic(self, trade: Trade, current_profit: float, current_time: datetime, trade_dur: int) -> Tuple[Optional[int], Optional[float]]: | |
| 344 | - | |
| 345 | - minimal_roi = self.minimal_roi | |
| 346 | - _, table_roi = self.min_roi_reached_entry(trade_dur) | |
| 347 | - | |
| 348 | - # see if we have the data we need to do this, otherwise fall back to the standard table | |
| 349 | - if self.custom_trade_info and trade and trade.pair in self.custom_trade_info: | |
| 350 | - if self.config['runmode'].value in ('live', 'dry_run'): | |
| 351 | - dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=trade.pair, timeframe=self.timeframe) | |
| 352 | - rmi_trend = dataframe['rmi-up-trend'].iat[-1] | |
| 353 | - candle_trend = dataframe['candle-up-trend'].iat[-1] | |
| 354 | - ssl_dir = dataframe['ssl-dir'].iat[-1] | |
| 355 | - # If in backtest or hyperopt, get the indicator values out of the trades dict (Thanks @JoeSchr!) | |
| 356 | - else: | |
| 357 | - rmi_trend = self.custom_trade_info[trade.pair]['rmi-up-trend'].loc[current_time]['rmi-up-trend'] | |
| 358 | - candle_trend = self.custom_trade_info[trade.pair]['candle-up-trend'].loc[current_time]['candle-up-trend'] | |
| 359 | - ssl_dir = self.custom_trade_info[trade.pair]['ssl-dir'].loc[current_time]['ssl-dir'] | |
| 360 | - | |
| 361 | - min_roi = table_roi | |
| 362 | - max_profit = trade.calc_profit_ratio(trade.max_rate) | |
| 363 | - pullback_value = (max_profit - self.droi_pullback_amount.value) | |
| 364 | - in_trend = False | |
| 365 | - | |
| 366 | - if self.droi_trend_type.value == 'rmi' or self.droi_trend_type.value == 'any': | |
| 367 | - if rmi_trend == 1: | |
| 368 | - in_trend = True | |
| 369 | - if self.droi_trend_type.value == 'ssl' or self.droi_trend_type.value == 'any': | |
| 370 | - if ssl_dir == 'up': | |
| 371 | - in_trend = True | |
| 372 | - if self.droi_trend_type.value == 'candle' or self.droi_trend_type.value == 'any': | |
| 373 | - if candle_trend == 1: | |
| 374 | - in_trend = True | |
| 375 | - | |
| 376 | - # Force the ROI value high if in trend | |
| 377 | - if (in_trend == True): | |
| 378 | - min_roi = 100 | |
| 379 | - # If pullback is enabled, allow to sell if a pullback from peak has happened regardless of trend | |
| 380 | - if self.droi_pullback.value == True and (current_profit < pullback_value): | |
| 381 | - if self.droi_pullback_respect_table.value == True: | |
| 382 | - min_roi = table_roi | |
| 383 | - else: | |
| 384 | - min_roi = current_profit / 2 | |
| 385 | - | |
| 386 | - else: | |
| 387 | - min_roi = table_roi | |
| 388 | - | |
| 389 | - return trade_dur, min_roi | |
| 390 | - | |
| 391 | - # Change here to allow loading of the dynamic_roi settings | |
| 392 | - def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool: | |
| 393 | - trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) | |
| 394 | - | |
| 395 | - if self.use_dynamic_roi: | |
| 396 | - _, roi = self.min_roi_reached_dynamic(trade, current_profit, current_time, trade_dur) | |
| 397 | - else: | |
| 398 | - _, roi = self.min_roi_reached_entry(trade_dur) | |
| 399 | - if roi is None: | |
| 400 | - return False | |
| 401 | - else: | |
| 402 | - return current_profit > roi | |
| 403 | - | |
| 404 | - """ | |
| 405 | - Trade Timeout Overloads | |
| 406 | - """ | |
| 407 | - def check_buy_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 408 | - bid_strategy = self.config.get('bid_strategy', {}) | |
| 409 | - ob = self.dp.orderbook(pair, 1) | |
| 410 | - current_price = ob[f"{bid_strategy['price_side']}s"][0][0] | |
| 411 | - if current_price > order['price'] * 1.01: | |
| 412 | - return True | |
| 413 | - return False | |
| 414 | - | |
| 415 | - def check_sell_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 416 | - ask_strategy = self.config.get('ask_strategy', {}) | |
| 417 | - ob = self.dp.orderbook(pair, 1) | |
| 418 | - current_price = ob[f"{ask_strategy['price_side']}s"][0][0] | |
| 419 | - if current_price < order['price'] * 0.99: | |
| 420 | - return True | |
| 421 | - return False | |
| 422 | - | |
| 423 | -# Sub-strategy with parameters specific to BTC stake | |
| 424 | -class Solipsis4_BTC(Solipsis4): | |
| 425 | - | |
| 426 | - timeframe = '5m' | |
| 427 | - inf_timeframe = '1h' | |
| 428 | - | |
| 429 | - minimal_roi = { | |
| 430 | - "0": 0.01, | |
| 431 | - "1440": 0 | |
| 432 | - } | |
| 433 | - | |
| 434 | -# Sub-strategy with parameters specific to ETH stake | |
| 435 | -class Solipsis4_ETH(Solipsis4): | |
| 436 | - | |
| 437 | - timeframe = '5m' | |
| 438 | - inf_timeframe = '1h' | |
| 439 | - | |
| 440 | - minimal_roi = { | |
| 441 | - "0": 0.01, | |
| 442 | - "1440": 0 | |
| 443 | - } | |
| No newline at the end of the file |
added strategies/Solipsis_v5.py +388 −0
| @@ -0,0 +1,388 @@ | ||
| 1 | +import numpy as np | |
| 2 | +import talib.abstract as ta | |
| 3 | +import freqtrade.vendor.qtpylib.indicators as qtpylib | |
| 4 | +import arrow | |
| 5 | + | |
| 6 | +from freqtrade.strategy import (IStrategy, timeframe_to_prev_date, merge_informative_pair, stoploss_from_open, | |
| 7 | + IntParameter, DecimalParameter, CategoricalParameter) | |
| 8 | + | |
| 9 | +from typing import Dict, List, Optional, Tuple, Union | |
| 10 | +from pandas import DataFrame, Series | |
| 11 | +from functools import reduce | |
| 12 | +from datetime import datetime, timedelta | |
| 13 | +from freqtrade.persistence import Trade | |
| 14 | + | |
| 15 | +# Get rid of pandas warnings during backtesting | |
| 16 | +import pandas as pd | |
| 17 | +pd.options.mode.chained_assignment = None # default='warn' | |
| 18 | + | |
| 19 | +# Strategy specific imports, files must reside in same folder as strategy | |
| 20 | +import sys | |
| 21 | +from pathlib import Path | |
| 22 | +sys.path.append(str(Path(__file__).parent)) | |
| 23 | + | |
| 24 | +import custom_indicators as cta | |
| 25 | + | |
| 26 | +""" | |
| 27 | +Solipsis - By @werkkrew | |
| 28 | + | |
| 29 | +Credits - | |
| 30 | +@JimmyNixx for many of the ideas used throughout as well as helping me stay motivated throughout development! | |
| 31 | + | |
| 32 | +I ask for nothing in return except that if you make changes which bring you greater success than what has been provided, you share those ideas back to | |
| 33 | +the community. Also, please don't nag me with a million questions and especially don't blame me if you lose a ton of money using this. | |
| 34 | + | |
| 35 | +I take no responsibility for any success or failure you have using this strategy. | |
| 36 | + | |
| 37 | +VERSION: 5.0 | |
| 38 | +""" | |
| 39 | + | |
| 40 | +class Solipsis5(IStrategy): | |
| 41 | + | |
| 42 | + ## Buy Space Hyperopt Variables | |
| 43 | + | |
| 44 | + # Base Pair Params | |
| 45 | + base_mp = IntParameter(10, 50, default=30, space='buy') | |
| 46 | + base_rmi_max = IntParameter(30, 60, default=50, space='buy') | |
| 47 | + base_rmi_min = IntParameter(0, 30, default=20, space='buy') | |
| 48 | + base_ma_streak = IntParameter(1, 4, default=1, space='buy') | |
| 49 | + base_rmi_streak = IntParameter(3, 8, default=3, space='buy') | |
| 50 | + base_trigger = CategoricalParameter(['pcc', 'rmi', 'none'], default='rmi', space='buy', optimize=False) | |
| 51 | + inf_pct_adr = DecimalParameter(0.70, 0.99, default=0.80, space='buy') | |
| 52 | + # BTC Informative | |
| 53 | + xbtc_guard = CategoricalParameter(['strict', 'lazy', 'none'], default='lazy', space='buy', optimize=True) | |
| 54 | + xbtc_base_rmi = IntParameter(20, 70, default=40, space='buy') | |
| 55 | + # BTC / ETH Stake Parameters | |
| 56 | + xtra_base_stake_rmi = IntParameter(10, 50, default=50, space='buy') | |
| 57 | + xtra_base_fiat_rmi = IntParameter(30, 70, default=50, space='buy') | |
| 58 | + | |
| 59 | + ## Sell Space Params are being used for both custom_stoploss and custom_sell | |
| 60 | + | |
| 61 | + # Custom Sell Profit (formerly Dynamic ROI) | |
| 62 | + csell_roi_type = CategoricalParameter(['static', 'decay', 'step'], default='static', space='sell', optimize=True) | |
| 63 | + csell_roi_time = IntParameter(720, 1440, default=720, space='sell') | |
| 64 | + csell_roi_start = DecimalParameter(0.01, 0.05, default=0.01, space='sell') | |
| 65 | + csell_roi_end = DecimalParameter(0.0, 0.01, default=0, space='sell') | |
| 66 | + csell_trend_type = CategoricalParameter(['rmi', 'ssl', 'candle', 'any'], default='any', space='sell', optimize=True) | |
| 67 | + csell_pullback = CategoricalParameter([True, False], default=True, space='sell', optimize=True) | |
| 68 | + csell_pullback_amount = DecimalParameter(0.005, 0.02, default=0.005, space='sell') | |
| 69 | + csell_pullback_respect_roi = CategoricalParameter([True, False], default=True, space='sell', optimize=True) | |
| 70 | + | |
| 71 | + # Custom Sell Loss (formerly Custom Stoploss) | |
| 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) | |
| 74 | + csell_bail_roc = DecimalParameter(-5.0, -1.0, default=-3.0, space='sell') | |
| 75 | + csell_bail_time = IntParameter(720, 1440, default=720, space='sell') | |
| 76 | + csell_bail_time_trend = CategoricalParameter([True, False], default=True, space='sell', optimize=True) | |
| 77 | + | |
| 78 | + timeframe = '5m' | |
| 79 | + inf_timeframe = '1h' | |
| 80 | + | |
| 81 | + buy_params = {} | |
| 82 | + | |
| 83 | + sell_params = {} | |
| 84 | + | |
| 85 | + minimal_roi = { | |
| 86 | + "0": 100 | |
| 87 | + } | |
| 88 | + | |
| 89 | + stoploss = -0.10 | |
| 90 | + | |
| 91 | + # Recommended | |
| 92 | + use_sell_signal = True | |
| 93 | + sell_profit_only = False | |
| 94 | + ignore_roi_if_buy_signal = False | |
| 95 | + | |
| 96 | + # Required | |
| 97 | + startup_candle_count: int = 233 | |
| 98 | + process_only_new_candles = False | |
| 99 | + | |
| 100 | + # Strategy Specific Variable Storage | |
| 101 | + custom_trade_info = {} | |
| 102 | + custom_fiat = "USD" # Only relevant if stake is BTC or ETH | |
| 103 | + custom_btc_inf = False # Don't change this. | |
| 104 | + | |
| 105 | + """ | |
| 106 | + Informative Pair Definitions | |
| 107 | + """ | |
| 108 | + def informative_pairs(self): | |
| 109 | + # add all whitelisted pairs on informative timeframe | |
| 110 | + pairs = self.dp.current_whitelist() | |
| 111 | + informative_pairs = [(pair, self.inf_timeframe) for pair in pairs] | |
| 112 | + | |
| 113 | + # add extra informative pairs if the stake is BTC or ETH | |
| 114 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 115 | + for pair in pairs: | |
| 116 | + coin, stake = pair.split('/') | |
| 117 | + coin_fiat = f"{coin}/{self.custom_fiat}" | |
| 118 | + informative_pairs += [(coin_fiat, self.timeframe)] | |
| 119 | + | |
| 120 | + stake_fiat = f"{self.config['stake_currency']}/{self.custom_fiat}" | |
| 121 | + informative_pairs += [(stake_fiat, self.timeframe)] | |
| 122 | + # if BTC/STAKE is not in whitelist, add it as an informative pair on both timeframes | |
| 123 | + else: | |
| 124 | + btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 125 | + if not btc_stake in pairs: | |
| 126 | + informative_pairs += [(btc_stake, self.timeframe)] | |
| 127 | + | |
| 128 | + return informative_pairs | |
| 129 | + | |
| 130 | + """ | |
| 131 | + Indicator Definitions | |
| 132 | + """ | |
| 133 | + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 134 | + if not metadata['pair'] in self.custom_trade_info: | |
| 135 | + self.custom_trade_info[metadata['pair']] = {} | |
| 136 | + self.custom_trade_info[metadata['pair']]['had-trend'] = False | |
| 137 | + | |
| 138 | + ## Base Timeframe / Pair | |
| 139 | + | |
| 140 | + # Kaufmann Adaptive Moving Average | |
| 141 | + dataframe['kama'] = ta.KAMA(dataframe, length=233) | |
| 142 | + | |
| 143 | + # RMI: https://www.tradingview.com/script/kwIt9OgQ-Relative-Momentum-Index/ | |
| 144 | + dataframe['rmi'] = cta.RMI(dataframe, length=24, mom=5) | |
| 145 | + | |
| 146 | + # Momentum Pinball: https://www.tradingview.com/script/fBpVB1ez-Momentum-Pinball-Indicator/ | |
| 147 | + dataframe['roc-mp'] = ta.ROC(dataframe, timeperiod=1) | |
| 148 | + dataframe['mp'] = ta.RSI(dataframe['roc-mp'], timeperiod=3) | |
| 149 | + | |
| 150 | + # MA Streak: https://www.tradingview.com/script/Yq1z7cIv-MA-Streak-Can-Show-When-a-Run-Is-Getting-Long-in-the-Tooth/ | |
| 151 | + dataframe['mastreak'] = cta.mastreak(dataframe, period=4) | |
| 152 | + | |
| 153 | + # Percent Change Channel: https://www.tradingview.com/script/6wwAWXA1-MA-Streak-Change-Channel/ | |
| 154 | + upper, mid, lower = cta.pcc(dataframe, period=40, mult=3) | |
| 155 | + dataframe['pcc-lowerband'] = lower | |
| 156 | + dataframe['pcc-upperband'] = upper | |
| 157 | + | |
| 158 | + lookup_idxs = dataframe.index.values - (abs(dataframe['mastreak'].values) + 1) | |
| 159 | + valid_lookups = lookup_idxs >= 0 | |
| 160 | + dataframe['sbc'] = np.nan | |
| 161 | + dataframe.loc[valid_lookups, 'sbc'] = dataframe['close'].to_numpy()[lookup_idxs[valid_lookups].astype(int)] | |
| 162 | + | |
| 163 | + dataframe['streak-roc'] = 100 * (dataframe['close'] - dataframe['sbc']) / dataframe['sbc'] | |
| 164 | + | |
| 165 | + # Trends, Peaks and Crosses | |
| 166 | + dataframe['candle-up'] = np.where(dataframe['close'] >= dataframe['close'].shift(),1,0) | |
| 167 | + dataframe['candle-up-trend'] = np.where(dataframe['candle-up'].rolling(5).sum() >= 3,1,0) | |
| 168 | + | |
| 169 | + dataframe['rmi-up'] = np.where(dataframe['rmi'] >= dataframe['rmi'].shift(),1,0) | |
| 170 | + dataframe['rmi-up-trend'] = np.where(dataframe['rmi-up'].rolling(5).sum() >= 3,1,0) | |
| 171 | + | |
| 172 | + dataframe['rmi-dn'] = np.where(dataframe['rmi'] <= dataframe['rmi'].shift(),1,0) | |
| 173 | + dataframe['rmi-dn-count'] = dataframe['rmi-dn'].rolling(8).sum() | |
| 174 | + | |
| 175 | + dataframe['streak-bo'] = np.where(dataframe['streak-roc'] < dataframe['pcc-lowerband'],1,0) | |
| 176 | + dataframe['streak-bo-count'] = dataframe['streak-bo'].rolling(8).sum() | |
| 177 | + | |
| 178 | + # Indicators used only for ROI and Custom Stoploss | |
| 179 | + ssldown, sslup = cta.SSLChannels_ATR(dataframe, length=21) | |
| 180 | + dataframe['sroc'] = cta.SROC(dataframe, roclen=21, emalen=13, smooth=21) | |
| 181 | + dataframe['ssl-dir'] = np.where(sslup > ssldown,'up','down') | |
| 182 | + | |
| 183 | + # Base pair informative timeframe indicators | |
| 184 | + informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe) | |
| 185 | + | |
| 186 | + # Get the "average day range" between the 1d high and 1d low to set up guards | |
| 187 | + informative['1d-high'] = informative['close'].rolling(24).max() | |
| 188 | + informative['1d-low'] = informative['close'].rolling(24).min() | |
| 189 | + informative['adr'] = informative['1d-high'] - informative['1d-low'] | |
| 190 | + | |
| 191 | + dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True) | |
| 192 | + | |
| 193 | + # Other stake specific informative indicators | |
| 194 | + # e.g if stake is BTC and current coin is XLM (pair: XLM/BTC) | |
| 195 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 196 | + coin, stake = metadata['pair'].split('/') | |
| 197 | + fiat = self.custom_fiat | |
| 198 | + coin_fiat = f"{coin}/{fiat}" | |
| 199 | + stake_fiat = f"{stake}/{fiat}" | |
| 200 | + | |
| 201 | + # Informative COIN/FIAT e.g. XLM/USD - Base Timeframe | |
| 202 | + coin_fiat_tf = self.dp.get_pair_dataframe(pair=coin_fiat, timeframe=self.timeframe) | |
| 203 | + dataframe[f"{fiat}_rmi"] = cta.RMI(coin_fiat_tf, length=55, mom=5) | |
| 204 | + | |
| 205 | + # Informative STAKE/FIAT e.g. BTC/USD - Base Timeframe | |
| 206 | + stake_fiat_tf = self.dp.get_pair_dataframe(pair=stake_fiat, timeframe=self.timeframe) | |
| 207 | + dataframe[f"{stake}_rmi"] = cta.RMI(stake_fiat_tf, length=55, mom=5) | |
| 208 | + | |
| 209 | + # Informatives for BTC/STAKE if not in whitelist | |
| 210 | + else: | |
| 211 | + pairs = self.dp.current_whitelist() | |
| 212 | + btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 213 | + if not btc_stake in pairs: | |
| 214 | + self.custom_btc_inf = True | |
| 215 | + # BTC/STAKE - Base Timeframe | |
| 216 | + btc_stake_tf = self.dp.get_pair_dataframe(pair=btc_stake, timeframe=self.timeframe) | |
| 217 | + dataframe['BTC_rmi'] = cta.RMI(btc_stake_tf, length=55, mom=5) | |
| 218 | + dataframe['BTC_close'] = btc_stake_tf['close'] | |
| 219 | + dataframe['BTC_kama'] = ta.KAMA(btc_stake_tf, length=144) | |
| 220 | + | |
| 221 | + return dataframe | |
| 222 | + | |
| 223 | + """ | |
| 224 | + Buy Signal | |
| 225 | + """ | |
| 226 | + def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 227 | + conditions = [] | |
| 228 | + | |
| 229 | + # Informative Timeframe Guards | |
| 230 | + conditions.append( | |
| 231 | + (dataframe['close'] <= dataframe[f"1d-low_{self.inf_timeframe}"] + | |
| 232 | + (self.inf_pct_adr.value * dataframe[f"adr_{self.inf_timeframe}"])) | |
| 233 | + ) | |
| 234 | + | |
| 235 | + # Base Timeframe Guards | |
| 236 | + conditions.append( | |
| 237 | + (dataframe['rmi-dn-count'] >= self.base_rmi_streak.value) & | |
| 238 | + (dataframe['streak-bo-count'] >= self.base_ma_streak.value) & | |
| 239 | + (dataframe['rmi'] <= self.base_rmi_max.value) & | |
| 240 | + (dataframe['rmi'] >= self.base_rmi_min.value) & | |
| 241 | + (dataframe['mp'] <= self.base_mp.value) | |
| 242 | + ) | |
| 243 | + | |
| 244 | + # Base Timeframe Trigger | |
| 245 | + if self.base_trigger.value == 'pcc': | |
| 246 | + conditions.append(qtpylib.crossed_above(dataframe['streak-roc'], dataframe['pcc-lowerband'])) | |
| 247 | + | |
| 248 | + if self.base_trigger.value == 'rmi': | |
| 249 | + conditions.append(dataframe['rmi-up-trend'] == 1) | |
| 250 | + | |
| 251 | + # Extra conditions for */BTC and */ETH stakes on additional informative pairs | |
| 252 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 253 | + conditions.append( | |
| 254 | + (dataframe[f"{self.custom_fiat}_rmi"] > self.xtra_base_fiat_rmi.value) | | |
| 255 | + (dataframe[f"{self.config['stake_currency']}_rmi"] < self.xtra_base_stake_rmi.value) | |
| 256 | + ) | |
| 257 | + # Extra conditions for BTC/STAKE if not in whitelist | |
| 258 | + else: | |
| 259 | + if self.custom_btc_inf: | |
| 260 | + if self.xbtc_guard.value == 'strict': | |
| 261 | + conditions.append( | |
| 262 | + ( | |
| 263 | + (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 264 | + (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 265 | + ) | |
| 266 | + ) | |
| 267 | + if self.xbtc_guard.value == 'lazy': | |
| 268 | + conditions.append( | |
| 269 | + (dataframe['close'] > dataframe['kama']) | | |
| 270 | + ( | |
| 271 | + (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 272 | + (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 273 | + ) | |
| 274 | + ) | |
| 275 | + | |
| 276 | + conditions.append(dataframe['volume'].gt(0)) | |
| 277 | + | |
| 278 | + if conditions: | |
| 279 | + dataframe.loc[ | |
| 280 | + reduce(lambda x, y: x & y, conditions), | |
| 281 | + 'buy'] = 1 | |
| 282 | + | |
| 283 | + return dataframe | |
| 284 | + | |
| 285 | + """ | |
| 286 | + Sell Signal | |
| 287 | + """ | |
| 288 | + def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 289 | + | |
| 290 | + dataframe['sell'] = 0 | |
| 291 | + | |
| 292 | + return dataframe | |
| 293 | + | |
| 294 | + """ | |
| 295 | + Custom Sell | |
| 296 | + Current implementation is meant to behave similar to my original "dynamic_roi" concept when in profit | |
| 297 | + or like the original "custom_stoploss" when at a loss. | |
| 298 | + """ | |
| 299 | + def custom_sell(self, pair: str, trade: Trade, current_time: datetime, current_rate: float, | |
| 300 | + current_profit: float, dataframe: DataFrame, | |
| 301 | + **kwargs) -> Optional[Union[str, bool]]: | |
| 302 | + | |
| 303 | + trade_open_date = timeframe_to_prev_date(self.timeframe, trade.open_date_utc) | |
| 304 | + trade_row = dataframe.loc[dataframe['date'] == trade_open_date].squeeze() | |
| 305 | + | |
| 306 | + trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) | |
| 307 | + max_profit = max(0, trade.calc_profit_ratio(trade.max_rate)) | |
| 308 | + pullback_value = max(0, (max_profit - self.csell_pullback_amount.value)) | |
| 309 | + in_trend = False | |
| 310 | + | |
| 311 | + # Determine our current ROI point based on the defined type | |
| 312 | + if self.csell_roi_type.value == 'static': | |
| 313 | + min_roi = self.csell_roi_start.value | |
| 314 | + elif self.csell_roi_type.value == 'decay': | |
| 315 | + min_roi = cta.linear_decay(self.csell_roi_start.value, self.csell_roi_end.value, 0, self.csell_roi_time.value, trade_dur) | |
| 316 | + elif self.csell_roi_type.value == 'step': | |
| 317 | + if trade_dur < self.csell_roi_time.value: | |
| 318 | + min_roi = self.csell_roi_start.value | |
| 319 | + else: | |
| 320 | + min_roi = self.csell_roi_end.value | |
| 321 | + | |
| 322 | + # Determine if there is a trend | |
| 323 | + if self.csell_trend_type.value == 'rmi' or self.csell_trend_type.value == 'any': | |
| 324 | + if trade_row['rmi-up-trend'] == 1: | |
| 325 | + in_trend = True | |
| 326 | + if self.csell_trend_type.value == 'ssl' or self.csell_trend_type.value == 'any': | |
| 327 | + if trade_row['ssl-dir'] == 'up': | |
| 328 | + in_trend = True | |
| 329 | + if self.csell_trend_type.value == 'candle' or self.csell_trend_type.value == 'any': | |
| 330 | + if trade_row['candle-up-trend'] == 1: | |
| 331 | + in_trend = True | |
| 332 | + | |
| 333 | + # Don't sell if we are in a trend unless the pullback threshold is met | |
| 334 | + if in_trend == True and current_profit > 0: | |
| 335 | + # Record that we were in a trend for this trade/pair for a more useful sell message later | |
| 336 | + self.custom_trade_info[trade.pair]['had-trend'] = True | |
| 337 | + # If pullback is enabled and profit has pulled back allow a sell, maybe | |
| 338 | + if self.csell_pullback.value == True and (current_profit <= pullback_value): | |
| 339 | + if self.csell_pullback_respect_roi.value == True and current_profit > min_roi: | |
| 340 | + return 'intrend_pullback_roi' | |
| 341 | + elif self.csell_pullback_respect_roi.value == False: | |
| 342 | + if current_profit > min_roi: | |
| 343 | + return 'intrend_pullback_roi' | |
| 344 | + else: | |
| 345 | + return 'intrend_pullback_noroi' | |
| 346 | + # We are in a trend and pullback is disabled or has not happened or various criteria were not met, hold | |
| 347 | + return None | |
| 348 | + # If we are not in a trend, just use the roi value | |
| 349 | + elif in_trend == False and current_profit > min_roi: | |
| 350 | + if self.custom_trade_info[trade.pair]['had-trend']: | |
| 351 | + self.custom_trade_info[trade.pair]['had-trend'] = False | |
| 352 | + return 'trend_roi' | |
| 353 | + else: | |
| 354 | + return 'notrend_roi' | |
| 355 | + # Determine how we sell when we are in a loss | |
| 356 | + elif current_profit < self.csell_loss_threshold.value: | |
| 357 | + if self.csell_bail_how.value == 'roc' or self.csell_bail_how.value == 'any': | |
| 358 | + # Dynamic bailout based on rate of change | |
| 359 | + if trade_row['sroc'] <= self.csell_bail_roc.value: | |
| 360 | + return 'loss_roc' | |
| 361 | + if self.csell_bail_how.value == 'time' or self.csell_bail_how.value == 'any': | |
| 362 | + # Dynamic bailout based on time, unless time_trend is true and there is a potential reversal | |
| 363 | + if trade_dur > self.csell_bail_time.value: | |
| 364 | + if self.csell_bail_time_trend.value == True and in_trend == True: | |
| 365 | + return None | |
| 366 | + else: | |
| 367 | + return 'loss_timeout' | |
| 368 | + else: | |
| 369 | + return None | |
| 370 | + | |
| 371 | + """ | |
| 372 | + Trade Timeout Overloads | |
| 373 | + """ | |
| 374 | + def check_buy_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 375 | + bid_strategy = self.config.get('bid_strategy', {}) | |
| 376 | + ob = self.dp.orderbook(pair, 1) | |
| 377 | + current_price = ob[f"{bid_strategy['price_side']}s"][0][0] | |
| 378 | + if current_price > order['price'] * 1.01: | |
| 379 | + return True | |
| 380 | + return False | |
| 381 | + | |
| 382 | + def check_sell_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 383 | + ask_strategy = self.config.get('ask_strategy', {}) | |
| 384 | + ob = self.dp.orderbook(pair, 1) | |
| 385 | + current_price = ob[f"{ask_strategy['price_side']}s"][0][0] | |
| 386 | + if current_price < order['price'] * 0.99: | |
| 387 | + return True | |
| 388 | + return False | |
| No newline at the end of the file |
modified strategies/custom_indicators.py +9 −0
| @@ -26,6 +26,15 @@ | ||
| 26 | 26 | |
| 27 | 27 | return min(end, start + (rate * time)) |
| 28 | 28 | |
| 29 | +def linear_decay(start: float, end: float, start_time: int, end_time: int, trade_time: int) -> float: | |
| 30 | + """ | |
| 31 | + Simple linear decay function. Decays from start to end after end_time minutes (starts after start_time minutes) | |
| 32 | + """ | |
| 33 | + time = max(0, trade_time - start_time) | |
| 34 | + rate = (start - end) / (end_time - start_time) | |
| 35 | + | |
| 36 | + return max(end, start - (rate * time)) | |
| 37 | + | |
| 29 | 38 | """ |
| 30 | 39 | TA Indicators |
| 31 | 40 | """ |
added strategies/old/Solipsis_v4.py +443 −0
| @@ -0,0 +1,443 @@ | ||
| 1 | +import numpy as np | |
| 2 | +import talib.abstract as ta | |
| 3 | +import freqtrade.vendor.qtpylib.indicators as qtpylib | |
| 4 | +import arrow | |
| 5 | + | |
| 6 | +from freqtrade.strategy.interface import IStrategy | |
| 7 | +from freqtrade.strategy import merge_informative_pair, stoploss_from_open, IntParameter, DecimalParameter, CategoricalParameter | |
| 8 | +from typing import Dict, List, Optional, Tuple | |
| 9 | +from pandas import DataFrame, Series | |
| 10 | +from functools import reduce | |
| 11 | +from datetime import datetime, timedelta | |
| 12 | +from freqtrade.persistence import Trade | |
| 13 | + | |
| 14 | +# Get rid of pandas warnings during backtesting | |
| 15 | +import pandas as pd | |
| 16 | +pd.options.mode.chained_assignment = None # default='warn' | |
| 17 | + | |
| 18 | +# Strategy specific imports, files must reside in same folder as strategy | |
| 19 | +import sys | |
| 20 | +from pathlib import Path | |
| 21 | +sys.path.append(str(Path(__file__).parent)) | |
| 22 | + | |
| 23 | +import custom_indicators as cta | |
| 24 | + | |
| 25 | +""" | |
| 26 | +Solipsis - By @werkkrew | |
| 27 | + | |
| 28 | +Credits - | |
| 29 | +@JimmyNixx for many of the ideas used throughout as well as helping me stay motivated throughout development! | |
| 30 | +@JoeSchr for documenting and doing the legwork of getting indicators to be available in the custom_stoploss | |
| 31 | + | |
| 32 | +We ask for nothing in return except that if you make changes which bring you greater success than what has been provided, you share those ideas back to us | |
| 33 | +and the rest of the community. Also, please don't nag us with a million questions and especially don't blame us if you lose a ton of money using this. | |
| 34 | + | |
| 35 | +We take no responsibility for any success or failure you have using this strategy. | |
| 36 | +""" | |
| 37 | + | |
| 38 | +class Solipsis4(IStrategy): | |
| 39 | + | |
| 40 | + ## Buy Space Hyperopt Variables | |
| 41 | + | |
| 42 | + # Base Pair Params | |
| 43 | + base_mp = IntParameter(10, 50, default=30, space='buy') | |
| 44 | + base_rmi_max = IntParameter(30, 60, default=50, space='buy') | |
| 45 | + base_rmi_min = IntParameter(0, 30, default=20, space='buy') | |
| 46 | + base_ma_streak = IntParameter(1, 4, default=1, space='buy') | |
| 47 | + base_rmi_streak = IntParameter(3, 8, default=3, space='buy') | |
| 48 | + base_trigger = CategoricalParameter(['pcc', 'rmi', 'none'], default='rmi', space='buy', optimize=False) | |
| 49 | + inf_pct_adr = DecimalParameter(0.70, 0.99, default=0.80, space='buy') | |
| 50 | + # BTC Informative | |
| 51 | + xbtc_guard = CategoricalParameter(['strict', 'lazy', 'none'], default='lazy', space='buy', optimize=True) | |
| 52 | + xbtc_base_rmi = IntParameter(20, 70, default=40, space='buy') | |
| 53 | + # BTC / ETH Stake Parameters | |
| 54 | + xtra_base_stake_rmi = IntParameter(10, 50, default=50, space='buy') | |
| 55 | + xtra_base_fiat_rmi = IntParameter(30, 70, default=50, space='buy') | |
| 56 | + | |
| 57 | + ## Sell Space Params are being "hijacked" for custom_stoploss and dynamic_roi | |
| 58 | + | |
| 59 | + # Dynamic ROI | |
| 60 | + droi_trend_type = CategoricalParameter(['rmi', 'ssl', 'candle', 'any'], default='any', space='sell', optimize=True) | |
| 61 | + droi_pullback = CategoricalParameter([True, False], default=True, space='sell', optimize=True) | |
| 62 | + droi_pullback_amount = DecimalParameter(0.005, 0.02, default=0.005, space='sell') | |
| 63 | + droi_pullback_respect_table = CategoricalParameter([True, False], default=False, space='sell', optimize=True) | |
| 64 | + | |
| 65 | + # Custom Stoploss | |
| 66 | + cstp_threshold = DecimalParameter(-0.05, 0, default=-0.03, space='sell') | |
| 67 | + cstp_bail_how = CategoricalParameter(['roc', 'time', 'any'], default='roc', space='sell', optimize=True) | |
| 68 | + cstp_bail_roc = DecimalParameter(-0.05, -0.01, default=-0.03, space='sell') | |
| 69 | + cstp_bail_time = IntParameter(720, 1440, default=720, space='sell') | |
| 70 | + | |
| 71 | + timeframe = '5m' | |
| 72 | + inf_timeframe = '1h' | |
| 73 | + | |
| 74 | + buy_params = { | |
| 75 | + 'base_ma_streak': 1, | |
| 76 | + 'base_mp': 12, | |
| 77 | + 'base_rmi_max': 50, | |
| 78 | + 'base_rmi_min': 20, | |
| 79 | + 'base_rmi_streak': 3, | |
| 80 | + 'inf_pct_adr': 950, | |
| 81 | + 'xbtc_base_rmi': 20, | |
| 82 | + 'xbtc_guard': 'none', | |
| 83 | + 'xtra_base_fiat_rmi': 45, | |
| 84 | + 'xtra_base_stake_rmi': 13 | |
| 85 | + } | |
| 86 | + | |
| 87 | + sell_params = { | |
| 88 | + 'droi_pullback': True, | |
| 89 | + 'droi_pullback_amount': 0.006, | |
| 90 | + 'droi_pullback_respect_table': False, | |
| 91 | + 'droi_trend_type': 'any' | |
| 92 | + } | |
| 93 | + | |
| 94 | + minimal_roi = { | |
| 95 | + "0": 0.01, | |
| 96 | + "1440": 0 | |
| 97 | + } | |
| 98 | + | |
| 99 | + # Enable or disable these as desired | |
| 100 | + # Must be enabled when hyperopting the respective spaces | |
| 101 | + use_dynamic_roi = True | |
| 102 | + use_custom_stoploss = True | |
| 103 | + | |
| 104 | + stoploss = -0.10 | |
| 105 | + | |
| 106 | + # Recommended | |
| 107 | + use_sell_signal = False | |
| 108 | + sell_profit_only = False | |
| 109 | + ignore_roi_if_buy_signal = False | |
| 110 | + | |
| 111 | + # Required | |
| 112 | + startup_candle_count: int = 233 | |
| 113 | + process_only_new_candles = False | |
| 114 | + | |
| 115 | + # Strategy Specific Variable Storage | |
| 116 | + custom_trade_info = {} | |
| 117 | + custom_fiat = "USD" # Only relevant if stake is BTC or ETH | |
| 118 | + custom_btc_inf = False # Don't change this. | |
| 119 | + | |
| 120 | + """ | |
| 121 | + Informative Pair Definitions | |
| 122 | + """ | |
| 123 | + def informative_pairs(self): | |
| 124 | + # add all whitelisted pairs on informative timeframe | |
| 125 | + pairs = self.dp.current_whitelist() | |
| 126 | + informative_pairs = [(pair, self.inf_timeframe) for pair in pairs] | |
| 127 | + | |
| 128 | + # add extra informative pairs if the stake is BTC or ETH | |
| 129 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 130 | + for pair in pairs: | |
| 131 | + coin, stake = pair.split('/') | |
| 132 | + coin_fiat = f"{coin}/{self.custom_fiat}" | |
| 133 | + informative_pairs += [(coin_fiat, self.timeframe)] | |
| 134 | + | |
| 135 | + stake_fiat = f"{self.config['stake_currency']}/{self.custom_fiat}" | |
| 136 | + informative_pairs += [(stake_fiat, self.timeframe)] | |
| 137 | + # if BTC/STAKE is not in whitelist, add it as an informative pair on both timeframes | |
| 138 | + else: | |
| 139 | + btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 140 | + if not btc_stake in pairs: | |
| 141 | + informative_pairs += [(btc_stake, self.timeframe)] | |
| 142 | + | |
| 143 | + return informative_pairs | |
| 144 | + | |
| 145 | + """ | |
| 146 | + Indicator Definitions | |
| 147 | + """ | |
| 148 | + def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 149 | + if not metadata['pair'] in self.custom_trade_info: | |
| 150 | + self.custom_trade_info[metadata['pair']] = {} | |
| 151 | + | |
| 152 | + ## Base Timeframe / Pair | |
| 153 | + | |
| 154 | + dataframe['kama'] = ta.KAMA(dataframe, length=233) | |
| 155 | + | |
| 156 | + # RMI: https://www.tradingview.com/script/kwIt9OgQ-Relative-Momentum-Index/ | |
| 157 | + dataframe['rmi'] = cta.RMI(dataframe, length=24, mom=5) | |
| 158 | + | |
| 159 | + # Momentum Pinball: https://www.tradingview.com/script/fBpVB1ez-Momentum-Pinball-Indicator/ | |
| 160 | + dataframe['roc-mp'] = ta.ROC(dataframe, timeperiod=1) | |
| 161 | + dataframe['mp'] = ta.RSI(dataframe['roc-mp'], timeperiod=3) | |
| 162 | + | |
| 163 | + # MA Streak: https://www.tradingview.com/script/Yq1z7cIv-MA-Streak-Can-Show-When-a-Run-Is-Getting-Long-in-the-Tooth/ | |
| 164 | + dataframe['mastreak'] = cta.mastreak(dataframe, period=4) | |
| 165 | + | |
| 166 | + # Percent Change Channel: https://www.tradingview.com/script/6wwAWXA1-MA-Streak-Change-Channel/ | |
| 167 | + upper, mid, lower = cta.pcc(dataframe, period=40, mult=3) | |
| 168 | + dataframe['pcc-lowerband'] = lower | |
| 169 | + dataframe['pcc-upperband'] = upper | |
| 170 | + | |
| 171 | + lookup_idxs = dataframe.index.values - (abs(dataframe['mastreak'].values) + 1) | |
| 172 | + valid_lookups = lookup_idxs >= 0 | |
| 173 | + dataframe['sbc'] = np.nan | |
| 174 | + dataframe.loc[valid_lookups, 'sbc'] = dataframe['close'].to_numpy()[lookup_idxs[valid_lookups].astype(int)] | |
| 175 | + | |
| 176 | + dataframe['streak-roc'] = 100 * (dataframe['close'] - dataframe['sbc']) / dataframe['sbc'] | |
| 177 | + | |
| 178 | + # Trends, Peaks and Crosses | |
| 179 | + dataframe['candle-up'] = np.where(dataframe['close'] >= dataframe['close'].shift(),1,0) | |
| 180 | + dataframe['candle-up-trend'] = np.where(dataframe['candle-up'].rolling(5).sum() >= 3,1,0) | |
| 181 | + | |
| 182 | + dataframe['rmi-up'] = np.where(dataframe['rmi'] >= dataframe['rmi'].shift(),1,0) | |
| 183 | + dataframe['rmi-up-trend'] = np.where(dataframe['rmi-up'].rolling(5).sum() >= 3,1,0) | |
| 184 | + | |
| 185 | + dataframe['rmi-dn'] = np.where(dataframe['rmi'] <= dataframe['rmi'].shift(),1,0) | |
| 186 | + dataframe['rmi-dn-count'] = dataframe['rmi-dn'].rolling(8).sum() | |
| 187 | + | |
| 188 | + dataframe['streak-bo'] = np.where(dataframe['streak-roc'] < dataframe['pcc-lowerband'],1,0) | |
| 189 | + dataframe['streak-bo-count'] = dataframe['streak-bo'].rolling(8).sum() | |
| 190 | + | |
| 191 | + # Indicators used only for ROI and Custom Stoploss | |
| 192 | + ssldown, sslup = cta.SSLChannels_ATR(dataframe, length=21) | |
| 193 | + dataframe['sroc'] = cta.SROC(dataframe, roclen=21, emalen=13, smooth=21) | |
| 194 | + dataframe['ssl-dir'] = np.where(sslup > ssldown,'up','down') | |
| 195 | + | |
| 196 | + # Base pair informative timeframe indicators | |
| 197 | + informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe=self.inf_timeframe) | |
| 198 | + | |
| 199 | + # Get the "average day range" between the 1d high and 1d low to set up guards | |
| 200 | + informative['1d-high'] = informative['close'].rolling(24).max() | |
| 201 | + informative['1d-low'] = informative['close'].rolling(24).min() | |
| 202 | + informative['adr'] = informative['1d-high'] - informative['1d-low'] | |
| 203 | + | |
| 204 | + dataframe = merge_informative_pair(dataframe, informative, self.timeframe, self.inf_timeframe, ffill=True) | |
| 205 | + | |
| 206 | + # Other stake specific informative indicators | |
| 207 | + # e.g if stake is BTC and current coin is XLM (pair: XLM/BTC) | |
| 208 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 209 | + coin, stake = metadata['pair'].split('/') | |
| 210 | + fiat = self.custom_fiat | |
| 211 | + coin_fiat = f"{coin}/{fiat}" | |
| 212 | + stake_fiat = f"{stake}/{fiat}" | |
| 213 | + | |
| 214 | + # Informative COIN/FIAT e.g. XLM/USD - Base Timeframe | |
| 215 | + coin_fiat_tf = self.dp.get_pair_dataframe(pair=coin_fiat, timeframe=self.timeframe) | |
| 216 | + dataframe[f"{fiat}_rmi"] = cta.RMI(coin_fiat_tf, length=55, mom=5) | |
| 217 | + | |
| 218 | + # Informative STAKE/FIAT e.g. BTC/USD - Base Timeframe | |
| 219 | + stake_fiat_tf = self.dp.get_pair_dataframe(pair=stake_fiat, timeframe=self.timeframe) | |
| 220 | + dataframe[f"{stake}_rmi"] = cta.RMI(stake_fiat_tf, length=55, mom=5) | |
| 221 | + | |
| 222 | + # Informatives for BTC/STAKE if not in whitelist | |
| 223 | + else: | |
| 224 | + pairs = self.dp.current_whitelist() | |
| 225 | + btc_stake = f"BTC/{self.config['stake_currency']}" | |
| 226 | + if not btc_stake in pairs: | |
| 227 | + self.custom_btc_inf = True | |
| 228 | + # BTC/STAKE - Base Timeframe | |
| 229 | + btc_stake_tf = self.dp.get_pair_dataframe(pair=btc_stake, timeframe=self.timeframe) | |
| 230 | + dataframe['BTC_rmi'] = cta.RMI(btc_stake_tf, length=55, mom=5) | |
| 231 | + dataframe['BTC_close'] = btc_stake_tf['close'] | |
| 232 | + dataframe['BTC_kama'] = ta.KAMA(btc_stake_tf, length=144) | |
| 233 | + | |
| 234 | + # Slam some indicators into the trade_info dict so we can dynamic roi and custom stoploss in backtest | |
| 235 | + if self.dp.runmode.value in ('backtest', 'hyperopt'): | |
| 236 | + self.custom_trade_info[metadata['pair']]['sroc'] = dataframe[['date', 'sroc']].copy().set_index('date') | |
| 237 | + self.custom_trade_info[metadata['pair']]['ssl-dir'] = dataframe[['date', 'ssl-dir']].copy().set_index('date') | |
| 238 | + self.custom_trade_info[metadata['pair']]['rmi-up-trend'] = dataframe[['date', 'rmi-up-trend']].copy().set_index('date') | |
| 239 | + self.custom_trade_info[metadata['pair']]['candle-up-trend'] = dataframe[['date', 'candle-up-trend']].copy().set_index('date') | |
| 240 | + | |
| 241 | + return dataframe | |
| 242 | + | |
| 243 | + """ | |
| 244 | + Buy Signal | |
| 245 | + """ | |
| 246 | + def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 247 | + conditions = [] | |
| 248 | + | |
| 249 | + # Informative Timeframe Guards | |
| 250 | + conditions.append( | |
| 251 | + (dataframe['close'] <= dataframe[f"1d-low_{self.inf_timeframe}"] + | |
| 252 | + (self.inf_pct_adr.value * dataframe[f"adr_{self.inf_timeframe}"])) | |
| 253 | + ) | |
| 254 | + | |
| 255 | + # Base Timeframe Guards | |
| 256 | + conditions.append( | |
| 257 | + (dataframe['rmi-dn-count'] >= self.base_rmi_streak.value) & | |
| 258 | + (dataframe['streak-bo-count'] >= self.base_ma_streak.value) & | |
| 259 | + (dataframe['rmi'] <= self.base_rmi_max.value) & | |
| 260 | + (dataframe['rmi'] >= self.base_rmi_min.value) & | |
| 261 | + (dataframe['mp'] <= self.base_mp.value) | |
| 262 | + ) | |
| 263 | + | |
| 264 | + # Base Timeframe Trigger | |
| 265 | + if self.base_trigger.value == 'pcc': | |
| 266 | + conditions.append(qtpylib.crossed_above(dataframe['streak-roc'], dataframe['pcc-lowerband'])) | |
| 267 | + | |
| 268 | + if self.base_trigger.value == 'rmi': | |
| 269 | + conditions.append(dataframe['rmi-up-trend'] == 1) | |
| 270 | + | |
| 271 | + # Extra conditions for */BTC and */ETH stakes on additional informative pairs | |
| 272 | + if self.config['stake_currency'] in ('BTC', 'ETH'): | |
| 273 | + conditions.append( | |
| 274 | + (dataframe[f"{self.custom_fiat}_rmi"] > self.xtra_base_fiat_rmi.value) | | |
| 275 | + (dataframe[f"{self.config['stake_currency']}_rmi"] < self.xtra_base_stake_rmi.value) | |
| 276 | + ) | |
| 277 | + # Extra conditions for BTC/STAKE if not in whitelist | |
| 278 | + else: | |
| 279 | + if self.custom_btc_inf: | |
| 280 | + if self.xbtc_guard.value == 'strict': | |
| 281 | + conditions.append( | |
| 282 | + ( | |
| 283 | + (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 284 | + (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 285 | + ) | |
| 286 | + ) | |
| 287 | + if self.xbtc_guard.value == 'lazy': | |
| 288 | + conditions.append( | |
| 289 | + (dataframe['close'] > dataframe['kama']) | | |
| 290 | + ( | |
| 291 | + (dataframe['BTC_rmi'] > self.xbtc_base_rmi.value) & | |
| 292 | + (dataframe['BTC_close'] > dataframe['BTC_kama']) | |
| 293 | + ) | |
| 294 | + ) | |
| 295 | + | |
| 296 | + conditions.append(dataframe['volume'].gt(0)) | |
| 297 | + | |
| 298 | + if conditions: | |
| 299 | + dataframe.loc[ | |
| 300 | + reduce(lambda x, y: x & y, conditions), | |
| 301 | + 'buy'] = 1 | |
| 302 | + | |
| 303 | + return dataframe | |
| 304 | + | |
| 305 | + """ | |
| 306 | + Sell Signal | |
| 307 | + """ | |
| 308 | + def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: | |
| 309 | + | |
| 310 | + dataframe['sell'] = 0 | |
| 311 | + | |
| 312 | + return dataframe | |
| 313 | + | |
| 314 | + """ | |
| 315 | + Custom Stoploss | |
| 316 | + """ | |
| 317 | + def custom_stoploss(self, pair: str, trade: 'Trade', current_time: datetime, current_rate: float, current_profit: float, **kwargs) -> float: | |
| 318 | + | |
| 319 | + trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) | |
| 320 | + | |
| 321 | + if self.config['runmode'].value in ('live', 'dry_run'): | |
| 322 | + dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=pair, timeframe=self.timeframe) | |
| 323 | + sroc = dataframe['sroc'].iat[-1] | |
| 324 | + # If in backtest or hyperopt, get the indicator values out of the trades dict (Thanks @JoeSchr!) | |
| 325 | + else: | |
| 326 | + sroc = self.custom_trade_info[trade.pair]['sroc'].loc[current_time]['sroc'] | |
| 327 | + | |
| 328 | + if current_profit < self.cstp_threshold.value: | |
| 329 | + if self.cstp_bail_how.value == 'roc' or self.cstp_bail_how.value == 'any': | |
| 330 | + # Dynamic bailout based on rate of change | |
| 331 | + if (sroc/100) <= self.cstp_bail_roc.value: | |
| 332 | + return 0.001 | |
| 333 | + if self.cstp_bail_how.value == 'time' or self.cstp_bail_how.value == 'any': | |
| 334 | + # Dynamic bailout based on time | |
| 335 | + if trade_dur > self.cstp_bail_time.value: | |
| 336 | + return 0.001 | |
| 337 | + | |
| 338 | + return 1 | |
| 339 | + | |
| 340 | + """ | |
| 341 | + Freqtrade ROI Overload for dynamic ROI functionality | |
| 342 | + """ | |
| 343 | + def min_roi_reached_dynamic(self, trade: Trade, current_profit: float, current_time: datetime, trade_dur: int) -> Tuple[Optional[int], Optional[float]]: | |
| 344 | + | |
| 345 | + minimal_roi = self.minimal_roi | |
| 346 | + _, table_roi = self.min_roi_reached_entry(trade_dur) | |
| 347 | + | |
| 348 | + # see if we have the data we need to do this, otherwise fall back to the standard table | |
| 349 | + if self.custom_trade_info and trade and trade.pair in self.custom_trade_info: | |
| 350 | + if self.config['runmode'].value in ('live', 'dry_run'): | |
| 351 | + dataframe, last_updated = self.dp.get_analyzed_dataframe(pair=trade.pair, timeframe=self.timeframe) | |
| 352 | + rmi_trend = dataframe['rmi-up-trend'].iat[-1] | |
| 353 | + candle_trend = dataframe['candle-up-trend'].iat[-1] | |
| 354 | + ssl_dir = dataframe['ssl-dir'].iat[-1] | |
| 355 | + # If in backtest or hyperopt, get the indicator values out of the trades dict (Thanks @JoeSchr!) | |
| 356 | + else: | |
| 357 | + rmi_trend = self.custom_trade_info[trade.pair]['rmi-up-trend'].loc[current_time]['rmi-up-trend'] | |
| 358 | + candle_trend = self.custom_trade_info[trade.pair]['candle-up-trend'].loc[current_time]['candle-up-trend'] | |
| 359 | + ssl_dir = self.custom_trade_info[trade.pair]['ssl-dir'].loc[current_time]['ssl-dir'] | |
| 360 | + | |
| 361 | + min_roi = table_roi | |
| 362 | + max_profit = trade.calc_profit_ratio(trade.max_rate) | |
| 363 | + pullback_value = (max_profit - self.droi_pullback_amount.value) | |
| 364 | + in_trend = False | |
| 365 | + | |
| 366 | + if self.droi_trend_type.value == 'rmi' or self.droi_trend_type.value == 'any': | |
| 367 | + if rmi_trend == 1: | |
| 368 | + in_trend = True | |
| 369 | + if self.droi_trend_type.value == 'ssl' or self.droi_trend_type.value == 'any': | |
| 370 | + if ssl_dir == 'up': | |
| 371 | + in_trend = True | |
| 372 | + if self.droi_trend_type.value == 'candle' or self.droi_trend_type.value == 'any': | |
| 373 | + if candle_trend == 1: | |
| 374 | + in_trend = True | |
| 375 | + | |
| 376 | + # Force the ROI value high if in trend | |
| 377 | + if (in_trend == True): | |
| 378 | + min_roi = 100 | |
| 379 | + # If pullback is enabled, allow to sell if a pullback from peak has happened regardless of trend | |
| 380 | + if self.droi_pullback.value == True and (current_profit < pullback_value): | |
| 381 | + if self.droi_pullback_respect_table.value == True: | |
| 382 | + min_roi = table_roi | |
| 383 | + else: | |
| 384 | + min_roi = current_profit / 2 | |
| 385 | + | |
| 386 | + else: | |
| 387 | + min_roi = table_roi | |
| 388 | + | |
| 389 | + return trade_dur, min_roi | |
| 390 | + | |
| 391 | + # Change here to allow loading of the dynamic_roi settings | |
| 392 | + def min_roi_reached(self, trade: Trade, current_profit: float, current_time: datetime) -> bool: | |
| 393 | + trade_dur = int((current_time.timestamp() - trade.open_date_utc.timestamp()) // 60) | |
| 394 | + | |
| 395 | + if self.use_dynamic_roi: | |
| 396 | + _, roi = self.min_roi_reached_dynamic(trade, current_profit, current_time, trade_dur) | |
| 397 | + else: | |
| 398 | + _, roi = self.min_roi_reached_entry(trade_dur) | |
| 399 | + if roi is None: | |
| 400 | + return False | |
| 401 | + else: | |
| 402 | + return current_profit > roi | |
| 403 | + | |
| 404 | + """ | |
| 405 | + Trade Timeout Overloads | |
| 406 | + """ | |
| 407 | + def check_buy_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 408 | + bid_strategy = self.config.get('bid_strategy', {}) | |
| 409 | + ob = self.dp.orderbook(pair, 1) | |
| 410 | + current_price = ob[f"{bid_strategy['price_side']}s"][0][0] | |
| 411 | + if current_price > order['price'] * 1.01: | |
| 412 | + return True | |
| 413 | + return False | |
| 414 | + | |
| 415 | + def check_sell_timeout(self, pair: str, trade: Trade, order: dict, **kwargs) -> bool: | |
| 416 | + ask_strategy = self.config.get('ask_strategy', {}) | |
| 417 | + ob = self.dp.orderbook(pair, 1) | |
| 418 | + current_price = ob[f"{ask_strategy['price_side']}s"][0][0] | |
| 419 | + if current_price < order['price'] * 0.99: | |
| 420 | + return True | |
| 421 | + return False | |
| 422 | + | |
| 423 | +# Sub-strategy with parameters specific to BTC stake | |
| 424 | +class Solipsis4_BTC(Solipsis4): | |
| 425 | + | |
| 426 | + timeframe = '5m' | |
| 427 | + inf_timeframe = '1h' | |
| 428 | + | |
| 429 | + minimal_roi = { | |
| 430 | + "0": 0.01, | |
| 431 | + "1440": 0 | |
| 432 | + } | |
| 433 | + | |
| 434 | +# Sub-strategy with parameters specific to ETH stake | |
| 435 | +class Solipsis4_ETH(Solipsis4): | |
| 436 | + | |
| 437 | + timeframe = '5m' | |
| 438 | + inf_timeframe = '1h' | |
| 439 | + | |
| 440 | + minimal_roi = { | |
| 441 | + "0": 0.01, | |
| 442 | + "1440": 0 | |
| 443 | + } | |
| No newline at the end of the file |