2021-03-27 10:26:26 +00:00
|
|
|
# pragma pylint: disable=missing-docstring, invalid-name, pointless-string-statement
|
|
|
|
|
|
|
|
from pandas import DataFrame
|
2022-07-16 09:15:14 +00:00
|
|
|
from strategy_test_v3 import StrategyTestV3
|
2021-03-27 10:26:26 +00:00
|
|
|
|
|
|
|
import freqtrade.vendor.qtpylib.indicators as qtpylib
|
2022-03-20 12:12:26 +00:00
|
|
|
from freqtrade.strategy import BooleanParameter, DecimalParameter, IntParameter, RealParameter
|
2021-03-27 10:26:26 +00:00
|
|
|
|
|
|
|
|
2022-07-16 09:15:14 +00:00
|
|
|
class HyperoptableStrategy(StrategyTestV3):
|
2021-03-27 10:26:26 +00:00
|
|
|
"""
|
|
|
|
Default Strategy provided by freqtrade bot.
|
|
|
|
Please do not modify this strategy, it's intended for internal use only.
|
|
|
|
Please look at the SampleStrategy in the user_data/strategy directory
|
|
|
|
or strategy repository https://github.com/freqtrade/freqtrade-strategies
|
|
|
|
for samples and inspiration.
|
|
|
|
"""
|
|
|
|
|
|
|
|
buy_params = {
|
2024-05-12 13:41:07 +00:00
|
|
|
"buy_rsi": 35,
|
2021-03-27 10:26:26 +00:00
|
|
|
# Intentionally not specified, so "default" is tested
|
|
|
|
# 'buy_plusdi': 0.4
|
|
|
|
}
|
|
|
|
|
2024-05-12 13:41:07 +00:00
|
|
|
sell_params = {"sell_rsi": 74, "sell_minusdi": 0.4}
|
2021-03-27 10:26:26 +00:00
|
|
|
|
2024-05-12 13:41:07 +00:00
|
|
|
buy_plusdi = RealParameter(low=0, high=1, default=0.5, space="buy")
|
|
|
|
sell_rsi = IntParameter(low=50, high=100, default=70, space="sell")
|
|
|
|
sell_minusdi = DecimalParameter(
|
|
|
|
low=0, high=1, default=0.5001, decimals=3, space="sell", load=False
|
|
|
|
)
|
2021-08-04 18:52:56 +00:00
|
|
|
protection_enabled = BooleanParameter(default=True)
|
2021-08-04 18:01:28 +00:00
|
|
|
protection_cooldown_lookback = IntParameter([0, 50], default=30)
|
|
|
|
|
2023-01-18 17:15:35 +00:00
|
|
|
# Invalid plot config ...
|
|
|
|
plot_config = {
|
|
|
|
"main_plot": {},
|
|
|
|
}
|
|
|
|
|
2021-08-04 18:01:28 +00:00
|
|
|
@property
|
|
|
|
def protections(self):
|
|
|
|
prot = []
|
2021-08-04 18:52:56 +00:00
|
|
|
if self.protection_enabled.value:
|
2024-05-12 13:41:07 +00:00
|
|
|
prot.append(
|
|
|
|
{
|
|
|
|
"method": "CooldownPeriod",
|
|
|
|
"stop_duration_candles": self.protection_cooldown_lookback.value,
|
|
|
|
}
|
|
|
|
)
|
2021-08-04 18:01:28 +00:00
|
|
|
return prot
|
2021-03-27 10:26:26 +00:00
|
|
|
|
2022-07-03 12:10:08 +00:00
|
|
|
bot_loop_started = False
|
2023-03-26 09:30:44 +00:00
|
|
|
bot_started = False
|
2022-07-03 12:10:08 +00:00
|
|
|
|
|
|
|
def bot_loop_start(self):
|
|
|
|
self.bot_loop_started = True
|
|
|
|
|
2022-05-30 05:08:37 +00:00
|
|
|
def bot_start(self, **kwargs) -> None:
|
|
|
|
"""
|
|
|
|
Parameters can also be defined here ...
|
|
|
|
"""
|
2023-03-26 09:30:44 +00:00
|
|
|
self.bot_started = True
|
2024-05-12 13:41:07 +00:00
|
|
|
self.buy_rsi = IntParameter([0, 50], default=30, space="buy")
|
2022-05-30 05:08:37 +00:00
|
|
|
|
2021-03-27 10:26:26 +00:00
|
|
|
def informative_pairs(self):
|
|
|
|
"""
|
|
|
|
Define additional, informative pair/interval combinations to be cached from the exchange.
|
|
|
|
These pair/interval combinations are non-tradeable, unless they are part
|
|
|
|
of the whitelist as well.
|
|
|
|
For more information, please consult the documentation
|
|
|
|
:return: List of tuples in the format (pair, interval)
|
|
|
|
Sample: return [("ETH/USDT", "5m"),
|
|
|
|
("BTC/USDT", "15m"),
|
|
|
|
]
|
|
|
|
"""
|
|
|
|
return []
|
|
|
|
|
|
|
|
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
|
|
"""
|
|
|
|
Based on TA indicators, populates the buy signal for the given dataframe
|
|
|
|
:param dataframe: DataFrame
|
|
|
|
:param metadata: Additional information, like the currently traded pair
|
|
|
|
:return: DataFrame with buy column
|
|
|
|
"""
|
|
|
|
dataframe.loc[
|
|
|
|
(
|
2024-05-12 13:41:07 +00:00
|
|
|
(dataframe["rsi"] < self.buy_rsi.value)
|
|
|
|
& (dataframe["fastd"] < 35)
|
|
|
|
& (dataframe["adx"] > 30)
|
|
|
|
& (dataframe["plus_di"] > self.buy_plusdi.value)
|
|
|
|
)
|
|
|
|
| ((dataframe["adx"] > 65) & (dataframe["plus_di"] > self.buy_plusdi.value)),
|
|
|
|
"buy",
|
|
|
|
] = 1
|
2021-03-27 10:26:26 +00:00
|
|
|
|
|
|
|
return dataframe
|
|
|
|
|
|
|
|
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
|
|
|
|
"""
|
|
|
|
Based on TA indicators, populates the sell signal for the given dataframe
|
|
|
|
:param dataframe: DataFrame
|
|
|
|
:param metadata: Additional information, like the currently traded pair
|
2021-08-18 12:03:44 +00:00
|
|
|
:return: DataFrame with sell column
|
2021-03-27 10:26:26 +00:00
|
|
|
"""
|
|
|
|
dataframe.loc[
|
|
|
|
(
|
|
|
|
(
|
2024-05-12 13:41:07 +00:00
|
|
|
(qtpylib.crossed_above(dataframe["rsi"], self.sell_rsi.value))
|
|
|
|
| (qtpylib.crossed_above(dataframe["fastd"], 70))
|
|
|
|
)
|
|
|
|
& (dataframe["adx"] > 10)
|
|
|
|
& (dataframe["minus_di"] > 0)
|
|
|
|
)
|
|
|
|
| ((dataframe["adx"] > 70) & (dataframe["minus_di"] > self.sell_minusdi.value)),
|
|
|
|
"sell",
|
|
|
|
] = 1
|
2021-03-27 10:26:26 +00:00
|
|
|
return dataframe
|