myTestFreqAI/protection_config_guide.md
zhangkun9038@dingtalk.com 0207db2da5 protections config
2025-08-21 00:28:34 +08:00

97 lines
3.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Freqtrade 保护机制配置指南2024年更新版
## 概述
本指南说明如何在Freqtrade 2024年最新版本中正确配置保护机制以防止连续亏损和情绪化交易。
## ⚠️ 重要更新
**从2024年开始保护机制配置方式已变更**
-**弃用**:在配置文件中设置`protections`属性
-**新方式**:在策略文件中使用`@property def protections`方法定义
## 当前配置方式
### 配置位置
保护机制现在需要在策略文件(`freqaiprimer.py`)中通过`@property def protections`方法定义。
### 已添加的保护机制
#### 1. StoplossGuard止损保护
**作用**:防止在短时间内出现过多止损交易
**配置参数**
- `method`: "StoplossGuard"
- `lookback_period_candles`: 6060根3分钟K线 = 3小时
- `trade_limit`: 2最多2笔止损交易
- `stop_duration_candles`: 60暂停60根3分钟K线 = 180分钟
- `only_per_pair`: true仅针对单个币对
#### 2. CooldownPeriod冷却期
**作用**:防止过度频繁交易
**配置参数**
- `method`: "CooldownPeriod"
- `stop_duration_candles`: 22根3分钟K线 = 6分钟冷却期
#### 3. MaxDrawdown最大回撤
**作用**:限制账户最大回撤,保护资金安全
**配置参数**
- `method`: "MaxDrawdown"
- `lookback_period_candles`: 4848根3分钟K线 = 2.4小时)
- `trade_limit`: 44笔交易限制
- `stop_duration_candles`: 24暂停24根3分钟K线 = 72分钟
- `max_allowed_drawdown`: 0.2020%最大回撤容忍度)
## 配置代码位置
```python
# 在策略类中添加以下代码
@property
def protections(self):
return [
{
"method": "StoplossGuard",
"lookback_period_candles": 60,
"trade_limit": 2,
"stop_duration_candles": 60,
"only_per_pair": True
},
{
"method": "CooldownPeriod",
"stop_duration_candles": 2
},
{
"method": "MaxDrawdown",
"lookback_period_candles": 48,
"trade_limit": 4,
"stop_duration_candles": 24,
"max_allowed_drawdown": 0.20
}
]
```
## 工作原理
1. **StoplossGuard**: 在3小时内如果单个币对出现2笔或更多止损交易将暂停该币对交易180分钟
2. **CooldownPeriod**: 每笔交易完成后强制等待6分钟才能进行下一笔交易
3. **MaxDrawdown**: 在2.4小时内如果账户回撤达到20%将暂停所有交易72分钟
## 迁移步骤
1.**配置文件**:已从`freqaiprimer.json`中移除`protections`配置
2.**策略文件**:已在`freqaiprimer.py`中添加`@property def protections`方法
3.**参数优化**根据3分钟K线交易特点调整时间参数
## 预期效果
- 减少连续亏损风险
- 防止情绪化交易
- 保护账户资金安全
- 维持合理的交易频率
- 避免配置文件弃用错误
## 验证方法
启动策略后,查看日志应显示:
```
freqtrade.plugins.protectionmanager - INFO - Loaded 3 protection handlers
```
## 故障排除
如果看到错误:
```
Configuration error: DEPRECATED: Setting 'protections' in the configuration is deprecated
```
**解决方案**:确保已从配置文件中移除`protections`配置,并在策略文件中添加`@property def protections`方法。