Files
Hermes-Skills/okx-auto-position/references/tp-sl-strategy.md
T
mike 657dc41c46 Initial commit: Trading skills collection
- OKX交易自动化 (okx-auto-position, okx-crypto, okx-exchange)
- 交易信号处理 (signal-confirmation-templates, trading-signal-aggregator)
- 量化因子挖掘 (quant-factor-mining)
- 长桥集成 (longbridge-cli, longbridge-python-sdk)
- 六合彩分析 (lottery-hk)
- 股息投资 (dividend-investing, dividend-scanner)
- 日内交易 (intraday-trading)
- 同花顺 (tonghuashun)
2026-07-05 02:39:41 -04:00

72 lines
2.3 KiB
Markdown
Raw 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.
# A+E+D 止盈止损策略
三合一套餐:多周期ATR融合(A) + 跟踪止损(E) + 自适应盈亏比(D)
## 第一层:入场止损 — 多周期ATR融合 (A)
```
SL距离 = (ATR_1H × 0.5 + ATR_4H × 0.3 + ATR_1D × 0.2) × 1.5
做多: SL = 入场价 - SL距离
做空: SL = 入场价 + SL距离
```
**为什么用多周期:** 1H(50%)应对短期波动,4H(30%)做主心骨,1D(20%)兜底。避免单根4H大K线拉偏ATR导致止损过宽。
## 第二层:跟踪止损 (E) — 持仓后动态调整
```
阶段1:初始SL = 第一层的SL距离
阶段2:浮盈 > ATR融合×1.0 → SL移到入场±ATR融合×0.3(保本)
阶段3:浮盈 > ATR融合×2.0 → SL跟踪,跟踪距离=ATR融合×1.2
```
实现方式:trading cron 定时轮询(15min间隔),reduceOnly模式。
## 第三层:自适应盈亏比 (D)
趋势强度判断(EMA12-EMA26斜率):
| 斜率 | 趋势 | R:R | 策略 |
|------|------|:---:|------|
| > +0.5 | strong_up | 3.0 | 强趋势多拿一会 |
| < -0.5 | strong_down | 3.0 | 强趋势多拿一会 |
| \|slope\| < 0.1 | ranging | 1.5 | 震荡见好就收 |
| 其他 | weak_trend | 2.0 | 正常 |
## 完整流程
```python
def calc_tp_sl(entry, side, exchange, symbol):
# A: 多周期ATR
fused, _, _, _ = calc_multi_atr(exchange, symbol)
sl_distance = fused if fused else entry * 0.03
# D: 自适应R:R
trend, slope = estimate_trend_strength(exchange, symbol)
rr = {'strong_up':3.0,'strong_down':3.0,'ranging':1.5}.get(trend, 2.0)
if side == 'sell':
sl = entry + sl_distance
tp = entry - sl_distance * rr
else:
sl = entry - sl_distance
tp = entry + sl_distance * rr
return tp, sl, rr, trend
# E: 跟踪止损(持仓后循环执行)
def update_trail(entry, current, side, fused):
upl = abs(current - entry) # 每张
if upl > fused * 2.0: # 阶段3
trail = fused * 1.2
return current - trail if side == 'buy' else current + trail
if upl > fused * 1.0: # 阶段2
return entry + fused * 0.3 if side == 'sell' else entry - fused * 0.3
return None # 保持初始SL
```
## 参数调整
- **高波动币种** (ATR% > 5%):×1.5 → ×2.0
- **低波动币种** (ATR% < 1%):×1.5 → ×1.0
- **数据不足**:退回到单4H ATR×1.5