feat: 添加部分平仓和动态止盈止损功能

新增功能:
- update_stop_loss: 调整止损价格(追踪止损)
- update_take_profit: 调整止盈价格(技术位优化)
- partial_close: 部分平仓(分批止盈)

实现细节:
- Decision struct 新增字段:NewStopLoss, NewTakeProfit, ClosePercentage
- 新增执行函数:executeUpdateStopLossWithRecord, executeUpdateTakeProfitWithRecord, executePartialCloseWithRecord
- 修复持仓字段获取 bug(使用 "side" 并转大写)
- 更新 adaptive.txt 文档,包含详细使用示例和策略建议
- 优先级排序:平仓 > 调整止盈止损 > 开仓

命名统一:
- 与社区 PR #197 保持一致,使用 update_* 而非 adjust_*
- 独有功能:partial_close(部分平仓)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
ZhouYongyou
2025-11-02 05:32:23 +08:00
parent 093d521394
commit 82660b12c5
3 changed files with 292 additions and 7 deletions

View File

@@ -237,13 +237,97 @@
关键: 夏普比率是唯一指标,它会自然惩罚频繁交易和过度进出。
# 动态止盈止损功能
你现在可以在持仓中主动调整止盈止损,实现追踪止损和分批止盈策略。
## 可用的新 Actions
### 1. update_stop_loss - 调整止损
用于实现追踪止损,保护利润。
示例场景:
- 开仓 BTC @ 100,000止损 99,000 (-1%)
- 价格上涨到 101,500 (+1.5%)
- 决策:将止损移到成本价 100,500锁定利润
JSON 格式:
```json
{
"symbol": "BTCUSDT",
"action": "update_stop_loss",
"new_stop_loss": 100500.0,
"confidence": 90,
"reasoning": "浮盈达到 1.5%,将止损移到成本价保证不亏"
}
```
### 2. update_take_profit - 调整止盈
用于在技术位前提前止盈,避免回撤。
示例场景:
- 持仓 BTC @ 100,000原止盈 102,000 (+2%)
- 15m EMA20 位于 101,800强压力位
- 价格到 101,700距离 EMA20 仅 0.1%
- 决策:将止盈调整到 101,750避免在技术位回撤
JSON 格式:
```json
{
"symbol": "BTCUSDT",
"action": "update_take_profit",
"new_take_profit": 101750.0,
"confidence": 85,
"reasoning": "价格接近 EMA20 压力位,提前止盈避免回撤"
}
```
### 3. partial_close - 部分平仓
用于分批止盈,既锁定部分利润,又保留追涨空间。
示例场景:
- 持仓 BTC 0.1 @ 100,000
- 价格到达第一目标 104,000 (+4%)
- 决策:平仓 50%,剩余继续持有追第二目标
JSON 格式:
```json
{
"symbol": "BTCUSDT",
"action": "partial_close",
"close_percentage": 50,
"confidence": 80,
"reasoning": "价格到达第一目标,分批平仓 50%,剩余持仓继续追踪"
}
```
## 使用建议
追踪止损策略(震荡市):
- 浮盈达到 0.8% → update_stop_loss 移到成本价
- 浮盈达到 1.2% → update_stop_loss 移到 +0.5%
- 价格距离技术位 < 0.3% → update_take_profit 或直接 close
分批止盈策略(趋势市):
- 第一目标(+4%)→ partial_close 50%
- 第二目标(+8%)→ partial_close 剩余的 50%(即总仓位的 25%
- 最后 25% 继续追踪,用 update_stop_loss 保护利润
技术位止盈优化:
- 当价格接近关键技术位EMA20、前高、整数关口
- 使用 update_take_profit 将止盈设在技术位前 0.1-0.2%
- 避免在技术位遇阻回撤
# 决策流程
1. 分析夏普比率: 当前策略是否有效?需要调整吗?
2. 判断市场状态: 震荡还是趋势?(多指标验证)
3. 选择对应策略: 策略A震荡还是策略B趋势
4. 评估持仓: 趋势是否改变?是否该止盈/止损?
5. 识别技术位: 上方压力、下方支撑在哪里?
4. 评估持仓: 趋势是否改变?是否该止盈/止损?需要调整止损保护利润吗?
5. 识别技术位: 上方压力、下方支撑在哪里?是否需要提前止盈?
6. 寻找新机会: 有强信号吗?技术位明确吗?
7. 计算止盈止损: 技术位优先,还是固定百分比?
8. 输出决策: 思维链分析 + JSON