# GodStraNew Strategy
# Author: @Mablue (Masoud Azizi)
# github: https://github.com/mablue/
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --spaces buy roi trailing sell --strategy GodStraNew
# --- Do not remove these libs ---
from datetime import timedelta, datetime
from typing import Optional
from freqtrade import data
from freqtrade.persistence import Trade
from freqtrade.strategy.parameters import CategoricalParameter, DecimalParameter, IntParameter, BooleanParameter
from numpy.lib import math
from freqtrade.strategy.interface import IStrategy
import pandas
from pandas import DataFrame
import time
import logging
import ta as ta2
import calendar
from freqtrade.loggers import setup_logging
from freqtrade.strategy.strategy_helper import merge_informative_pair
# --------------------------------
# Add your lib to import here
# TODO: ta is fast but have not more indicators
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
from functools import reduce
import numpy as np
from random import shuffle
logger = logging.getLogger(__name__)
operators = [
"D", # Disabled gene
">", # Indicator, bigger than cross indicator
"<", # Indicator, smaller than cross indicator
"=", # Indicator, equal with cross indicator
"C", # Indicator, crossed the cross indicator
"CA", # Indicator, crossed above the cross indicator
"CB", # Indicator, crossed below the cross indicator
">R", # Normalized indicator, bigger than real number
"=R", # Normalized indicator, equal with real number
"R", # Normalized indicator devided to cross indicator, bigger than real number
"/=R", # Normalized indicator devided to cross indicator, equal with real number
"/ 10)
# TODO : it ill callculated in populate indicators.
dataframe[indicator] = gene_calculator(dataframe, indicator)
dataframe[crossed_indicator] = gene_calculator(dataframe, crossed_indicator)
indicator_trend_sma = f"{indicator}-SMA-{TREND_CHECK_CANDLES}"
if operator in ["UT", "DT", "OT", "CUT", "CDT", "COT"]:
dataframe[indicator_trend_sma] = gene_calculator(dataframe, indicator_trend_sma)
if operator == ">":
condition = (dataframe[indicator].shift(decalage) > dataframe[crossed_indicator].shift(decalage))
elif operator == "=":
condition = (np.isclose(dataframe[indicator].shift(decalage), dataframe[crossed_indicator].shift(decalage)))
elif operator == "<":
condition = (dataframe[indicator].shift(decalage) < dataframe[crossed_indicator].shift(decalage))
elif operator == "C":
condition = (
(qtpylib.crossed_below(dataframe[indicator].shift(decalage), dataframe[crossed_indicator].shift(decalage))) |
(qtpylib.crossed_above(dataframe[indicator].shift(decalage), dataframe[crossed_indicator].shift(decalage)))
)
elif operator == "CA":
condition = (qtpylib.crossed_above(dataframe[indicator].shift(decalage), dataframe[crossed_indicator].shift(decalage)))
elif operator == "CB":
condition = (qtpylib.crossed_below(dataframe[indicator].shift(decalage), dataframe[crossed_indicator].shift(decalage)))
elif operator == ">R":
condition = (dataframe[indicator].shift(decalage) > real_num)
elif operator == "=R":
condition = (np.isclose(dataframe[indicator].shift(decalage), real_num))
elif operator == "R":
condition = (dataframe[indicator].shift(decalage).div(dataframe[crossed_indicator].shift(decalage)) > real_num)
elif operator == "/=R":
condition = (np.isclose(dataframe[indicator].shift(decalage).div(dataframe[crossed_indicator].shift(decalage)), real_num))
elif operator == "/ dataframe[indicator_trend_sma].shift(decalage))
elif operator == "DT":
condition = (dataframe[indicator].shift(decalage) < dataframe[indicator_trend_sma].shift(decalage))
elif operator == "OT":
condition = (np.isclose(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage)))
elif operator == "CUT":
condition = (
(
qtpylib.crossed_above(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage))
) &
(
dataframe[indicator].shift(decalage) > dataframe[indicator_trend_sma].shift(decalage)
)
)
elif operator == "CDT":
condition = (
(
qtpylib.crossed_below(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage))
) &
(
dataframe[indicator].shift(decalage) < dataframe[indicator_trend_sma].shift(decalage)
)
)
elif operator == "COT":
condition = (
(
(
qtpylib.crossed_below(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage))
) |
(
qtpylib.crossed_above(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage))
)
) &
(
np.isclose(dataframe[indicator].shift(decalage), dataframe[indicator_trend_sma].shift(decalage))
)
)
return condition, dataframe
class GodStraJD3_7_5_9_2(IStrategy):
# #################### RESULTS PASTE PLACE ####################
# ROI table:
minimal_roi = {
"0": 10,
# "600": 0.12,
# "1200": 0.08,
# "2400": 0.06,
# "3600": 0.04,
# "7289": 0
}
# Stoploss:
stoploss = -1
# Buy hypers
timeframe = '5m'
# Trailing stoploss
trailing_stop = False
trailing_stop_positive = 0.15
trailing_stop_positive_offset = 0.20
trailing_only_offset_is_reached = True
plot_config = {
# Main plot indicators (Moving averages, ...)
'main_plot': {
'bb_lowerband': {'color': 'red'},
'bb_upperband': {'color': 'green'},
'sma100': {'color': 'blue'},
'sma10': {'color': 'yellow'},
'min20': {'color': '#87e470'},
'min50': {'color': '#ac3e2a'},
"min1.1": {'color': 'yellow'},
'sma20': {'color': 'cyan'},
'open_1d': {'color': 'white'},
'close_1d': {'color': 'white'}
},
'subplots': {
# Subplots - each dict defines one additional plot
"BB": {
'bb_width': {'color': 'white'},
'bb_lower_5': {'color': 'yellow'}
},
# "Ind0": {
# buy_crossed_indicator0: {'color': 'green'},
# buy_indicator0: {'color': 'red'}
# },
"Cond": {
'cond1': {'color': 'yellow'},
},
# "Ind1": {
# buy_indicator1: {'color': 'yellow'},
# buy_crossed_indicator1: {'color': 'pink'}
# },
# "Ind2": {
# buy_indicator2: {'color': 'cyan'},
# buy_crossed_indicator2: {'color': 'blue'},
# },
"Rsi": {
'rsi': {'color': 'pink'},
},
"Ecart": {
'normal_var_20': {'color': 'red'},
'normal_var_50': {'color': 'yellow'},
},
# "rolling": {
# 'bb_rolling': {'color': '#87e470'},
# "bb_rolling_min": {'color': '#ac3e2a'}
# },
"percent": {
"percent": {'color': 'green'},
"percent3": {'color': 'blue'},
"percent5": {'color': 'red'},
"distance_min": {'color': 'white'}
}
}
}
# #################### END OF RESULT PLACE ####################
trades = list()
profit_no_change = BooleanParameter(default=True, space="sell")
profit_quick_lost = BooleanParameter(default=True, space="sell")
profit_sma5 = BooleanParameter(default=True, space="sell")
profit_sma10 = BooleanParameter(default=True, space="sell")
profit_sma20 = BooleanParameter(default=True, space="sell")
profit_quick_gain = BooleanParameter(default=True, space="sell")
profit_quick_gain_3 = BooleanParameter(default=True, space="sell")
profit_old_sma10 = BooleanParameter(default=True, space="sell")
profit_very_old_sma10 = BooleanParameter(default=True, space="sell")
profit_over_rsi = BooleanParameter(default=True, space="sell")
profit_short_loss = BooleanParameter(default=True, space="sell")
profit_h_no_change = BooleanParameter(default=True, space="sell")
profit_h_quick_lost = BooleanParameter(default=True, space="sell")
profit_h_sma5 = BooleanParameter(default=True, space="sell")
profit_h_sma10 = BooleanParameter(default=True, space="sell")
profit_h_sma20 = BooleanParameter(default=True, space="sell")
profit_h_quick_gain = BooleanParameter(default=True, space="sell")
profit_h_quick_gain_3 = BooleanParameter(default=True, space="sell")
profit_h_old_sma10 = BooleanParameter(default=True, space="sell")
profit_h_very_old_sma10 = BooleanParameter(default=True, space="sell")
profit_h_over_rsi = BooleanParameter(default=True, space="sell")
profit_h_short_loss = BooleanParameter(default=True, space="sell")
# buy_signal_bb_width = DecimalParameter(0.06, 0.15, decimals=2, default=0.065, space='buy')
buy_real = DecimalParameter(0.001, 0.999, decimals=4, default=0.11908, space='buy')
buy_cat = CategoricalParameter([">R", "=R", " expected_profit) & (last_candle['pct_change_1_1d'] < 0):
# return "exp_profit_down"
if (current_profit >= - self.sell_too_old_percent.value) & ((current_time - trade.open_date_utc).days >= self.sell_too_old_day.value)\
& ((current_time - trade.open_date_utc).days < self.sell_too_old_day.value * 2)\
& (previous_last_candle['sma10'] > last_candle['sma10']) & (last_candle['percent3'] < 0):
return "too_old_0.01"
if (current_profit >= - self.sell_too_old_percent.value * 2) & ((current_time - trade.open_date_utc).days >= self.sell_too_old_day.value * 2)\
& ((current_time - trade.open_date_utc).days < self.sell_too_old_day.value * 3) \
& (previous_last_candle['sma10'] > last_candle['sma10']) & (last_candle['percent3'] < 0):
return "too_old_0.02"
if (current_profit >= - self.sell_too_old_percent.value * 3) & ((current_time - trade.open_date_utc).days >= self.sell_too_old_day.value * 3) \
& (previous_last_candle['sma10'] > last_candle['sma10']) & (last_candle['percent3'] < 0):
return "too_old_0.03"
if (last_candle['pct_change_1_1d'] > 0):
if self.profit_quick_lost.value and (current_profit >= 0.015) & (last_candle['percent3'] < -0.005):
return "quick_lost"
if self.profit_no_change.value and (current_profit > self.sell_profit_no_change.value) \
& (last_candle['percent10'] < self.sell_profit_percent10.value) & (last_candle['percent5'] < 0) \
& ((current_time - trade.open_date_utc).seconds >= 3600):
return "no_change"
if (current_profit > self.sell_percent.value) & (last_candle['percent3'] < - self.sell_percent3.value) \
& ((current_time - trade.open_date_utc).seconds <= 300 * self.sell_candels.value):
return "quick_gain_param"
if self.profit_sma5.value:
if (current_profit > expected_profit) \
& ((previous_5_candle['sma5'] > last_candle['sma5']) \
| (last_candle['percent3'] < -expected_profit) | (last_candle['percent5'] < -expected_profit)) \
& ((last_candle['percent'] < 0) & (last_candle['percent3'] < 0)):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'sma5'
if self.profit_sma10.value:
if (current_profit > expected_profit) \
& ((previous_5_candle['sma10'] > last_candle['sma10']) \
| (last_candle['percent3'] < -expected_profit) | (last_candle['percent5'] < -expected_profit)) \
& ((last_candle['percent'] < 0) & (last_candle['percent3'] < 0)):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'sma10'
if self.profit_sma20.value:
if (current_profit > 0.005) \
& (previous_last_candle['sma10'] > last_candle['sma10']) \
& ((current_time - trade.open_date_utc).seconds >= 3600) \
& ((previous_last_candle['sma20'] > last_candle['sma20']) &
((last_candle['percent5'] < 0) | (last_candle['percent10'] < 0) | (last_candle['percent20'] < 0))):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'sma20'
if self.profit_over_rsi.value:
if (current_profit > 0) & (previous_last_candle['rsi'] > self.sell_RSI.value): # & (last_candle['percent'] < 0): #| (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'over_rsi'
if (current_profit > 0) & (previous_last_candle['rsi'] > self.sell_RSI2.value) & \
(last_candle['percent'] < - self.sell_RSI2_percent.value): #| (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'over_rsi_2'
if self.profit_short_loss.value:
if (current_profit > -expected_profit) & (previous_last_candle['percent10'] > 0.04) & (last_candle['percent'] < 0)\
& ((current_time - trade.open_date_utc).days >= 1): #| (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'short_lost'
else:
if self.profit_h_quick_lost.value and (current_profit >= 0.015) & (last_candle['percent3'] < -0.005):
return "h_quick_lost"
if self.profit_h_no_change.value and (current_profit > self.sell_profit_no_change.value) \
& (last_candle['percent10'] < self.sell_profit_percent10.value) & (last_candle['percent5'] < 0) \
& ((current_time - trade.open_date_utc).seconds >= 3600):
return "h_no_change"
if (current_profit > self.sell_percent.value) & (last_candle['percent3'] < - self.sell_percent3.value) \
& ((current_time - trade.open_date_utc).seconds <= 300 * self.sell_candels.value):
return "h_quick_gain_param"
if self.profit_h_sma5.value:
if (current_profit > expected_profit) \
& ((previous_5_candle['sma5'] > last_candle['sma5']) \
| (last_candle['percent3'] < -expected_profit) | (
last_candle['percent5'] < -expected_profit)) \
& ((last_candle['percent'] < 0) & (last_candle['percent3'] < 0)):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_sma5'
if self.profit_h_sma10.value:
if (current_profit > expected_profit) \
& ((previous_5_candle['sma10'] > last_candle['sma10']) \
| (last_candle['percent3'] < -expected_profit) | (
last_candle['percent5'] < -expected_profit)) \
& ((last_candle['percent'] < 0) & (last_candle['percent3'] < 0)):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_sma10'
if self.profit_h_sma20.value:
if (current_profit > 0.005) \
& (previous_last_candle['sma10'] > last_candle['sma10']) \
& ((current_time - trade.open_date_utc).seconds >= 3600) \
& ((previous_last_candle['sma20'] > last_candle['sma20']) &
((last_candle['percent5'] < 0) | (last_candle['percent10'] < 0) | (
last_candle['percent20'] < 0))):
# print("over_bb_band_sma10_desc", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_sma20'
if self.profit_h_over_rsi.value:
if (current_profit > 0) & (previous_last_candle[
'rsi'] > self.sell_RSI.value): # & (last_candle['percent'] < 0): #| (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_over_rsi'
if (current_profit > 0) & (previous_last_candle['rsi'] > self.sell_RSI2.value) & \
(last_candle[
'percent'] < - self.sell_RSI2_percent.value): # | (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_over_rsi_2'
if self.profit_h_short_loss.value:
if (current_profit > -expected_profit) & (previous_last_candle['percent10'] > 0.04) & (
last_candle['percent'] < 0) \
& ((
current_time - trade.open_date_utc).days >= 1): # | (previous_last_candle['rsi'] > 75 & last_candle['rsi'] < 70)):
# print("over_rsi", pair, trade, " profit=", current_profit, " rate=", current_rate)
return 'h_short_lost'
def informative_pairs(self):
pairs = self.dp.current_whitelist()
informative_pairs = [(pair, '1d') for pair in pairs]
return informative_pairs
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
# dataframe['profit'] = 0
# RSI
dataframe['trend_ichimoku_base'] = ta2.trend.ichimoku_base_line(
dataframe['high'],
dataframe['low'],
window1=9,
window2=26,
visual=False,
fillna=False
)
KST = ta2.trend.KSTIndicator(
close=dataframe['close'],
roc1=10,
roc2=15,
roc3=20,
roc4=30,
window1=10,
window2=10,
window3=10,
window4=15,
nsig=9,
fillna=False
)
dataframe['trend_kst_diff'] = KST.kst_diff()
dataframe['pct_change'] = dataframe['close'].pct_change(5)
dataframe['min10'] = ta.MIN(dataframe['close'], timeperiod=10)
dataframe['min20'] = ta.MIN(dataframe['close'], timeperiod=20)
dataframe['min50'] = ta.MIN(dataframe['close'], timeperiod=50)
dataframe['min200'] = ta.MIN(dataframe['close'], timeperiod=200)
dataframe['max50'] = ta.MAX(dataframe['close'], timeperiod=50)
dataframe['max200'] = ta.MAX(dataframe['close'], timeperiod=200)
dataframe['rsi'] = ta.RSI(dataframe)
dataframe['sma5'] = ta.SMA(dataframe, timeperiod=5)
dataframe['sma10'] = ta.SMA(dataframe, timeperiod=10)
dataframe['sma20'] = ta.SMA(dataframe, timeperiod=20)
dataframe['sma50'] = ta.SMA(dataframe, timeperiod=50)
dataframe['sma100'] = ta.SMA(dataframe, timeperiod=100)
dataframe["percent"] = (dataframe["close"] - dataframe["open"]) / dataframe["open"]
dataframe["percent5"] = dataframe["percent"].rolling(5).sum()
dataframe["percent3"] = dataframe["percent"].rolling(3).sum()
dataframe["percent10"] = dataframe["percent"].rolling(10).sum()
dataframe["percent20"] = dataframe["percent"].rolling(20).sum()
dataframe["percent50"] = dataframe["percent"].rolling(50).sum()
dataframe['ecart_20'] = dataframe['close'].rolling(20).var() / dataframe['close']
dataframe['ecart_50'] = dataframe['close'].rolling(50).var() / dataframe['close']
dataframe['min'] = ta.MIN(dataframe['close'], timeperiod=self.buy_min_horizon.value)
dataframe['min10'] = ta.MIN(dataframe['close'], timeperiod=10)
dataframe['min20'] = ta.MIN(dataframe['close'], timeperiod=20)
dataframe['min50'] = ta.MIN(dataframe['close'], timeperiod=50)
dataframe['min200'] = ta.MIN(dataframe['close'], timeperiod=200)
dataframe["volume10"] = dataframe["volume"].rolling(10).mean()
dataframe['max'] = ta.MAX(dataframe['close'], timeperiod=200)
dataframe['max_min'] = dataframe['max'] / dataframe['min']
# Bollinger Bands
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["bb_percent"] = (
(dataframe["close"] - dataframe["bb_lowerband"]) /
(dataframe["bb_upperband"] - dataframe["bb_lowerband"])
)
dataframe["bb_width"] = (
(dataframe["bb_upperband"] - dataframe["bb_lowerband"]) / dataframe["bb_middleband"]
)
dataframe['bb_lower_var_5'] = (dataframe['bb_lowerband'] - dataframe['min50']).rolling(5).var()
dataframe['bb_lower_5'] = 100 * ((dataframe['bb_lowerband'].rolling(5).mean() / dataframe['bb_lowerband']) - 1)
# dataframe['bb_min'] = ta.MIN(dataframe['bb_lowerband'], timeperiod=36)
dataframe['distance_min'] = (dataframe['close'] - dataframe['min']) / dataframe['close']
dataframe['min1.1'] = 1.01 * dataframe['min']
dataframe['normal'] = 100 * (dataframe['close'] / dataframe['close'].rolling(200).mean())
dataframe['normal_var_20'] = dataframe['normal'].rolling(20).var()
dataframe['normal_var_50'] = dataframe['normal'].rolling(50).var()
dataframe[buy_crossed_indicator0] = gene_calculator(dataframe, buy_crossed_indicator0)
dataframe[buy_crossed_indicator1] = gene_calculator(dataframe, buy_crossed_indicator1)
dataframe[buy_crossed_indicator2] = gene_calculator(dataframe, buy_crossed_indicator2)
dataframe[buy_indicator0] = gene_calculator(dataframe, buy_indicator0)
dataframe[buy_indicator1] = gene_calculator(dataframe, buy_indicator1)
dataframe[buy_indicator2] = gene_calculator(dataframe, buy_indicator2)
dataframe["cond1"] = dataframe[buy_indicator0].div(dataframe[buy_crossed_indicator0])
# Normalization
tib = dataframe['trend_ichimoku_base']
dataframe['trend_ichimoku_base'] = (tib-tib.min())/(tib.max()-tib.min())
tkd = dataframe['trend_kst_diff']
dataframe['trend_kst_diff'] = (tkd-tkd.min())/(tkd.max()-tkd.min())
informative = self.dp.get_pair_dataframe(pair=metadata['pair'], timeframe="1d")
informative["rsi"] = ta.RSI(informative)
informative["max3"] = ta.MAX(informative['close'], timeperiod=3)
informative["min3"] = ta.MIN(informative['close'], timeperiod=3)
informative['pct_change_1'] = informative['close'].pct_change(1)
informative['pct_change_3'] = informative['close'].pct_change(3)
informative['pct_change_5'] = informative['close'].pct_change(5)
informative['sma3'] = ta.SMA(informative, timeperiod=3)
informative['sma5'] = ta.SMA(informative, timeperiod=5)
informative['sma10'] = ta.SMA(informative, timeperiod=10)
bollinger = qtpylib.bollinger_bands(qtpylib.typical_price(informative), window=20, stds=2)
informative['bb_lowerband'] = bollinger['lower']
informative['bb_middleband'] = bollinger['mid']
informative['bb_upperband'] = bollinger['upper']
informative["bb_percent"] = (
(informative["close"] - informative["bb_lowerband"]) /
(informative["bb_upperband"] - informative["bb_lowerband"])
)
informative["bb_width"] = (
(informative["bb_upperband"] - informative["bb_lowerband"]) / informative["bb_middleband"]
)
dataframe = merge_informative_pair(dataframe, informative, self.timeframe, "1d", ffill=True)
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
for decalage in range(self.buy_decalage_deb_0.value, self.buy_decalage0.value):
#if self.buy_0.value:
conditions = list()
condition1, dataframe = condition_generator(
dataframe,
buy_operator0,
buy_indicator0,
buy_crossed_indicator0,
self.buy_real_num0.value,
self.buy_decalage0.value
)
conditions.append(condition1)
dataframe.loc[
(
reduce(lambda x, y: x & y, conditions)
& (dataframe['volume10'].shift(decalage) * dataframe['close'].shift(decalage) / 1000 >= 10)
& (dataframe['sma10'].shift(1) <= dataframe['sma10'])
& (dataframe['close'] < dataframe['bb_middleband'])
& (dataframe['open'] < dataframe['sma10'])
& (dataframe['open'] < dataframe['sma20'])
& (dataframe['min50'].shift(decalage) == dataframe['min50'])
& (dataframe['min10'] <= dataframe['min50'] * 1.02)
& (dataframe['percent20'].shift(decalage) <= self.buy_0_percent20.value)
# & (dataframe['min20'] == dataframe['min50'])
& (dataframe['distance_min'] <= self.buy_0_distance.value)
& ((dataframe['close'] - dataframe['open'].shift(decalage)) / dataframe['open'].shift(decalage) <= 0.005)
# & (dataframe['bb_lower_var_5'] <= self.buy_1_bb_lower_var_5.value)
& (dataframe['bb_lower_5'] <= self.buy_1_bb_lower_5.value)
#& (dataframe['percent_1d'] >= self.buy_1_percent_1d_num.value)
#& (dataframe['percent_4h'] > 0)
#& (dataframe['percent3_4h'] <= self.buy_1_percent_4h_num.value)
& (dataframe['pct_change_1_1d'] < self.buy_pct_1.value)
& (dataframe['pct_change_3_1d'] < self.buy_pct_3.value)
& (dataframe['pct_change_5_1d'] < self.buy_pct_5.value)
), ['buy', 'buy_tag']] = (1, 'buy_1_' + str(decalage))
for decalage in range(self.buy_decalage_deb_2.value, self.buy_decalage2.value):
#if self.buy_2.value:
dataframe.loc[
(
(dataframe['cond1'].shift(decalage) <= 0.45) #self.buy_real_num0.value / 2)
& (dataframe['volume10'].shift(decalage) * dataframe['close'].shift(decalage) / 1000 >= 10)
# & (dataframe['sma10'].shift(1) <= dataframe['sma10'])
& (dataframe['close'] < dataframe['sma10'])
& (dataframe['open'] < dataframe['sma20'])
& (dataframe['open'] < dataframe['sma10'])
& (dataframe['min50'].shift(decalage) == dataframe['min50'])
#& (dataframe['min10'] <= dataframe['min50'] * 1.02)
& (dataframe['percent20'].shift(decalage) <= self.buy_2_percent20.value)
# & (dataframe['min20'] == dataframe['min50'])
& (dataframe['distance_min'] <= self.buy_2_distance.value)
& ((dataframe['close'] - dataframe['open'].shift(decalage)) / dataframe['open'].shift(
decalage) <= 0.005)
# & (dataframe['bb_lower_var_5'] <= self.buy_2_bb_lower_var_5.value)
& (dataframe['bb_lower_5'] <= self.buy_2_bb_lower_5.value)
#& (dataframe['percent_4h'] > 0)
#& (dataframe['percent3_4h'] <= self.buy_2_percent_4h_num.value)
& (dataframe['pct_change_1_1d'] < self.buy_pct_1.value)
& (dataframe['pct_change_3_1d'] < self.buy_pct_3.value)
& (dataframe['pct_change_5_1d'] < self.buy_pct_5.value)
), ['buy', 'buy_tag']] = (1, 'buy_2_' + str(decalage))
for decalage in range(self.buy_decalage_deb_3.value, self.buy_decalage3.value):
#if self.buy_3.value:
dataframe.loc[
(
(dataframe['cond1'].shift(decalage) <= 0.2)
& (dataframe['volume10'].shift(decalage) * dataframe['close'].shift(decalage) / 1000 >= 10)
# & (dataframe['sma10'].shift(1) <= dataframe['sma10'])
& (dataframe['close'] < dataframe['sma10'])
& (dataframe['open'] < dataframe['sma20'])
& (dataframe['open'] < dataframe['sma10'])
& (dataframe['min50'].shift(decalage) == dataframe['min50'])
#& (dataframe['min10'] <= dataframe['min50'] * 1.02)
& (dataframe['percent20'].shift(decalage) <= self.buy_3_percent20.value)
& (dataframe['distance_min'] <= self.buy_3_distance.value)
& ((dataframe['close'] - dataframe['open'].shift(decalage)) / dataframe['open'].shift(
decalage) <= 0.005)
# & (dataframe['bb_lower_var_5'] <= self.buy_3_bb_lower_var_5.value)
& (dataframe['bb_lower_5'] <= self.buy_3_bb_lower_5.value)
#& (dataframe['percent_4h'] > 0)
#& (dataframe['percent3_4h'] <= self.buy_3_percent_4h_num.value)
& (dataframe['pct_change_1_1d'] < self.buy_pct_1.value)
& (dataframe['pct_change_3_1d'] < self.buy_pct_3.value)
& (dataframe['pct_change_5_1d'] < self.buy_pct_5.value)
), ['buy', 'buy_tag']] = (1, 'buy_3_' + str(decalage))
conditions = []
IND = 'trend_ichimoku_base'
REAL = self.buy_real.value
OPR = self.buy_cat.value
DFIND = dataframe[IND]
# print(DFIND.mean())
if OPR == ">R":
conditions.append(DFIND > REAL)
elif OPR == "=R":
conditions.append(np.isclose(DFIND, REAL))
elif OPR == " self.buy_pct_1.value)
& (dataframe['pct_change_3_1d'] > self.buy_pct_3.value)
& (dataframe['pct_change_5_1d'] > self.buy_pct_5.value)
#& (dataframe['close_1d'] < dataframe['bb_lowerband_1d'] * self.buy_bb_lowerband.value)
& (dataframe['bb_width_1d'] >= self.buy_bb_width.value)
& (dataframe['close'] <= dataframe['sma5_1d'])
& (dataframe['sma10_1d'].shift(1) <= dataframe['sma10_1d'])
,
'buy'] = 1
return dataframe
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe