From d75c2029758c46a4cee5e4fc255882dc248f951b Mon Sep 17 00:00:00 2001 From: jackyu66git Date: Sat, 12 Jul 2025 02:33:19 +0800 Subject: [PATCH] Change config --- .DS_Store | Bin 8196 -> 10244 bytes config/TradingViewConfig.xlsx | Bin 8753 -> 9095 bytes strategies/BB9033.py | 39 +++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/.DS_Store b/.DS_Store index 041d444aaf408faaaec952cf1bc7a0c65bd35b52..eebb0aecff6b2305ab0c85be8469d78eed5318e4 100644 GIT binary patch delta 448 zcmZp1XbF&DU|?W$DortDU{C-uIe-{M3-C-V6q~50$f&t7U^hRb=42j$Wyk^Yiam4klaq4tlRyRljqL`~djG)y$O4HG(4SOZTmaR- zJEFR1jb4vpq1tSx~S{;RILn9M&9R))JQ?uGy zP7YCJee0n3?3~=Z{9dq?42+Brnt>Ne!>B$WgP?;_ij#Aa^7C^*n!t)R@Oi&1xF|0t zKQA4qm~rz30aND5H-&jQU}kJ)6k%i8SRKzM$P6+L7|z^4!WC#R&&I;<%#-786D+=Fgd5)%OK2Vs){ delta 101 zcmZn(XmOBWU|?W$DortDU;r^WfEYvza8E20o2aMAsIoC&H$S7wWFCRzo1=w{m^UvI qWnvLz1}Xsp32q?a3R1nX@H_Klew9EDMu-^qpB z`FkdnkmRKGykk9BYKkA);WUXE*IIA7*9RuSfUSLS=r zn4XYIcSZMm?W_(v$ojON-)Y4dcn00f$eldwIhBVUxxCzlORTNNGNe-i;E`@qhBex8 zXC)pIKTJQp40fuF^R0|2N7|P}335oB=gLef4&d-Q5`=;_Jt~3>d&wI__d_V1#P$TM zZexO2(c*N(q^TDyfX?2Cuv*_pGgb>&iB_^#PcNz%V_oiRyqT#X&v2B`ii7kJy0K2| zJDVm>stAiATG40F%A3z2cH_Xkn<-Rb*)d<7Z=~r2zH&3QpZ5QXG`N z#h&`S8B!DXssmKg7Vg&)7Gk@XFz;9HGdj5?2MaFe{O09V*O&>mgsgL6T)r&82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=2R_f%x<#sBzX*Nzo7}$F~gjJ}wzcpjDAzhLy>gze86LqxE*+ZtM~2$KOuQBurL=M2sm%C=GVxh`Na;|3u%1E-@@0+={ z6Y801+Y-t07voBa&f1B0-+s&_Kfd*Ip|;q!G^A2eUWIDf*SHt8S=QFSwS{5%yd-6J z?68P*V4O)2=Ea=YW-bvz*}__I$*!cE3GrTri_!hqOFNJr)6m1ayORIGgEChv_Qg(0|MfAInWvHxxPtvuPV q=d7IAeFPNt$41oeu_3=X#Q1+jC{8R7pDOt{42$MNQ08*~N&Xww$Qq~s diff --git a/strategies/BB9033.py b/strategies/BB9033.py index a26e2c0..93ae3df 100644 --- a/strategies/BB9033.py +++ b/strategies/BB9033.py @@ -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]) \ No newline at end of file