This commit is contained in:
zhangkun9038@dingtalk.com 2025-05-12 10:50:39 +00:00
parent f34adc75f2
commit 037bb3fd28
5 changed files with 6 additions and 190 deletions

6
.gitignore vendored
View File

@ -124,3 +124,9 @@ data/
!result/
output.log
output_filted.log
result/backtest-result-2025-05-12_09-59-10_config.json
result/backtest-result-2025-05-12_09-59-10.json
result/backtest-result-2025-05-12_09-59-10.meta.json
result/backtest-result-2025-05-12_09-59-10_TheForceV7.py
result/output_filted.log
-r

File diff suppressed because one or more lines are too long

View File

@ -1 +0,0 @@
{"TheForceV7":{"run_id":"e8f9a8bc83f3c5ac5ce322fdaaa8e118ecd1dc96","backtest_start_time":1747043938,"timeframe":"5m","timeframe_detail":null,"backtest_start_ts":1704067200,"backtest_end_ts":1744502400}}

View File

@ -1,187 +0,0 @@
from freqtrade.strategy import IStrategy
from pandas import DataFrame
import numpy as np # noqa
import pandas as pd # noqa
import talib.abstract as ta
import freqtrade.vendor.qtpylib.indicators as qtpylib
class TheForceV7(IStrategy):
INTERFACE_VERSION = 3 # 升级到 V3 接口
minimal_roi = {
"0": 10
}
stoploss = -0.1
trailing_stop = False
timeframe = '3m'
process_only_new_candles = True
use_exit_signal = True # 替换 use_sell_signal
ignore_roi_if_entry_signal = True # 替换 ignore_roi_if_buy_signal
startup_candle_count: int = 30
order_types = {
'entry': 'limit', # 替换 buy
'exit': 'limit', # 替换 sell
'stoploss': 'market',
'stoploss_on_exchange': False
}
order_time_in_force = {
'entry': 'gtc',
'exit': 'gtc'
}
plot_config = {
'main_plot': {
'tema': {},
'sar': {'color': 'white'},
},
'subplots': {
"MACD": {
'macd': {'color': 'blue'},
'macdsignal': {'color': 'orange'},
},
"RSI": {
'rsi': {'color': 'red'},
}
}
}
def informative_pairs(self):
return []
def populate_indicators(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
stoch = ta.STOCH(dataframe)
dataframe['slowd'] = stoch['slowd']
dataframe['slowk'] = stoch['slowk']
dataframe['rsi7'] = ta.RSI(dataframe, timeperiod=7)
macd = ta.MACD(dataframe, 12, 26, 1)
dataframe['macd'] = macd['macd']
dataframe['macdsignal'] = macd['macdsignal']
dataframe['macdhist'] = macd['macdhist']
dataframe['ema5h'] = ta.EMA(dataframe['high'], timeperiod=5)
dataframe['ema5l'] = ta.EMA(dataframe['low'], timeperiod=5)
dataframe['ema5c'] = ta.EMA(dataframe['close'], timeperiod=5)
dataframe['ema5o'] = ta.EMA(dataframe['open'], timeperiod=5)
dataframe['ema200c'] = ta.MA(dataframe['close'], 200)
dataframe['volvar'] = (dataframe['volume'].rolling(100).mean() * 1.5)
bollinger = qtpylib.bollinger_bands(dataframe['close'], window=21, stds=2)
dataframe['bb_lowerband'] = bollinger['lower']
dataframe['bb_upperband'] = bollinger['upper']
dataframe['bb_middleband'] = bollinger['mid']
return dataframe
def populate_entry_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(
(
(dataframe['slowk'] >= 20) & (dataframe['slowk'] <= 80)
&
(dataframe['slowd'] >= 20) & (dataframe['slowd'] <= 80)
)
|
(
(dataframe['slowk'] < 30) & (dataframe['slowd'] < 30) &
(qtpylib.crossed_above(dataframe['slowk'], dataframe['slowd']))
)
)
&
(
(dataframe['macd'] > dataframe['macd'].shift(1))
&
(dataframe['macdsignal'] > dataframe['macdsignal'].shift(1))
)
&
(
(dataframe['close'] > dataframe['close'].shift(1))
&
(dataframe['open'] > dataframe['open'].shift(1))
)
&
(
(dataframe['ema5c'] >= dataframe['ema5o'])
|
(dataframe['open'] < dataframe['ema5l'])
)
&
(
(dataframe['volume'] > dataframe['volvar'])
)
|
(
(dataframe['slowk'] >= 20) & (dataframe['slowk'] <= 80)
&
(dataframe['slowd'] >= 20) & (dataframe['slowd'] <= 80)
&
(
(dataframe['close'] <= dataframe['bb_lowerband'])
|
(dataframe['open'] <= dataframe['bb_lowerband'])
)
)
|
(
(dataframe['close'] > dataframe['ema200c'])
&
(dataframe['rsi7'] < 35)
)
),
'enter_long'] = 1
return dataframe
def populate_exit_trend(self, dataframe: DataFrame, metadata: dict) -> DataFrame:
dataframe.loc[
(
(
(
(dataframe['slowk'] <= 80) & (dataframe['slowd'] <= 80)
)
|
(
(qtpylib.crossed_above(dataframe['slowk'], 70))
|
(qtpylib.crossed_above(dataframe['slowd'], 70))
)
)
&
(
(dataframe['macd'] < dataframe['macd'].shift(1))
&
(dataframe['macdsignal'] < dataframe['macdsignal'].shift(1))
)
&
(
(dataframe['ema5c'] < dataframe['ema5o'])
|
(dataframe['open'] >= dataframe['ema5h'])
)
|
(
(dataframe['slowk'] <= 80)
&
(dataframe['slowd'] <= 80)
&
(
(dataframe['close'] >= dataframe['bb_upperband'])
|
(dataframe['open'] >= dataframe['bb_upperband'])
)
)
|
(
(dataframe['high'] > dataframe['bb_upperband'])
&
(((dataframe['high'] - dataframe['bb_upperband']) * 100 / dataframe['bb_upperband']) > 1)
)
),
'exit_long'] = 1
return dataframe

View File

@ -1 +0,0 @@
{"$schema":"https://schema.freqtrade.io/schema.json","trading_mode":"spot","margin_mode":"isolated","max_open_trades":4,"stake_currency":"USDT","stake_amount":150,"startup_candle_count":30,"tradable_balance_ratio":1,"fiat_display_currency":"USD","dry_run":true,"identifier":"demo1","timeframe":"5m","dry_run_wallet":1000,"cancel_open_orders_on_exit":true,"stoploss":-0.05,"unfilledtimeout":{"entry":5,"exit":15},"exchange":{"name":"okx","key":"REDACTED","secret":"REDACTED","enable_ws":false,"ccxt_config":{"enableRateLimit":true,"rateLimit":500,"options":{"defaultType":"spot"}},"ccxt_async_config":{"enableRateLimit":true,"rateLimit":500,"timeout":20000},"pair_whitelist":["OKB/USDT","BTC/USDT","SOL/USDT","DOT/USDT","TON/USDT","ETH/USDT"],"pair_blacklist":[]},"freqai":{"enabled":true,"identifier":"test175","freqaimodel":"XGBoostRegressor","model_path":"/freqtrade/user_data/models","save_backtesting_prediction":true,"save_backtest_models":true,"backtest_period_days":10,"purge_old_models":true,"load_trained_model":true,"train_period_days":90,"live_retrain_hours":0,"include_predictions_in_final_dataframe":true,"data_kitchen":{"fillna":"ffill","feature_parameters":{"DI_threshold":0.5,"weight_factor":0.9}},"feature_parameters":{"include_timeframes":["5m","15m","1h"],"include_corr_pairlist":["BTC/USDT","ETH/USDT"],"label_period_candles":12,"include_shifted_candles":3,"indicator_periods_candles":[10,20,50],"plot_feature_importances":1,"feature_selection":{"method":"none"}},"data_split_parameters":{"test_size":0.2,"shuffle":false},"model_training_parameters":{"n_estimators":200,"learning_rate":0.05,"max_depth":6,"subsample":0.8,"colsample_bytree":0.8}},"entry_pricing":{"price_side":"same","use_order_book":true,"order_book_top":1,"price_last_balance":0.0,"check_depth_of_market":{"enabled":false,"bids_to_ask_delta":1}},"exit_pricing":{"price_side":"other","use_order_book":true,"order_book_top":1},"pairlists":[{"method":"StaticPairList"}],"api_server":{"enabled":true,"listen_ip_address":"0.0.0.0","listen_port":8080,"verbosity":"error","enable_openapi":false,"jwt_secret_key":"6a599ab046dbb419014807dffd7b8823bfa7e5df56b17d545485deb87331b4ca","ws_token":"6O5pBDiRigiZrmIsofaE2rkKMJtf9h8zVQ","CORS_origins":[],"username":"freqAdmin","password":"REDACTED"},"use_exit_signal":true,"bot_name":"freqtrade","initial_state":"running","force_entry_enable":false,"internals":{"process_throttle_secs":5,"heartbeat_interval":20,"loglevel":"DEBUG"},"config_files":["/freqtrade/config_examples/config_my_hyperopt.json"]}