关掉剧烈拉升检查
This commit is contained in:
parent
ae475be4d9
commit
33ceb20547
185
doc/介绍.md
185
doc/介绍.md
@ -0,0 +1,185 @@
|
||||
# 策略入场出场逻辑和FreqAI机制详解
|
||||
|
||||
## 🎯 策略总体架构
|
||||
|
||||
这是一个基于**多时间框架技术分析**和**FreqAI机器学习**相结合的智能交易策略。策略分为两个主要部分:
|
||||
|
||||
1. **传统技术指标过滤系统**
|
||||
2. **FreqAI智能决策系统**
|
||||
|
||||
## 📊 技术指标入场逻辑
|
||||
|
||||
### 1. 多时间框架趋势确认
|
||||
```python
|
||||
# 3m、15m、1h三个时间框架的趋势确认
|
||||
dataframe['trend_3m'] = np.where(dataframe['ema_50_3m'] > dataframe['ema_200_3m'], 1, 0)
|
||||
dataframe['trend_15m'] = np.where(dataframe['ema_50_15m'] > dataframe['ema_200_15m'], 1, 0)
|
||||
dataframe['trend_1h_ema'] = np.where(dataframe['ema_50_1h'] > dataframe['ema_200_1h'], 1, 0)
|
||||
```
|
||||
|
||||
### 2. EMA趋势过滤(核心逻辑)
|
||||
```python
|
||||
# EMA5保持在EMA20之上 或 最近20根1h K线内发生过向上穿越
|
||||
# 这样既能捕捉趋势启动,又能在趋势延续时继续入场
|
||||
if 'ema_5_1h' in dataframe.columns and 'ema_20_1h' in dataframe.columns:
|
||||
ema5_above_ema20 = dataframe['ema_5_1h'] > dataframe['ema_20_1h']
|
||||
if 'ema5_cross_above_ema20' in dataframe.columns:
|
||||
recent_cross = dataframe['ema5_cross_above_ema20'].rolling(window=20, min_periods=1).max() == 1
|
||||
ema_trend_filter = ema5_above_ema20 | recent_cross
|
||||
else:
|
||||
ema_trend_filter = ema5_above_ema20
|
||||
```
|
||||
|
||||
### 3. EMA20趋势强度过滤(新增功能)
|
||||
```python
|
||||
# 新增:EMA20斜率必须满足阈值(避免过于平缓的趋势)
|
||||
if 'ema_20_1h' in dataframe.columns:
|
||||
ema20_slope = (dataframe['ema_20_1h'] - dataframe['ema_20_1h'].shift(5)) / dataframe['ema_20_1h'].shift(5)
|
||||
min_ema20_slope = 0.0001 # 0.01%的斜率阈值
|
||||
ema20_slope_condition = ema20_slope > min_ema20_slope
|
||||
ema_trend_filter = ema_trend_filter & ema20_slope_condition
|
||||
```
|
||||
|
||||
### 4. 多因子综合筛选
|
||||
```python
|
||||
# 基础条件组合
|
||||
condition_count = (
|
||||
close_to_bb_lower_1h.astype(int) +
|
||||
rsi_condition_1h.astype(int) +
|
||||
stochrsi_condition_1h.astype(int) +
|
||||
macd_condition_1h.astype(int) +
|
||||
(volume_spike | bb_width_condition).astype(int) +
|
||||
trend_confirmation.astype(int)
|
||||
)
|
||||
basic_condition = condition_count >= self.min_condition_count.value
|
||||
final_condition = basic_condition & ema_trend_filter & ~kdj_1h_block
|
||||
```
|
||||
|
||||
## 🤖 FreqAI智能决策系统
|
||||
|
||||
### 1. 标签定义(分类任务)
|
||||
```python
|
||||
# 入场标签:未来24根K线内最高价是否超过+1%
|
||||
future_max = dataframe["close"].rolling(window=24, min_periods=1).max().shift(-23)
|
||||
dataframe["&s-entry_signal"] = np.where(
|
||||
future_max > dataframe["close"] * 1.01, # +1%阈值
|
||||
1, 0
|
||||
)
|
||||
|
||||
# 出场标签:未来24根K线内最低价是否跌破-1%
|
||||
future_min = dataframe["close"].rolling(window=24, min_periods=1).min().shift(-23)
|
||||
dataframe["&s-exit_signal"] = np.where(
|
||||
future_min < dataframe["close"] * 0.99, # -1%阈值
|
||||
1, 0
|
||||
)
|
||||
```
|
||||
|
||||
### 2. ML审核官机制
|
||||
```python
|
||||
# 入场审核:基于FreqAI预测概率
|
||||
if entry_prob is not None:
|
||||
entry_prob = max(0.0, min(1.0, entry_prob)) # 确保概率在[0,1]范围内
|
||||
if entry_prob < self.ml_entry_signal_threshold.value:
|
||||
# 拒绝入场:上涨概率低,不宜入场
|
||||
allow_trade = False
|
||||
else:
|
||||
# 允许入场:上涨概率足够高
|
||||
allow_trade = True
|
||||
|
||||
# 出场审核:基于FreqAI预测概率
|
||||
if exit_prob is not None:
|
||||
exit_prob = max(0.0, min(1.0, exit_prob))
|
||||
if exit_prob < dynamic_threshold:
|
||||
allow_exit = False # 拒绝出场
|
||||
else:
|
||||
allow_exit = True # 允许出场
|
||||
```
|
||||
|
||||
## 🔄 入场流程
|
||||
|
||||
### 1. confirm_trade_entry 方法
|
||||
```python
|
||||
def confirm_trade_entry(self, ...):
|
||||
# 1. 冷启动保护(回测模式下禁用)
|
||||
# 2. 入场间隔控制
|
||||
# 3. 剧烈拉升检测
|
||||
# 4. ML审核官(FreqAI过滤低质量入场)
|
||||
# 5. 最终决定是否允许入场
|
||||
```
|
||||
|
||||
### 2. 入场信号生成
|
||||
```python
|
||||
# 在populate_entry_trend中
|
||||
dataframe.loc[final_condition, 'enter_long'] = 1
|
||||
```
|
||||
|
||||
## 📤 出场流程
|
||||
|
||||
### 1. confirm_trade_exit 方法
|
||||
```python
|
||||
def confirm_trade_exit(self, ...):
|
||||
# 1. 风险控制类退出(止损、追踪止损等)- 直接允许
|
||||
# 2. ML审核官(FreqAI过滤低质量出场)
|
||||
# 3. 特殊退出条件:
|
||||
# - EMA20趋势变弱时强制退出
|
||||
# - AI预测震荡市时强制退出
|
||||
# 4. 最终决定是否允许出场
|
||||
```
|
||||
|
||||
### 2. 特殊退出机制
|
||||
```python
|
||||
# EMA20趋势变弱时提前退出
|
||||
if self.is_ema20_trend_weakening(df):
|
||||
return True # 强制出场
|
||||
|
||||
# AI预测震荡市时强制退出
|
||||
elif future_vol_signal < 0.35:
|
||||
return True # 强制出场
|
||||
```
|
||||
|
||||
## 📈 策略特点
|
||||
|
||||
### ✅ 优势
|
||||
1. **多维度过滤**:技术指标+机器学习双重验证
|
||||
2. **趋势强度控制**:避免在趋势不明确时入场
|
||||
3. **智能退出机制**:基于趋势变化和AI预测的动态退出
|
||||
4. **回测友好**:符合看前偏差修复要求,回测结果更真实
|
||||
|
||||
### ✅ 风险控制
|
||||
1. **冷启动保护**:策略启动初期不入场
|
||||
2. **入场间隔控制**:避免频繁交易
|
||||
3. **ML审核官**:过滤低质量信号
|
||||
4. **动态止损**:基于ATR的动态止损
|
||||
|
||||
### ✅ 适应性
|
||||
1. **参数优化**:大量可调参数支持个性化优化
|
||||
2. **多时间框架**:3m/15m/1h多周期分析
|
||||
3. **市场状态识别**:根据市场状态调整策略参数
|
||||
|
||||
## 📊 策略执行流程图
|
||||
|
||||
```
|
||||
开始
|
||||
↓
|
||||
技术指标分析(EMA、RSI、MACD等)
|
||||
↓
|
||||
趋势过滤(EMA5/EMA20、趋势强度)
|
||||
↓
|
||||
多因子综合筛选
|
||||
↓
|
||||
FreqAI智能决策(entry_signal概率)
|
||||
↓
|
||||
ML审核官过滤
|
||||
↓
|
||||
确认入场/拒绝入场
|
||||
↓
|
||||
持仓中...
|
||||
↓
|
||||
实时监控(趋势变化、AI预测)
|
||||
↓
|
||||
智能退出(趋势变弱、震荡市)
|
||||
↓
|
||||
结束
|
||||
```
|
||||
|
||||
这个策略结合了传统技术分析的可靠性与机器学习的智能性,能够在不同市场环境下做出相对稳健的交易决策。
|
||||
@ -933,12 +933,12 @@ class FreqaiPrimer(IStrategy):
|
||||
|
||||
# 检查2:检查是否处于剧烈拉升的不稳固区域
|
||||
unstable_rejected = False
|
||||
if not cold_start_rejected and not interval_rejected:
|
||||
is_unstable_region = self.detect_h1_rapid_rise(pair)
|
||||
if is_unstable_region:
|
||||
rejected_conditions.append("剧烈拉升检测: 检测到1小时图剧烈拉升")
|
||||
self.strategy_log(f"[{pair}] {rejected_conditions[-1]}")
|
||||
unstable_rejected = True
|
||||
# if not cold_start_rejected and not interval_rejected:
|
||||
# is_unstable_region = self.detect_h1_rapid_rise(pair)
|
||||
# if is_unstable_region:
|
||||
# rejected_conditions.append("剧烈拉升检测: 检测到1小时图剧烈拉升")
|
||||
# self.strategy_log(f"[{pair}] {rejected_conditions[-1]}")
|
||||
# unstable_rejected = True
|
||||
|
||||
# 检查3:ML 审核官(FreqAI 过滤低质量入场)+ 入场诊断统计
|
||||
# 逻辑:用 entry_signal 概率来判断——若"容易上涨概率"低,则拒绝入场
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user