mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-06 04:20:59 +08:00
fix(prompts): add explicit stop-loss direction logic for long/short positions
Address DaDaManMan's error where AI set stop-loss incorrectly for short position. ## Problem AI attempted to set stop-loss at $107,500 for SHORT position at $108,230, causing validation error: "空单止损必须高于当前价格" Root cause: Prompts lacked explicit guidance on stop-loss direction logic. ## Solution ### adaptive.txt (Chinese): - Add "止损方向逻辑" section with clear rules - Long position: stop_loss < entry_price (protect downside) - Short position: stop_loss > entry_price (protect upside) - Include examples and common mistakes to avoid ### nof1.txt (English): - Add "Stop-Loss Direction Logic" section - Same directional rules with detailed explanations - Include real error example from production logs - Emphasize validation failures when rules are violated ## Impact - ✅ Prevents AI from setting illogical stop-loss prices - ✅ Reduces validation errors and failed trades - ✅ Provides clear examples with entry/stop-loss pairs - ✅ Addresses DaDaManMan's reported issue directly ## Files Changed - prompts/adaptive.txt (+19 lines) - prompts/nof1.txt (+25 lines) Fixes: #272 (DaDaManMan's comment) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -139,6 +139,24 @@
|
||||
- `partial_close` 用于锁定阶段性收益或降低风险,建议使用清晰比例(如 25% / 50% / 75%),并说明目的(例:"锁定关键阻力前利润""减半仓等待回踩确认")。
|
||||
- 执行部分平仓后,应评估是否需要同步上调止损 / 下调止盈,确保剩余仓位符合新的风险回报结构。
|
||||
- `update_stop_loss` / `update_take_profit` 优先用于顺势推进(如跟踪新高新低),避免在无新证据下放宽止损。
|
||||
|
||||
## ⚠️ 止损方向逻辑(关键规则)
|
||||
|
||||
**多单 (Long Position):**
|
||||
- 止损价格必须 **低于** 入场价格(`stop_loss < entry_price`)
|
||||
- 原因:保护下跌风险,价格跌破止损时自动平仓
|
||||
- 示例:入场 $100,止损 $95(亏损 5%)
|
||||
|
||||
**空单 (Short Position):**
|
||||
- 止损价格必须 **高于** 入场价格(`stop_loss > entry_price`)
|
||||
- 原因:保护上涨风险,价格涨破止损时自动平仓
|
||||
- 示例:入场 $100,止损 $105(亏损 5%)
|
||||
|
||||
**常见错误(务必避免):**
|
||||
- ❌ 空单设置 `stop_loss < entry_price`(错误!会导致验证失败)
|
||||
- ❌ 多单设置 `stop_loss > entry_price`(错误!会导致无保护)
|
||||
- ✅ 使用 `update_stop_loss` 调整时,同样遵循上述方向规则
|
||||
|
||||
- 若计划分批退出,请在 `reasoning` 中描述剩余仓位的策略与失效条件,避免出现"减仓后不知道如何处理剩余部位"的情况。
|
||||
|
||||
---
|
||||
|
||||
@@ -72,6 +72,31 @@ You can issue the following actions each decision cycle:
|
||||
- ✅ Locking in profits as position moves in your favor
|
||||
- ❌ NOT for widening stops without new evidence (don't move stops against you)
|
||||
|
||||
## ⚠️ Stop-Loss Direction Logic (Critical Rule)
|
||||
|
||||
**Long Position:**
|
||||
- Stop-loss MUST be **below** entry price (`stop_loss < entry_price`)
|
||||
- Reason: Protects against downside risk, exits when price drops below threshold
|
||||
- Example: Entry $100, stop-loss $95 (5% loss protection)
|
||||
|
||||
**Short Position:**
|
||||
- Stop-loss MUST be **above** entry price (`stop_loss > entry_price`)
|
||||
- Reason: Protects against upside risk, exits when price rises above threshold
|
||||
- Example: Entry $100, stop-loss $105 (5% loss protection)
|
||||
|
||||
**Common Mistakes (Must Avoid):**
|
||||
- ❌ Short position with `stop_loss < entry_price` (WRONG! Causes validation failure)
|
||||
- ❌ Long position with `stop_loss > entry_price` (WRONG! No protection)
|
||||
- ✅ When using `update_stop_loss`, follow the same directional rules above
|
||||
|
||||
**Real Example from Error Log:**
|
||||
```
|
||||
Position: SHORT BTCUSDT at $108,230
|
||||
AI attempted: stop_loss = $107,500 (WRONG! Below entry)
|
||||
Correct: stop_loss should be > $108,230 (e.g., $109,000)
|
||||
Error: "空单止损必须高于当前价格"
|
||||
```
|
||||
|
||||
## Multi-Stage Exit Strategy
|
||||
|
||||
When planning phased exits (partial closes):
|
||||
|
||||
Reference in New Issue
Block a user