improve pairlist and spells lenght compatiblity check,bug #185 fixed

This commit is contained in:
Masoud Azizi
2021-05-30 14:17:35 +04:30
parent 20725a54bb
commit cebb5773df
+85 -44
View File
@@ -1,14 +1,24 @@
# DevilStra Strategy
# 𝔇𝔢𝔳𝔦𝔩 𝔦𝔰 𝔞𝔩𝔴𝔞𝔶𝔰 𝔰𝔱𝔯𝔬𝔫𝔤𝔢𝔯 𝔱𝔥𝔞𝔫 𝔊𝔬𝔡.
# 𝔅𝔲𝔱 𝔱𝔥𝔢 𝔬𝔫𝔩𝔶 𝔬𝔫𝔢 𝔴𝔥𝔬 𝔥𝔞𝔰 𝔱𝔥𝔢 𝔞𝔟𝔦𝔩𝔦𝔱𝔶
# 𝔱𝔬 𝔠𝔯𝔢𝔞𝔱𝔢 𝔫𝔢𝔴 𝔠𝔯𝔢𝔞𝔱𝔲𝔯𝔢𝔰 𝔦𝔰 𝔊𝔬𝔡.
# 𝔄𝔫𝔡 𝔱𝔥𝔢 𝔡𝔢𝔳𝔦𝔩 𝔪𝔞𝔨𝔢𝔰 𝔭𝔬𝔴𝔢𝔯𝔣𝔲𝔩 𝔰𝔭𝔢𝔩𝔩𝔰
# 𝔗𝔬 𝔠𝔯𝔢𝔞𝔱𝔢 𝔫𝔢𝔴 𝔠𝔯𝔢𝔞𝔱𝔲𝔯𝔢𝔰 𝔦𝔰 𝔊𝔬𝔡.
# 𝔄𝔫𝔡 𝔱𝔥𝔢 𝔇𝔢𝔳𝔦𝔩 𝔪𝔞𝔨𝔢𝔰 𝔭𝔬𝔴𝔢𝔯𝔣𝔲𝔩 𝔰𝔭𝔢𝔩𝔩𝔰
# 𝔉𝔯𝔬𝔪 𝔱𝔥𝔦𝔰 𝔰𝔪𝔞𝔩𝔩 𝔠𝔯𝔢𝔞𝔱𝔲𝔯𝔢𝔰 (𝔩𝔦𝔨𝔢 𝔣𝔯𝔬𝔤𝔰, 𝔢𝔱𝔠.)
# 𝔴𝔦𝔱𝔥 𝔣𝔯𝔞𝔤𝔪𝔢𝔫𝔱𝔞𝔱𝔦𝔬𝔫 𝔞𝔫𝔡 𝔪𝔦𝔵𝔦𝔫𝔤 𝔱𝔥𝔢𝔪.
# 𝔚𝔦𝔱𝔥 𝔣𝔯𝔞𝔤𝔪𝔢𝔫𝔱𝔞𝔱𝔦𝔬𝔫 𝔞𝔫𝔡 𝔪𝔦𝔵𝔦𝔫𝔤 𝔱𝔥𝔢𝔪.
# Author: @Mablue (Masoud Azizi)
# github: https://github.com/mablue/
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --spaces buy sell --strategy GodStraNew
# * IMPORTANT: You Need An "STATIC" Pairlist On Your Config.json !
# * IMPORTANT: First set PAIR_LIST_LENGHT={pair_whitelist size}
# * And re-hyperopt the Sell strategy And paste result in exact
# * place(lines 535~564)")
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLoss --spaces all -s 𝕯𝖊𝖛𝖎𝖑𝕾𝖙𝖗𝖆
# --- Do not remove these libs ---
import numpy as np
from functools import reduce
import freqtrade.vendor.qtpylib.indicators as qtpylib
import talib.abstract as ta
import random
from freqtrade.strategy.hyper import CategoricalParameter, DecimalParameter, IntParameter
@@ -16,39 +26,29 @@ from numpy.lib import math
from freqtrade.strategy.interface import IStrategy
from pandas import DataFrame
# --------------------------------
# Add your lib to import here
# TODO: talib 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
# TODO: this gene is removed 'MAVP' cuz or error on periods
########################### SETTINGS ##############################
# ########################## SETTINGS ##############################
# pairlist lenght(use exact count of pairs you used in whitelist size+1):
PAIR_LIST_LENGHT = 300
PAIR_LIST_LENGHT = 269
# you can find exact value of is inside GodStra
TREND_CHECK_CANDLES = 4
# Set the pain range of devil(2~9999)
PAIN_RANGE = 300
# Add GodStra Generated Results As spells inside SPELLS.
PAIN_RANGE = 1000
# Add "GodStraNew" Generated Results As spells inside SPELLS.
# Set them unic phonemes like 'Zi' 'Gu' or 'Lu'!
# * Use below replacement on GodStra results to
# * Change God Generated Creatures to Spells:
# +--------------------------+----------------------+
# | GodStra Hyperopt Results | DevilStra Spells |
# +--------------------------+----------------------+
# | | "phonem" : { |
# | buy_params = { | "buy_params" : { |
# | ... | ... |
# | } | }, |
# | sell_params = { | "sell_params" : { |
# | ... | ... |
# | } | } |
# | | }, |
# +--------------------------+----------------------+
# +-----------------------------+----------------------+
# | GodStraNew Hyperopt Results | DevilStra Spells |
# +-----------------------------+----------------------+
# | | "phonem" : { |
# | buy_params = { | "buy_params" : { |
# | ... | ... |
# | } | }, |
# | sell_params = { | "sell_params" : { |
# | ... | ... |
# | } | } |
# | | }, |
# +-----------------------------+----------------------+
SPELLS = {
"Zi": {
"buy_params": {
@@ -140,7 +140,7 @@ SPELLS = {
"sell_real_num2": 0.8467,
}
},
"A": {
"La": {
"buy_params": {
"buy_crossed_indicator0": "WMA-14",
"buy_crossed_indicator1": "MAMA-1-14",
@@ -321,7 +321,7 @@ SPELLS = {
}
}
}
######################### END SETTINGS ############################
# ######################## END SETTINGS ############################
def spell_finder(index, space):
@@ -534,19 +534,40 @@ def condition_generator(dataframe, operator, indicator, crossed_indicator, real_
class DevilStra(IStrategy):
# #################### RESULTS PASTE PLACE ####################
# * 4/1000: 9 trades. 7/0/2 Wins/Draws/Losses. Avg profit 91.39%. Median profit 53.30%. Total profit 0.08233278 BTC ( 82.33Σ%). Avg duration 23 days, 8:00:00 min. Objective: -3.27019
# #################### RESULT PASTE PLACE ####################
# * 9/100: 207 trades. 159/36/12 Wins/Draws/Losses. Avg profit 1.76%. Median profit 2.19%. Total profit 0.12158029 BTC ( 121.58Σ%). Avg duration 18:51:00 min. Objective: -30.36214
# Buy hyperspace params:
buy_params = {
"buy_spell": "Pa,Gu,Lu,Gu,Ra,Gu,Cu,Si,Lu,De,Si,Cu,De,Lu,Cu,Cu,Zi,De,Ra,Lu,Lu,Lu,De,Gu,Lu,Cu,Cu,Gu,Pa,Si,A,Zi,Gu,Ra,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𝖆𝖑𝖆𝖕𝖗𝖔𝖕𝖔𝖘 𝕬𝖓𝖉 𝕯𝖎𝖘𝖒𝖆𝖑 𝖙𝖎𝖒𝖊𝖋𝖗𝖆𝖒𝖊 𝖋𝖔𝖗 𝖙𝖍𝖎𝖘 𝖘𝖙𝖗𝖆𝖙𝖊𝖌𝖞:
timeframe = '1h'
spell_pot = [
",".join(
tuple(
@@ -564,19 +585,27 @@ class DevilStra(IStrategy):
sell_spell = CategoricalParameter(
spell_pot, default=spell_pot[0], space='sell')
# Stoploss:
stoploss = -0.1
# Buy hypers
timeframe = '1h'
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
return dataframe
def populate_buy_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
pairs = self.dp.current_whitelist()
pairs_len = len(pairs)
pair_index = pairs.index(metadata['pair'])
buy_params_index = self.buy_spell.value.split(",")[pair_index]
buy_spells = self.buy_spell.value.split(",")
buy_spells_len = len(buy_spells)
if pairs_len > buy_spells_len:
print(
f"First set PAIR_LIST_LENGHT={pairs_len + 1} And re-hyperopt the")
print("Buy strategy And paste result in exact place(lines 535~564)")
print("IMPORTANT: You Need An 'STATIC' Pairlist On Your Config.json !!!")
exit()
buy_params_index = buy_spells[pair_index]
params = spell_finder(buy_params_index, 'buy')
conditions = list()
@@ -624,7 +653,7 @@ class DevilStra(IStrategy):
if conditions:
dataframe.loc[
reduce(lambda x, y: x & y, conditions),
'buy'] = 1
'buy']=1
# print(len(dataframe.keys()))
@@ -633,8 +662,20 @@ class DevilStra(IStrategy):
def populate_sell_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
pairs = self.dp.current_whitelist()
pairs_len = len(pairs)
pair_index = pairs.index(metadata['pair'])
sell_params_index = self.sell_spell.value.split(",")[pair_index]
sell_spells = self.sell_spell.value.split(",")
sell_spells_len = len(sell_spells)
if pairs_len > sell_spells_len:
print(
f"First set PAIR_LIST_LENGHT={pairs_len + 1} And re-hyperopt the")
print("Sell strategy And paste result in exact place(lines 535~564)")
print("IMPORTANT: You Need An 'STATIC' Pairlist On Your Config.json !!!")
exit()
sell_params_index = sell_spells[pair_index]
params = spell_finder(sell_params_index, 'sell')