add more files

This commit is contained in:
jackyu66git
2025-04-25 21:39:24 +08:00
parent 761d73cdac
commit bb0b70fa44
12 changed files with 787 additions and 108 deletions
+35 -21
View File
@@ -2,10 +2,8 @@
from freqtrade.strategy import IStrategy
import sys
import os
#sys.setrecursionlimit(1000000) #例如这里设置为一百万
#sys.path.append(os.path.abspath("/freqtrade/user_data/Chan"))
#sys.path.append(os.path.abspath("/Users/jack/Project/freqtrade/user_data/Chan"))
sys.path.append(os.path.abspath("/Users/jack/Documents/GitHub/freqtrade/user_data/Chan"))
# 添加父目录到系统路径
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from ChanLun import ChanLun
from ChanLun_Classifier import ChanLunClassifier
from ChanEnum import Chan_FX_TYPE, Chan_KLC_FX
@@ -26,9 +24,9 @@ logger = logging.getLogger(__name__)
# freqtrade download-data -c ./user_data/Chan/config/ChanLun_SOL.json -t 1m --pairs SOL/USDT:USDT --timerange=20250405-
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi stoploss --strategy ChanLun_SOL_5 --strategy-path ./user _data/Chan/strategies -c ./user_data/Chan/config/ChanLun_SOL.json -e 200 --timerange=20250201-20250401
# sudo docker compose run --rm chan_btc backtesting -c ./user_data/ChanLun_SOL.json --strategy ChanLun_SOL --strategy-path ./user_data/strategies --timerange=20250101-
# sudo docker compose run --rm chan_btc download-data -c ./user_data/ChanLun_SOL.json --pairs SOL/USDT:USDT -t 1m --timerange 20240101-
# sudo docker compose run --rm chan_btc trade -c ./user_data/ChanLun_SOL.json --strategy ChanLun_SOL --strategy-path ./user_data/strategies
# sudo docker compose run --rm chan_btc backtesting -c ./user_data/Chan/config/ChanLun_SOL.json --strategy ChanLun_SOL --strategy-path ./user_data/Chan/strategies --timerange=20250101-
# sudo docker compose run --rm chan_btc download-data -c ./user_data/Chan/config/ChanLun_SOL.json --pairs SOL/USDT:USDT -t 1m --timerange 20240101-
# sudo docker compose run --rm chan_btc trade -c ./user_data/Chan/config/ChanLun_SOL.json --strategy ChanLun_SOL --strategy-path ./user_data/Chan/strategies
class ChanLun_SOL_5(IStrategy):
INTERFACE_VERSION: int = 3
@@ -72,7 +70,7 @@ class ChanLun_SOL_5(IStrategy):
time30 = 30
time60 = 60
time4h = 240
time5 = 30
time5 = 5
last_time = datetime.now()
big_size = 0
big_state = "00"
@@ -117,11 +115,11 @@ class ChanLun_SOL_5(IStrategy):
self.classifier.train_model(dataframe, model_name="1m_model")
self.classifier.train_model(dataframe_1d, model_name="1d_model")
"""
model_name = "60m_model"
df = dataframe_60
"""
model_name = "30m_model"
df = dataframe_30
if self.classifier.model is None:
#self.classifier.train_model(df, model_name=model_name)
#self.classifier.train_model(df, model_name=model_name, data_file_path=model_name + '_feature_data.csv')
self.classifier.load_model(model_name=model_name)
klc_list = self.chan.get_klc_list(df)
bi_list = self.chan.cal_bi_list(klc_list)
@@ -131,14 +129,14 @@ class ChanLun_SOL_5(IStrategy):
bottom_count = 0
for index in range(int(len(klc_list) * 0.8), len(klc_list)):
klc = klc_list[index]
if self.classifier.predict(klc) > 0.37 and (klc.klc_fx_type == Chan_KLC_FX.BOTTOM1 or klc.klc_fx_type == Chan_KLC_FX.BOTTOM2):
if self.classifier.predict(klc) > 0.4 and (klc.klc_fx_type == Chan_KLC_FX.BOTTOM1 or klc.klc_fx_type == Chan_KLC_FX.BOTTOM2):
features = klc.get_feature_data()
print(klc.bi.start_time, klc.start_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
bottom_avg += self.classifier.predict(klc)
bottom_count += 1
if self.classifier.predict(klc) > 0.42 and (klc.klc_fx_type == Chan_KLC_FX.TOP1 or klc.klc_fx_type == Chan_KLC_FX.TOP2):
if self.classifier.predict(klc) > 0.35 and (klc.klc_fx_type == Chan_KLC_FX.TOP1 or klc.klc_fx_type == Chan_KLC_FX.TOP2):
features = klc.get_feature_data()
print(klc.bi.start_time, klc.start_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
print(klc.end_time, klc.fx, self.classifier.predict(klc), features['klc_macd'], features['klc_macd_hist'], features['klc_rsi'], features['klc_macd_signal'])
top_avg += self.classifier.predict(klc)
top_count += 1
if bottom_count > 0:
@@ -147,7 +145,7 @@ class ChanLun_SOL_5(IStrategy):
top_avg /= top_count
print(bottom_avg, top_avg)
print("-------------------------------------------------------------------------------")
"""
"""
self.print_xgb(dataframe, "1m_model")
self.print_xgb(dataframe_5, "5m_model")
@@ -167,13 +165,16 @@ class ChanLun_SOL_5(IStrategy):
#dataframe_60['state'] = self.chan.cal_klu_state(dataframe_60)
#dataframe_4h['state'] = self.chan.resample_klc_list(dataframe_4h)
self.chan.plot_dual(dataframe_30, dataframe_60)
#self.chan.plot_dual(dataframe_5, dataframe_30)
dataframe['rsi'] = ta.RSI(dataframe, timeperiod=14)
#self.print_macd_div_list(dataframe)
#self.print_resample_df(dataframe, 1, 50)
#self.chan.get_bi_list(dataframe_30)
if self.last_time + timedelta(minutes=1) < datetime.now():
#print(informative.iloc[-1])
#self.print_klc(dataframe, "1m: ")
#self.print_klc(dataframe_5, "5m: ")
#self.print_klc(dataframe_30, "30m:")
#self.log_macd_div_list(dataframe)
#self.print_xgb(dataframe, "1m_model")
#self.print_xgb(dataframe_5, "5m_model")
@@ -311,6 +312,19 @@ class ChanLun_SOL_5(IStrategy):
fx5 = fx_list[-5]
#print(fx1.end_time, fx1.fx, fx2.end_time, fx2.fx, fx3.end_time, fx3.fx)
logger.info(f'\n{fx5.end_time} {fx5.state} {fx4.end_time} {fx4.state} {fx3.end_time} {fx3.state} {fx2.end_time} {fx2.state} {fx1.end_time} {fx1.state} TF: {label}')
def print_klc(self, df, label):
klc_list = self.chan.get_full_klc_list(df)
log_str = f""
for index in range(len(klc_list)-5, len(klc_list)):
klc = klc_list[index]
fx = str(klc.fx).replace("Chan_FX_TYPE.", "")
bi_dir = str(klc.bi.dir).replace("Chan_BI_DIR.", "")
klc_fx_type = str(klc.klc_fx_type).replace("Chan_KLC_FX.", "")
if klc.end_time:
log_str += f"{klc.end_time}E, {bi_dir}, {klc_fx_type}, "
else:
log_str += f"{klc.start_time}S, {bi_dir}, {klc_fx_type}, "
logger.info(label+log_str)
def print_fx_list(self, df):
bsp_list = self.chan.get_bsp_list(self.chan.get_klc_list(df))
for bsp in bsp_list:
@@ -336,9 +350,9 @@ class ChanLun_SOL_5(IStrategy):
cn3 = 'resample_{}_state'.format(self.get_ticker_indicator()*time)
logger.info(f'{df[cn1][index]}, {df[cn2][index]}, {df[cn3][index]}')
def add_indicators(self, df):
fast = 8
slow = 16
period = 6
fast = 9
slow = 24
period = 14
macd = ta.MACD(df, fastperiod=fast, slowperiod=slow, signalperiod=period)
df['macd'] = macd['macd']
df['macdsignal'] = macd['macdsignal']