custom_entry_price custom_exit_price调整价格
This commit is contained in:
parent
0023f6789e
commit
c927bdded2
@ -3,7 +3,7 @@
|
||||
"redis": {
|
||||
"url": "redis://192.168.1.215:6379/0"
|
||||
},
|
||||
"enable_strategy_logs": true,
|
||||
"strategy_log_level": "INFO",
|
||||
"trading_mode": "spot",
|
||||
"margin_mode": "isolated",
|
||||
"max_open_trades": 5,
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
{
|
||||
"enable_strategy_logs": false
|
||||
|
||||
"strategy_log_level": "INFO"
|
||||
}
|
||||
@ -116,11 +116,11 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 确保EMA值在合理范围内
|
||||
final_coef = max(0.1, min(5.0, ema_volatility_coef))
|
||||
logger.info(f"计算波动系数EMA完成 {pair}: 最终系数={final_coef:.4f} (历史数据点数={len(self._volatility_history[pair])})")
|
||||
self.log_debug(f"计算波动系数EMA完成 {pair}: 最终系数={final_coef:.4f} (历史数据点数={len(self._volatility_history[pair])})")
|
||||
else:
|
||||
# 如果历史数据不足,返回当前波动系数(或默认值)
|
||||
final_coef = max(0.1, min(5.0, current_volatility_coef))
|
||||
logger.info(f"计算波动系数EMA完成 {pair}: 最终系数={final_coef:.4f} (历史数据不足,使用当前值)")
|
||||
self.log_debug(f"计算波动系数EMA完成 {pair}: 最终系数={final_coef:.4f} (历史数据不足,使用当前值)")
|
||||
|
||||
# 更新缓存和时间戳
|
||||
self._volatility_cache[pair] = final_coef
|
||||
@ -288,6 +288,10 @@ class FreqaiPrimer(IStrategy):
|
||||
exit_volume_multiplier = DecimalParameter(1.5, 3.0, decimals=1, default=2.0, optimize=False, load=True, space='sell')
|
||||
|
||||
rsi_overbought = IntParameter(50, 70, default=58, optimize=False, load=True, space='sell')
|
||||
|
||||
# 价格调整参数:入场降低百分比、出场抬高百分比(用于实盘和回测)
|
||||
entry_price_discount = DecimalParameter(0.005, 0.03, decimals=4, default=0.0167, optimize=True, load=True, space='buy') # 入场降价百分比(1.67% = 0.0167)
|
||||
exit_price_premium = DecimalParameter(0.005, 0.03, decimals=4, default=0.0167, optimize=True, load=True, space='sell') # 出场加价百分比
|
||||
|
||||
|
||||
def informative_pairs(self):
|
||||
@ -296,13 +300,23 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
def log_info(self, message: str):
|
||||
"""
|
||||
条件化的 INFO 日志输出,通过 config 中的 enable_strategy_logs 控制
|
||||
条件化的 INFO 日志输出,根据 config 中的 strategy_log_level 决定是否输出
|
||||
用法:self.log_info(f"[{pair}] 一些信息")
|
||||
"""
|
||||
# 从 config 中读取日志开关,默认开启
|
||||
enable_logs = self.config.get('enable_strategy_logs', True)
|
||||
if enable_logs:
|
||||
# 从 config 中读取日志级别,默认 INFO
|
||||
log_level = self.config.get('strategy_log_level', 'INFO').upper()
|
||||
# 只有当级别 <= INFO 时才输出
|
||||
if log_level in ['DEBUG', 'INFO']:
|
||||
logger.info(message)
|
||||
|
||||
def log_debug(self, message: str):
|
||||
"""
|
||||
条件化的 DEBUG 日志输出
|
||||
用法:self.log_debug(f"[{pair}] 调试信息")
|
||||
"""
|
||||
log_level = self.config.get('strategy_log_level', 'INFO').upper()
|
||||
if log_level == 'DEBUG':
|
||||
logger.debug(message)
|
||||
|
||||
def _validate_dataframe_columns(self, dataframe: DataFrame, required_columns: list, metadata: dict):
|
||||
"""
|
||||
@ -658,9 +672,10 @@ class FreqaiPrimer(IStrategy):
|
||||
# 设置入场信号
|
||||
dataframe.loc[final_condition, 'enter_long'] = 1
|
||||
|
||||
# 设置入场价格:下调1.67%(使用乘法避免除零风险)
|
||||
# 设置入场价格:使用 hyperopt 参数动态调整
|
||||
final_condition_updated = dataframe['enter_long'] == 1
|
||||
dataframe.loc[final_condition_updated, 'enter_price'] = dataframe.loc[final_condition_updated, 'close'] * 0.9833
|
||||
discount_multiplier = 1.0 - self.entry_price_discount.value # 例如 1 - 0.0167 = 0.9833
|
||||
dataframe.loc[final_condition_updated, 'enter_price'] = dataframe.loc[final_condition_updated, 'close'] * discount_multiplier
|
||||
|
||||
# 增强调试信息
|
||||
#logger.info(f"[{metadata['pair']}] 入场条件检查:")
|
||||
@ -1176,3 +1191,25 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
return adjusted_stake
|
||||
|
||||
def custom_entry_price(self, pair: str, trade: Optional['Trade'], current_time: datetime,
|
||||
proposed_rate: float, entry_tag: Optional[str], side: str,
|
||||
**kwargs) -> float:
|
||||
"""
|
||||
实盘入场价格调整:降低1.67%以提高成交率
|
||||
"""
|
||||
# 入场价格下调1.67%(与回测中 populate_entry_trend 的逻辑一致)
|
||||
adjusted_price = proposed_rate * 0.9833
|
||||
self.log_debug(f"[实盘入场] [{pair}] 市场价: {proposed_rate:.8f}, 调整后: {adjusted_price:.8f} (-1.67%)")
|
||||
return adjusted_price
|
||||
|
||||
def custom_exit_price(self, pair: str, trade: 'Trade', current_time: datetime,
|
||||
proposed_rate: float, current_profit: float, exit_tag: Optional[str],
|
||||
**kwargs) -> float:
|
||||
"""
|
||||
实盘出场价格调整:抬高1.67%以提高利润
|
||||
"""
|
||||
# 出场价格抬高1.67%
|
||||
adjusted_price = proposed_rate * 1.0167
|
||||
self.log_debug(f"[实盘出场] [{pair}] 市场价: {proposed_rate:.8f}, 调整后: {adjusted_price:.8f} (+1.67%)")
|
||||
return adjusted_price
|
||||
|
||||
|
||||
@ -370,7 +370,7 @@ print(' '.join(pairs) if pairs else '')")
|
||||
echo "Using pairs from --pairs parameter: $PAIRS_ARG"
|
||||
else
|
||||
# 使用默认的交易对列表
|
||||
DEFAULT_PAIRS="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT LTC/USDT SUI/USDT PEPE/USDT TRB/USDT FIL/USDT UNI/USDT KAITO/USDT"
|
||||
DEFAULT_PAIRS="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT LTC/USDT SUI/USDT PEPE/USDT TRB/USDT FIL/USDT KAITO/USDT"
|
||||
PAIRS_FLAG="--pairs $DEFAULT_PAIRS"
|
||||
echo "Using default pairs: $DEFAULT_PAIRS"
|
||||
fi
|
||||
@ -382,7 +382,7 @@ elif [ -n "$PAIRS_ARG" ]; then
|
||||
echo "Using pairs from --pairs parameter: $PAIRS_ARG"
|
||||
else
|
||||
# 没有提供任何交易对参数,使用默认值
|
||||
DEFAULT_PAIRS="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT LTC/USDT SUI/USDT PEPE/USDT TRB/USDT FIL/USDT UNI/USDT KAITO/USDT"
|
||||
DEFAULT_PAIRS="BTC/USDT TON/USDT DOT/USDT XRP/USDT OKB/USDT SOL/USDT DOGE/USDT LTC/USDT SUI/USDT PEPE/USDT TRB/USDT FIL/USDT KAITO/USDT"
|
||||
PAIRS_FLAG="--pairs $DEFAULT_PAIRS"
|
||||
echo "No pairs parameter provided, using default pairs: $DEFAULT_PAIRS"
|
||||
fi
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user