From e65893aa70a239675873b183963230971a5fb29f Mon Sep 17 00:00:00 2001 From: Masoud Azizi Date: Tue, 13 Apr 2021 21:14:37 +0430 Subject: [PATCH] GodStra Strategy + hyperopt file this is a genetic algorithm Strategy that makes a dna for using as strategy from GoDs genes! --- user_data/strategies/GodStra.py | 167 ++++++++++++++++++++++++++++++++ 1 file changed, 167 insertions(+) create mode 100644 user_data/strategies/GodStra.py diff --git a/user_data/strategies/GodStra.py b/user_data/strategies/GodStra.py new file mode 100644 index 0000000..bf11c70 --- /dev/null +++ b/user_data/strategies/GodStra.py @@ -0,0 +1,167 @@ +# GodStra Strategy +# Author: @Mablue (Masoud Azizi) +# github: https://github.com/mablue/ +# IMPORTANT:Add to your pairlists inside config.json (Under StaticPairList): +# { +# "method": "AgeFilter", +# "min_days_listed": 30 +# }, +# IMPORTANT: INSTALL TA BEFOUR RUN(pip install ta) +# IMPORTANT: Use Smallest "max_open_trades" for getting best results inside config.json + +# --- Do not remove these libs --- +import logging + +from numpy.lib import math +from freqtrade.strategy.interface import IStrategy +from pandas import DataFrame +# -------------------------------- + +# Add your lib to import here +# import talib.abstract as ta +import pandas as pd +# import talib.abstract as ta +from ta import add_all_ta_features +from ta.utils import dropna +import freqtrade.vendor.qtpylib.indicators as qtpylib +from functools import reduce +import numpy as np + + +class GodStra(IStrategy): + # 5/66: 9 trades. 8/0/1 Wins/Draws/Losses. Avg profit 21.83%. Median profit 35.52%. Total profit 1060.11476586 USDT ( 196.50Σ%). Avg duration 3440.0 min. Objective: -7.06960 + # +--------+---------+----------+------------------+--------------+-------------------------------+----------------+-------------+ + # | Best | Epoch | Trades | Win Draw Loss | Avg profit | Profit | Avg duration | Objective | + # |--------+---------+----------+------------------+--------------+-------------------------------+----------------+-------------| + # | * Best | 1/500 | 11 | 2 1 8 | 5.22% | 280.74230393 USDT (57.40%) | 2,421.8 m | -2.85206 | + # | * Best | 2/500 | 10 | 7 0 3 | 18.76% | 983.46414442 USDT (187.58%) | 360.0 m | -4.32665 | + # | * Best | 5/500 | 9 | 8 0 1 | 21.83% | 1,060.11476586 USDT (196.50%) | 3,440.0 m | -7.0696 | + + # Buy hyperspace params: + buy_params = { + 'buy-cross-0': 'volatility_kcc', + 'buy-indicator-0': 'trend_ichimoku_base', + 'buy-int-0': 42, + 'buy-oper-0': ' DataFrame: + # Add all ta features + dataframe = dropna(dataframe) + dataframe = add_all_ta_features( + dataframe, open="open", high="high", low="low", close="close", volume="volume", fillna=True) + # dataframe.to_csv("df.csv", index=True) + return dataframe + + def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame: + conditions = list() + # /5: Cuz We have 5 Group of variables inside buy_param + for i in range(int(len(self.buy_params)/5)): + + OPR = self.buy_params[f'buy-oper-{i}'] + IND = self.buy_params[f'buy-indicator-{i}'] + CRS = self.buy_params[f'buy-cross-{i}'] + INT = self.buy_params[f'buy-int-{i}'] + REAL = self.buy_params[f'buy-real-{i}'] + DFIND = dataframe[IND] + DFCRS = dataframe[CRS] + + if OPR == ">": + conditions.append(DFIND > DFCRS) + elif OPR == "=": + conditions.append(np.isclose(DFIND, DFCRS)) + elif OPR == "<": + conditions.append(DFIND < DFCRS) + elif OPR == "CA": + conditions.append(qtpylib.crossed_above(DFIND, DFCRS)) + elif OPR == "CB": + conditions.append(qtpylib.crossed_below(DFIND, DFCRS)) + elif OPR == ">I": + conditions.append(DFIND > INT) + elif OPR == "=I": + conditions.append(DFIND == INT) + elif OPR == "R": + conditions.append(DFIND > REAL) + elif OPR == "=R": + conditions.append(np.isclose(DFIND, REAL)) + elif OPR == " DataFrame: + conditions = list() + for i in range(int(len(self.sell_params)/5)): + OPR = self.sell_params[f'sell-oper-{i}'] + IND = self.sell_params[f'sell-indicator-{i}'] + CRS = self.sell_params[f'sell-cross-{i}'] + INT = self.sell_params[f'sell-int-{i}'] + REAL = self.sell_params[f'sell-real-{i}'] + DFIND = dataframe[IND] + DFCRS = dataframe[CRS] + + if OPR == ">": + conditions.append(DFIND > DFCRS) + elif OPR == "=": + conditions.append(np.isclose(DFIND, DFCRS)) + elif OPR == "<": + conditions.append(DFIND < DFCRS) + elif OPR == "CA": + conditions.append(qtpylib.crossed_above(DFIND, DFCRS)) + elif OPR == "CB": + conditions.append(qtpylib.crossed_below(DFIND, DFCRS)) + elif OPR == ">I": + conditions.append(DFIND > INT) + elif OPR == "=I": + conditions.append(DFIND == INT) + elif OPR == "R": + conditions.append(DFIND > REAL) + elif OPR == "=R": + conditions.append(np.isclose(DFIND, REAL)) + elif OPR == "