Change config

This commit is contained in:
jackyu66git
2025-07-12 02:33:19 +08:00
parent 14c194043a
commit d75c202975
3 changed files with 22 additions and 17 deletions
Vendored
BIN
View File
Binary file not shown.
Binary file not shown.
+22 -17
View File
@@ -12,6 +12,7 @@ import freqtrade.vendor.qtpylib.indicators as qtpylib
from technical.util import resample_to_interval, resampled_merge
from freqtrade.persistence import Trade, Order
from datetime import datetime, timedelta
from typing import Optional
import logging
logger = logging.getLogger(__name__)
# freqtrade plot-dataframe --strategy BB9033 --datadir user_data/data/binance -c ./user_data/ChanLun_SOL_30.json --timerange=20250309-
@@ -40,10 +41,10 @@ class BB9033(IStrategy):
INTERFACE_VERSION: int = 3
# 策略参数
bb_length = 54 # 布林带长度
atr_multiplier = 2.5 # ATR乘数(轨道)
atr_stop_multiplier = 5.6 # ATR乘数(止损)
atr_length = 17 # ATR计算周期
bb_length = 90 # 布林带长度
atr_multiplier = 4.2 # ATR乘数(轨道)
atr_stop_multiplier = 1.8 # ATR乘数(止损)
atr_length = 14 # ATR计算周期
# Minimal ROI designed for the strategy.
# This attribute will be overridden if the config file contains "minimal_roi"
@@ -58,10 +59,10 @@ class BB9033(IStrategy):
# Optimal timeframe for the strategy
timeframe = '3m'
time3 = 60
time = 30
# Trailing stop loss
trailing_stop = False
lev = 1.0
# Run "populate_indicators" only for new candle
process_only_new_candles = False
@@ -75,7 +76,7 @@ class BB9033(IStrategy):
"""
计算技术指标
"""
dataframe_3 = resample_to_interval(dataframe, self.get_ticker_indicator() * self.time3)
dataframe_3 = resample_to_interval(dataframe, self.get_ticker_indicator() * self.time)
# 计算ATR(用于止损计算)
dataframe_3['atr'] = ta.ATR(dataframe_3, timeperiod=self.atr_length)
@@ -84,7 +85,8 @@ class BB9033(IStrategy):
bb_upper, bb_middle, bb_lower = ta.BBANDS(dataframe_3['close'], timeperiod=self.bb_length, nbdevup=self.atr_multiplier, nbdevdn=self.atr_multiplier, matype=0)
dataframe_3['bb_upper'] = bb_upper
dataframe_3['bb_lower'] = bb_lower
for i in range(1700, 1800):
print(dataframe_3.iloc[i])
# 计算突破条件(与Pine Script保持一致)
# 确保所有用于计算的数据都不是NaN
valid_data = (
@@ -113,8 +115,8 @@ class BB9033(IStrategy):
"""
Based on TA indicators, populates the entry trend columns
"""
break_below_lower = 'resample_{}_break_below_lower'.format(self.get_ticker_indicator()*self.time3)
break_above_upper = 'resample_{}_break_above_upper'.format(self.get_ticker_indicator()*self.time3)
break_below_lower = 'resample_{}_break_below_lower'.format(self.get_ticker_indicator()*self.time)
break_above_upper = 'resample_{}_break_above_upper'.format(self.get_ticker_indicator()*self.time)
# 做多条件:价格跌破下轨
dataframe.loc[
@@ -138,8 +140,8 @@ class BB9033(IStrategy):
"""
Based on TA indicators, populates the exit trend columns
"""
bb_upper_str = 'resample_{}_bb_upper'.format(self.get_ticker_indicator()*self.time3)
bb_lower_str = 'resample_{}_bb_lower'.format(self.get_ticker_indicator()*self.time3)
bb_upper_str = 'resample_{}_bb_upper'.format(self.get_ticker_indicator()*self.time)
bb_lower_str = 'resample_{}_bb_lower'.format(self.get_ticker_indicator()*self.time)
# 多头止盈:价格突破上轨(与Pine Script一致)
dataframe.loc[
@@ -215,9 +217,9 @@ class BB9033(IStrategy):
latest_candle = dataframe.iloc[-1]
# 使用重采样后的字段名
bb_upper_str = 'resample_{}_bb_upper'.format(self.get_ticker_indicator() * self.time3)
bb_lower_str = 'resample_{}_bb_lower'.format(self.get_ticker_indicator() * self.time3)
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator() * self.time3)
bb_upper_str = 'resample_{}_bb_upper'.format(self.get_ticker_indicator() * self.time)
bb_lower_str = 'resample_{}_bb_lower'.format(self.get_ticker_indicator() * self.time)
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator() * self.time)
# 确保技术指标有效
if (np.isnan(latest_candle[bb_upper_str]) or
@@ -243,7 +245,7 @@ class BB9033(IStrategy):
return
# 获取开仓时的ATR值
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator() * self.time3)
atr_str = 'resample_{}_atr'.format(self.get_ticker_indicator() * self.time)
# 找到最接近开仓时间的K线
open_candle = dataframe.iloc[-1] # 使用最新的K线作为开仓时的数据
@@ -275,6 +277,9 @@ class BB9033(IStrategy):
if trade_id in self.trade_stop_prices:
del self.trade_stop_prices[trade_id]
logger.info(f"交易 {trade.id} 已关闭,清理止损价格记录")
def leverage(self, pair: str, current_time: datetime, current_rate: float,
proposed_leverage: float, max_leverage: float, entry_tag: Optional[str], side: str,
**kwargs) -> float:
return self.lev
def get_ticker_indicator(self):
return int(self.timeframe[:-1])