本地测试和本地实盘测试分开配置,需要加载startup candles才能得到ema26和ema52数据

This commit is contained in:
jackyu66git
2026-02-27 12:10:05 +08:00
parent eb039e9987
commit a7ab32133b
2 changed files with 98 additions and 8 deletions
+15 -8
View File
@@ -22,13 +22,13 @@ logger = logging.getLogger(__name__)
### Now you can use logger.info('asfd') to log
# freqtrade plot-dataframe --strategy ChanLun_BTC --datadir user_data/data/binance -c ./user_data/ChanLun_SOL_30.json --timerange=20250309-
# freqtrade trade -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies
# freqtrade backtesting -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange=20260101-
# freqtrade download-data -c ./user_data/Chan/config/EMA26_EMA52_Cross.json -t 1m 1m 1h 1d 1w 1M --pairs SOL/USDT:USDT --timerange=20240101-
# freqtrade download-data -c ./user_data/Chan/config/EMA26_EMA52_Cross.json -t 1m 1h 1d 1M --pairs SOL/USDT:USDT --timerange=20170101-
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/EMA26_EMA52_Cross.json -e 200 --timerange=20250201-20250901
# freqtrade edge -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
# freqtrade plot-dataframe -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
# freqtrade trade -c ./user_data/Chan/config/Local_Test.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies
# freqtrade backtesting -c ./user_data/Chan/config/Local_Test.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange=20260101-
# freqtrade download-data -c ./user_data/Chan/config/Local_Test.json -t 1m 1h 1d 1w 1M --pairs SOL/USDT:USDT --timerange=20240101-
# freqtrade download-data -c ./user_data/Chan/config/Local_Test.json -t 1m 1h 1d 1M --pairs SOL/USDT:USDT --timerange=20170101-
# freqtrade hyperopt --hyperopt-loss SharpeHyperOptLossDaily --spaces roi --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies -c ./user_data/Chan/config/Local_Test.json -e 200 --timerange=20250201-20250901
# freqtrade edge -c ./user_data/Chan/config/Local_Test.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
# freqtrade plot-dataframe -c ./user_data/Chan/config/Local_Test.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange 20250721-20250901
# sudo docker compose run --rm chanlun_btc backtesting -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --strategy EMA26_EMA52_Cross --strategy-path ./user_data/Chan/strategies --timerange=20250721-
# sudo docker compose run --rm chanlun_btc download-data -c ./user_data/Chan/config/EMA26_EMA52_Cross.json --pairs BTC/USDT:USDT -t 1m --timerange 20240101-
@@ -72,7 +72,7 @@ class EMA26_EMA52_Cross(IStrategy):
lev = 1.0
stoploss = -0.3 # 设置为很大的负值,让custom_stoploss来控制
use_custom_stoploss = False # 启用自定义止损
startup_candle_count = 1600
trailing_stop = False
trailing_stop_positive = 0.03
trailing_stop_positive_offset = 0.06
@@ -88,6 +88,7 @@ class EMA26_EMA52_Cross(IStrategy):
dataframe_15m = self.add_indicators(dataframe_15m)
dataframe_30m = self.add_indicators(dataframe_30m)
dataframe_60m = self.add_indicators(dataframe_60m)
dataframe = self.add_indicators(dataframe)
dataframe = resampled_merge(dataframe, dataframe_15m)
dataframe = resampled_merge(dataframe, dataframe_30m)
dataframe = resampled_merge(dataframe, dataframe_60m)
@@ -150,6 +151,9 @@ class EMA26_EMA52_Cross(IStrategy):
time = self.time30
cross_up = 'resample_{}_ema26_cross_up_52'.format(self.get_ticker_indicator() * time)
cross_down = 'resample_{}_ema26_cross_down_52'.format(self.get_ticker_indicator() * time)
#time = 1
#cross_up = 'ema26_cross_up_52'
#cross_down = 'ema26_cross_down_52'
dataframe.loc[
(dataframe[cross_up].shift(time) == True),
['enter_long', 'enter_tag']] = (1, 'long_signal')
@@ -161,6 +165,9 @@ class EMA26_EMA52_Cross(IStrategy):
time = self.time30
cross_up = 'resample_{}_ema26_cross_up_52'.format(self.get_ticker_indicator() * time)
cross_down = 'resample_{}_ema26_cross_down_52'.format(self.get_ticker_indicator() * time)
#time = 1
#cross_up = 'ema26_cross_up_52'
#cross_down = 'ema26_cross_down_52'
dataframe.loc[
(dataframe[cross_down].shift(time) == True),
['exit_long', 'exit_tag']] = (1, 'long_signal')