Timeframe
5m
Direction
Long Only
Stoploss
-3.0%
Trailing Stop
No
ROI
0m: 1000.0%
Interface Version
2
Startup Candles
N/A
Indicators
5
freqtrade/freqtrade-strategies
Strategy 003 author@: Gerald Lonlas github@: https://github.com/freqtrade/freqtrade-strategies
import freqtrade.vendor.qtpylib.indicators as qtpylib
import numpy as np
import talib.abstract as ta
from freqtrade.strategy.interface import IStrategy
from freqtrade.strategy import (
merge_informative_pair,
DecimalParameter,
IntParameter,
CategoricalParameter,
)
from pandas import DataFrame
from functools import reduce
from freqtrade.persistence import Trade
# NFI3
# source: -
class NFI3(IStrategy):
INTERFACE_VERSION = 2
minimal_roi = {
"0": 10,
}
stoploss = -0.03 # effectively pinned.
timeframe = "5m"
inf_1h = "1h"
custom_info = {}
# Sell signal
use_exit_signal = True
exit_profit_only = False
# it doesn't meant anything, just to guarantee there is a minimal profit.
exit_profit_offset = 0.001
ignore_roi_if_entry_signal = True
# Trailing stop:
trailing_stop = False
# trailing_stop_positive = 0.184
# trailing_stop_positive_offset = 0.241
# trailing_only_offset_is_reached = True
# Custom stoploss
use_custom_stoploss = False
# Run "populate_indicators()" only for new candle.
process_only_new_candles = True
# Number of candles the strategy requires before producing valid signals
startup_candle_count: int = 400
#############################################################
buy_params = {
#############
# Enable/Disable conditions
"buy_condition_1_enable": True,
"buy_condition_2_enable": True,
"buy_condition_3_enable": True,
"buy_condition_4_enable": True,
"buy_condition_5_enable": True,
"buy_condition_6_enable": True,
"buy_condition_7_enable": True,
"buy_condition_8_enable": True,
"buy_condition_9_enable": True,
"buy_condition_10_enable": True,
}
sell_params = {
#############
# Enable/Disable conditions
"sell_condition_1_enable": True,
"sell_condition_2_enable": True,
"sell_condition_3_enable": True,
"sell_condition_4_enable": True,
"sell_condition_5_enable": True,
"sell_condition_6_enable": True,
"sell_condition_7_enable": True,
"sell_condition_8_enable": True,
}
############################################################################
# Buy
buy_condition_1_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_2_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_3_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_4_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_5_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_6_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_7_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_8_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_9_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_condition_10_enable = CategoricalParameter(
[True, False], default=True, space="buy"
)
buy_dip_threshold_0 = DecimalParameter(
0.001, 0.1, default=0.03, space="buy", decimals=3
)
buy_dip_threshold_1 = DecimalParameter(
0.001, 0.2, default=0.12, space="buy", decimals=3
)
buy_dip_threshold_2 = DecimalParameter(
0.05, 0.4, default=0.3, space="buy", decimals=3
)
buy_dip_threshold_3 = DecimalParameter(
0.2, 0.5, default=0.4, space="buy", decimals=3
)
buy_volume_1 = DecimalParameter(1.0, 30.0, default=2.0, space="buy", decimals=1)
buy_min_inc_1 = DecimalParameter(
0.005, 0.05, default=0.029, space="buy", decimals=3
)
buy_rsi_1h_min_1 = DecimalParameter(
40.0, 70.0, default=45.25, space="buy", decimals=2
)
buy_rsi_1h_max_1 = DecimalParameter(
70.0, 90.0, default=85.06, space="buy", decimals=2
)
buy_rsi_1 = DecimalParameter(30.0, 40.0, default=36.64, space="buy", decimals=2)
buy_mfi_1 = DecimalParameter(36.0, 65.0, default=45.25, space="buy", decimals=2)
buy_volume_2 = DecimalParameter(1.0, 10.0, default=2.96, space="buy", decimals=2)
buy_ema_relative_2 = DecimalParameter(
0.005, 0.08, default=0.006, space="buy", decimals=3
)
buy_rsi_1h_min_2 = DecimalParameter(
40.0, 70.0, default=63.91, space="buy", decimals=2
)
buy_rsi_1h_max_2 = DecimalParameter(
70.0, 95.0, default=89.94, space="buy", decimals=2
)
buy_rsi_1h_diff_2 = DecimalParameter(
35.0, 55.0, default=38.69, space="buy", decimals=2
)
buy_mfi_2 = DecimalParameter(36.0, 65.0, default=53.89, space="buy", decimals=2)
buy_bb40_bbdelta_close = DecimalParameter(0.005, 0.06, default=0.057, space="buy")
buy_bb40_closedelta_close = DecimalParameter(0.01, 0.03, default=0.023, space="buy")
buy_bb40_tail_bbdelta = DecimalParameter(0.15, 0.45, default=0.418, space="buy")
buy_bb20_close_bblowerband = DecimalParameter(0.7, 1.1, default=0.98, space="buy")
buy_bb20_volume = IntParameter(18, 35, default=24, space="buy")
buy_volume_5 = DecimalParameter(1.0, 10.0, default=4.12, space="buy", decimals=2)
buy_ema_open_mult_5 = DecimalParameter(
0.01, 0.04, default=0.019, space="buy", decimals=3
)
buy_volume_6 = DecimalParameter(1.0, 10.0, default=1.48, space="buy", decimals=2)
buy_ema_open_mult_6 = DecimalParameter(
0.025, 0.05, default=0.033, space="buy", decimals=3
)
buy_volume_7 = DecimalParameter(1.0, 10.0, default=7.04, space="buy", decimals=2)
buy_ema_open_mult_7 = DecimalParameter(
0.015, 0.03, default=0.02, space="buy", decimals=3
)
buy_rsi_7 = DecimalParameter(24.0, 50.0, default=41.09, space="buy", decimals=2)
buy_rsi_8 = DecimalParameter(30.0, 50.0, default=46.0, space="buy", decimals=1)
buy_volume_9 = DecimalParameter(1.0, 30.0, default=17.0, space="buy", decimals=1)
buy_bb_offset_9 = DecimalParameter(
0.97, 1.05, default=0.98, space="buy", decimals=3
)
buy_volume_10 = DecimalParameter(1.0, 26.0, default=9.6, space="buy", decimals=1)
buy_bb_offset_10 = DecimalParameter(
0.97, 1.05, default=0.994, space="buy", decimals=3
)
buy_rsi_1h_10 = DecimalParameter(15.0, 40.0, default=30.2, space="buy", decimals=1)
# Sell
sell_condition_1_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_2_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_3_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_4_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_5_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_6_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_7_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_condition_8_enable = CategoricalParameter(
[True, False], default=True, space="sell"
)
sell_rsi_bb_1 = DecimalParameter(60.0, 80.0, default=79.5, space="sell", decimals=1)
sell_rsi_bb_2 = DecimalParameter(72.0, 90.0, default=81, space="sell", decimals=1)
sell_rsi_main_3 = DecimalParameter(77.0, 90.0, default=82, space="sell", decimals=1)
sell_dual_rsi_rsi_4 = DecimalParameter(
72.0, 84.0, default=73.4, space="sell", decimals=1
)
sell_dual_rsi_rsi_1h_4 = DecimalParameter(
78.0, 92.0, default=79.6, space="sell", decimals=1
)
sell_ema_relative_5 = DecimalParameter(0.005, 0.05, default=0.024, space="sell")
sell_rsi_diff_5 = DecimalParameter(0.0, 20.0, default=4.382, space="sell")
sell_rsi_under_6 = DecimalParameter(
72.0, 90.0, default=87.708, space="sell", decimals=1
)
sell_rsi_1h_7 = DecimalParameter(80.0, 95.0, default=81.7, space="sell", decimals=1)
sell_bb_relative_8 = DecimalParameter(
1.05, 1.3, default=1.1, space="sell", decimals=3
)
sell_custom_profit_1 = DecimalParameter(
0.01, 0.20, default=0.01, space="sell", decimals=2
)
sell_custom_rsi_1 = DecimalParameter(
30.0, 50.0, default=38.65, space="sell", decimals=2
)
sell_custom_profit_2 = DecimalParameter(
0.01, 0.20, default=0.05, space="sell", decimals=2
)
sell_custom_rsi_2 = DecimalParameter(
34.0, 50.0, default=43.37, space="sell", decimals=2
)
sell_custom_profit_3 = DecimalParameter(
0.15, 0.30, default=0.25, space="sell", decimals=2
)
sell_custom_rsi_3 = DecimalParameter(
38.0, 55.0, default=51.87, space="sell", decimals=2
)
sell_custom_profit_4 = DecimalParameter(
0.3, 0.7, default=0.45, space="sell", decimals=2
)
sell_custom_rsi_4 = DecimalParameter(
40.0, 58.0, default=50.35, space="sell", decimals=2
)
sell_custom_under_profit_1 = DecimalParameter(
0.01, 0.10, default=0.02, space="sell", decimals=3
)
sell_custom_under_profit_2 = DecimalParameter(
0.01, 0.10, default=0.025, space="sell", decimals=3
)
sell_custom_under_profit_3 = DecimalParameter(
0.05, 0.3, default=0.07, space="sell", decimals=3
)
sell_trail_profit_min_1 = DecimalParameter(
0.1, 0.25, default=0.166, space="sell", decimals=3
)
sell_trail_profit_max_1 = DecimalParameter(
0.3, 0.5, default=0.38, space="sell", decimals=2
)
sell_trail_down_1 = DecimalParameter(
0.04, 0.2, default=0.154, space="sell", decimals=3
)
sell_trail_profit_min_2 = DecimalParameter(
0.01, 0.1, default=0.035, space="sell", decimals=3
)
sell_trail_profit_max_2 = DecimalParameter(
0.08, 0.25, default=0.1, space="sell", decimals=2
)
sell_trail_down_2 = DecimalParameter(
0.04, 0.2, default=0.045, space="sell", decimals=3
)
############################################################################
def custom_exit(
self,
pair: str,
trade: "Trade",
current_time: "datetime",
current_rate: float,
current_profit: float,
**kwargs
):
dataframe, _ = self.dp.get_analyzed_dataframe(pair, self.timeframe)
last_candle = dataframe.iloc[-1].squeeze()
if last_candle is not None:
if (current_profit > self.sell_custom_profit_4.value) & (
last_candle["rsi"] < self.sell_custom_rsi_4.value
):
return "target_profit_4"
elif (current_profit > self.sell_custom_profit_3.value) & (
last_candle["rsi"] < self.sell_custom_rsi_3.value
):
return "target_profit_3"
elif (current_profit > self.sell_custom_profit_2.value) & (
last_candle["rsi"] < self.sell_custom_rsi_2.value
):
return "target_profit_2"
elif (current_profit > self.sell_custom_profit_1.value) & (
last_candle["rsi"] < self.sell_custom_rsi_1.value
):
return "target_profit_1"
elif (current_profit > self.sell_custom_under_profit_1.value) & (
last_candle["close"] < last_candle["ema_200"]
):
return "target_profit_u_1"
elif (current_profit > self.sell_custom_under_profit_2.value) & (
last_candle["sma_200_dec"]
):
return "target_profit_u_2"
elif (
(current_profit > self.sell_trail_profit_min_1.value)
& (current_profit < self.sell_trail_profit_max_1.value)
& (
((trade.max_rate - trade.open_rate) / 100)
> (current_profit + self.sell_trail_down_1.value)
)
):
return "target_profit_t_1"
elif (
(current_profit > self.sell_trail_profit_min_2.value)
& (current_profit < self.sell_trail_profit_max_2.value)
& (
((trade.max_rate - trade.open_rate) / 100)
> (current_profit + self.sell_trail_down_2.value)
)
):
return "target_profit_t_2"
return None
def informative_pairs(self):
# get access to all pairs available in whitelist.
pairs = self.dp.current_whitelist()
# Assign tf to each pair so they can be downloaded and cached for strategy.
informative_pairs = [(pair, "1h") for pair in pairs]
return informative_pairs
def informative_1h_indicators(
self, dataframe: DataFrame, metadata: dict
) -> DataFrame:
assert self.dp, "DataProvider is required for multiple timeframes."
# Get the informative pair
informative_1h = self.dp.get_pair_dataframe(
pair=metadata["pair"], timeframe=self.inf_1h
)
# EMA
informative_1h["ema_15"] = ta.EMA(informative_1h, timeperiod=15)
informative_1h["ema_50"] = ta.EMA(informative_1h, timeperiod=50)
informative_1h["ema_100"] = ta.EMA(informative_1h, timeperiod=100)
informative_1h["ema_200"] = ta.EMA(informative_1h, timeperiod=200)
# SMA
informative_1h["sma_50"] = ta.SMA(informative_1h, timeperiod=50)
informative_1h["sma_200"] = ta.SMA(informative_1h, timeperiod=200)
# RSI
informative_1h["rsi"] = ta.RSI(informative_1h, timeperiod=14)
# BB
bollinger = qtpylib.bollinger_bands(
qtpylib.typical_price(informative_1h), window=20, stds=2
)
informative_1h["bb_lowerband"] = bollinger["lower"]
informative_1h["bb_middleband"] = bollinger["mid"]
informative_1h["bb_upperband"] = bollinger["upper"]
return informative_1h
def normal_tf_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# BB 40
bb_40 = qtpylib.bollinger_bands(dataframe["close"], window=40, stds=2)
dataframe["lower"] = bb_40["lower"]
dataframe["mid"] = bb_40["mid"]
dataframe["bbdelta"] = (bb_40["mid"] - dataframe["lower"]).abs()
dataframe["closedelta"] = (
dataframe["close"] - dataframe["close"].shift()
).abs()
dataframe["tail"] = (dataframe["close"] - dataframe["low"]).abs()
# BB 20
bollinger = qtpylib.bollinger_bands(
qtpylib.typical_price(dataframe), window=20, stds=2
)
dataframe["bb_lowerband"] = bollinger["lower"]
dataframe["bb_middleband"] = bollinger["mid"]
dataframe["bb_upperband"] = bollinger["upper"]
dataframe["volume_mean_30"] = dataframe["volume"].rolling(window=30).mean()
# EMA
dataframe["ema_12"] = ta.EMA(dataframe, timeperiod=12)
dataframe["ema_26"] = ta.EMA(dataframe, timeperiod=26)
dataframe["ema_50"] = ta.EMA(dataframe, timeperiod=50)
dataframe["ema_100"] = ta.EMA(dataframe, timeperiod=100)
dataframe["ema_200"] = ta.EMA(dataframe, timeperiod=200)
# SMA
dataframe["sma_5"] = ta.SMA(dataframe, timeperiod=5)
dataframe["sma_200"] = ta.SMA(dataframe, timeperiod=200)
dataframe["sma_200_dec"] = dataframe["sma_200"] < dataframe["sma_200"].shift(20)
# MFI
dataframe["mfi"] = ta.MFI(dataframe, timeperiod=14)
# RSI
dataframe["rsi"] = ta.RSI(dataframe, timeperiod=14)
# Alligator
dataframe["lips"] = ta.SMA(dataframe, timeperiod=5)
dataframe["smma_lips"] = dataframe["lips"].rolling(3).mean()
dataframe["teeth"] = ta.SMA(dataframe, timeperiod=8)
dataframe["smma_teeth"] = dataframe["teeth"].rolling(5).mean()
dataframe["jaw"] = ta.SMA(dataframe, timeperiod=13)
dataframe["smma_jaw"] = dataframe["jaw"].rolling(8).mean()
# Volume
dataframe["volume_mean_4"] = dataframe["volume"].rolling(4).mean().shift(1)
# If don't exceed the dip limits
dataframe["safe_dips"] = (
(
((dataframe["open"] - dataframe["close"]) / dataframe["close"])
< self.buy_dip_threshold_0.value
)
& (
(
(dataframe["open"].rolling(2).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_1.value
)
& (
(
(dataframe["open"].rolling(12).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_2.value
)
& (
(
(dataframe["open"].rolling(144).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_3.value
)
)
return dataframe
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# The indicators for the 1h informative timeframe
informative_1h = self.informative_1h_indicators(dataframe, metadata)
dataframe = merge_informative_pair(
dataframe, informative_1h, self.timeframe, self.inf_1h, ffill=True
)
# The indicators for the normal (5m) timeframe
dataframe = self.normal_tf_indicators(dataframe, metadata)
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
conditions.append(
(
self.buy_condition_1_enable.value
& (dataframe["ema_50_1h"] > dataframe["ema_200_1h"])
& (dataframe["sma_200"] > dataframe["sma_200"].shift(20))
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_1.value
> dataframe["volume"]
)
& (
(
(dataframe["close"] - dataframe["open"].rolling(36).min())
/ dataframe["open"].rolling(36).min()
)
> self.buy_min_inc_1.value
)
& (dataframe["rsi_1h"] > self.buy_rsi_1h_min_1.value)
& (dataframe["rsi_1h"] < self.buy_rsi_1h_max_1.value)
& (dataframe["rsi"] < self.buy_rsi_1.value)
& (dataframe["mfi"] < self.buy_mfi_1.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_2_enable.value
& (dataframe["close"] < dataframe["sma_5"])
& (dataframe["close"] > dataframe["ema_200"])
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_50"] > dataframe["ema_100"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_2.value
> dataframe["volume"]
)
& (
((dataframe["close"] - dataframe["ema_200"]) / dataframe["ema_200"])
< self.buy_ema_relative_2.value
)
& (dataframe["rsi_1h"] > self.buy_rsi_1h_min_2.value)
& (dataframe["rsi_1h"] < self.buy_rsi_1h_max_2.value)
& (
dataframe["rsi"]
< dataframe["rsi_1h"] - self.buy_rsi_1h_diff_2.value
)
& (dataframe["mfi"] < self.buy_mfi_2.value)
& (dataframe["close"] < (dataframe["bb_lowerband"]))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_3_enable.value
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_100"] > dataframe["ema_200"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["safe_dips"])
& dataframe["lower"].shift().gt(0)
& dataframe["bbdelta"].gt(
dataframe["close"] * self.buy_bb40_bbdelta_close.value
)
& dataframe["closedelta"].gt(
dataframe["close"] * self.buy_bb40_closedelta_close.value
)
& dataframe["tail"].lt(
dataframe["bbdelta"] * self.buy_bb40_tail_bbdelta.value
)
& dataframe["close"].lt(dataframe["lower"].shift())
& dataframe["close"].le(dataframe["close"].shift())
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_4_enable.value
& (dataframe["close"] > dataframe["ema_100"])
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_50"] > dataframe["ema_100"])
& (dataframe["ema_15_1h"] > dataframe["ema_50_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_200_1h"])
& (
(
(dataframe["open"].rolling(2).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_1.value
)
& (
(
(dataframe["open"].rolling(12).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_2.value
)
& (
(
(dataframe["open"].rolling(144).max() - dataframe["close"])
/ dataframe["close"]
)
< self.buy_dip_threshold_3.value
)
& (dataframe["close"] < dataframe["ema_50"])
& (
dataframe["close"]
< self.buy_bb20_close_bblowerband.value * dataframe["bb_lowerband"]
)
& (
dataframe["volume"]
< (
dataframe["volume_mean_30"].shift(1)
* self.buy_bb20_volume.value
)
)
)
)
conditions.append(
(
self.buy_condition_5_enable.value
&
# (dataframe['close'] > dataframe['ema_200']) &
(dataframe["close"] > dataframe["ema_100_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_5.value
> dataframe["volume"]
)
& (dataframe["ema_26"] > dataframe["ema_12"])
& (
(dataframe["ema_26"] - dataframe["ema_12"])
> (dataframe["open"] * self.buy_ema_open_mult_5.value)
)
& (
(dataframe["ema_26"].shift() - dataframe["ema_12"].shift())
> (dataframe["open"] / 100)
)
& (dataframe["close"] < (dataframe["bb_lowerband"]))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_6_enable.value
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_6.value
> dataframe["volume"]
)
& (dataframe["ema_26"] > dataframe["ema_12"])
& (
(dataframe["ema_26"] - dataframe["ema_12"])
> (dataframe["open"] * self.buy_ema_open_mult_6.value)
)
& (
(dataframe["ema_26"].shift() - dataframe["ema_12"].shift())
> (dataframe["open"] / 100)
)
& (dataframe["close"] < (dataframe["bb_lowerband"]))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_7_enable.value
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_7.value
> dataframe["volume"]
)
& (dataframe["ema_26"] > dataframe["ema_12"])
& (
(dataframe["ema_26"] - dataframe["ema_12"])
> (dataframe["open"] * self.buy_ema_open_mult_7.value)
)
& (
(dataframe["ema_26"].shift() - dataframe["ema_12"].shift())
> (dataframe["open"] / 100)
)
& (dataframe["rsi"] < self.buy_rsi_7.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_8_enable.value
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (dataframe["close"] > dataframe["open"])
& (dataframe["close"] > dataframe["smma_lips"])
& (dataframe["smma_lips"] > dataframe["smma_teeth"])
& (dataframe["smma_teeth"] > dataframe["smma_jaw"])
& (dataframe["smma_lips"].shift(1) > dataframe["smma_teeth"].shift(1))
& (dataframe["smma_teeth"].shift(1) > dataframe["smma_jaw"].shift(1))
& (dataframe["smma_lips"] > dataframe["smma_lips"].shift(1))
& (dataframe["smma_teeth"] > dataframe["smma_teeth"].shift(1))
& (dataframe["smma_jaw"] > dataframe["smma_jaw"].shift(1))
& (dataframe["rsi"] < self.buy_rsi_8.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_9_enable.value
& (dataframe["close"] > dataframe["ema_200"])
& (dataframe["close"] > dataframe["ema_200_1h"])
& (dataframe["ema_50_1h"] > dataframe["ema_100_1h"])
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_9.value
> dataframe["volume"]
)
& (dataframe["close"] < dataframe["ema_50"])
& (
dataframe["close"]
< dataframe["bb_lowerband"] * self.buy_bb_offset_9.value
)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.buy_condition_10_enable.value
& (dataframe["sma_200_1h"] > dataframe["sma_200_1h"].shift(24))
& (dataframe["safe_dips"])
& (
dataframe["volume_mean_4"] * self.buy_volume_10.value
> dataframe["volume"]
)
& (dataframe["close"] < dataframe["ema_50"])
& (
dataframe["close"]
< dataframe["bb_lowerband"] * self.buy_bb_offset_10.value
)
& (dataframe["rsi_1h"] < self.buy_rsi_1h_10.value)
& (dataframe["volume"] > 0)
)
)
if conditions:
dataframe.loc[reduce(lambda x, y: x | y, conditions), "buy"] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
conditions = []
conditions.append(
(
self.sell_condition_1_enable.value
& (dataframe["rsi"] > self.sell_rsi_bb_1.value)
& (dataframe["close"] > dataframe["bb_upperband"])
& (dataframe["close"].shift(1) > dataframe["bb_upperband"].shift(1))
& (dataframe["close"].shift(2) > dataframe["bb_upperband"].shift(2))
& (dataframe["close"].shift(3) > dataframe["bb_upperband"].shift(3))
& (dataframe["close"].shift(4) > dataframe["bb_upperband"].shift(4))
& (dataframe["close"].shift(5) > dataframe["bb_upperband"].shift(5))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_2_enable.value
& (dataframe["rsi"] > self.sell_rsi_bb_2.value)
& (dataframe["close"] > dataframe["bb_upperband"])
& (dataframe["close"].shift(1) > dataframe["bb_upperband"].shift(1))
& (dataframe["close"].shift(2) > dataframe["bb_upperband"].shift(2))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_3_enable.value
& (dataframe["rsi"] > self.sell_rsi_main_3.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_4_enable.value
& (dataframe["rsi"] > self.sell_dual_rsi_rsi_4.value)
& (dataframe["rsi_1h"] > self.sell_dual_rsi_rsi_1h_4.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_5_enable.value
& (dataframe["close"] < dataframe["ema_200"])
& (
((dataframe["ema_200"] - dataframe["close"]) / dataframe["close"])
< self.sell_ema_relative_5.value
)
& (dataframe["rsi"] > dataframe["rsi_1h"] + self.sell_rsi_diff_5.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_6_enable.value
& (dataframe["close"] < dataframe["ema_200"])
& (dataframe["close"] > dataframe["ema_50"])
& (dataframe["rsi"] > self.sell_rsi_under_6.value)
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_7_enable.value
& (dataframe["rsi_1h"] > self.sell_rsi_1h_7.value)
& (qtpylib.crossed_below(dataframe["ema_12"], dataframe["ema_26"]))
& (dataframe["volume"] > 0)
)
)
conditions.append(
(
self.sell_condition_8_enable.value
& (
dataframe["close"]
> dataframe["bb_upperband_1h"] * self.sell_bb_relative_8.value
)
& (dataframe["volume"] > 0)
)
)
if conditions:
dataframe.loc[reduce(lambda x, y: x | y, conditions), "sell"] = 1
return dataframe