Files
Hermes-Skills/trading/okx-auto-position/references/trend-analysis.md
T
Hermes Skills Manager 6770bc9b9d Initial commit: Hermes Agent skills collection
- Trading skills (OKX, dividend, lottery, quantitative)
- Creative skills (ASCII art, diagrams, video)
- Development skills (GitHub, debugging, TDD)
- Research skills (arXiv, blog monitoring)
- Productivity skills (email, documents, notes)
- MCP integration skills
- Custom user skills
2026-07-05 02:31:15 -04:00

2.0 KiB

Trend Analysis for Position Decisions

Use EMA12/EMA26 slope on 4H candles to determine if position direction is correct.

Algorithm

def calc_ema(closes, period):
    if len(closes) < period:
        return closes[-1]
    multiplier = 2 / (period + 1)
    ema = closes[0]
    for price in closes[1:]:
        ema = (price - ema) * multiplier + ema
    return ema

def analyze_trend(inst_id):
    # Get 4H candles
    candles = get_candles(inst_id, "4H", 30)
    closes = [c.close for c in candles]
    
    ema12 = calc_ema(closes[-12:], 12)
    ema26 = calc_ema(closes[-26:], 26)
    
    slope = (ema12 - ema26) / ema26 * 100
    
    if slope > 0.5:      return 'strong_up'
    if slope < -0.5:     return 'strong_down'
    if abs(slope) < 0.1: return 'ranging'
    return 'weak_trend'

Position Decision Rules

趋势 做多持仓 做空持仓
strong_up 持有 平仓
weak_up 持有 ⚠️ 观察
ranging ⚠️ 观察 ⚠️ 观察
weak_down ⚠️ 观察 持有
strong_down 平仓 持有

Decision Flow

信号/定期检查
  ↓
分析趋势 (EMA12 vs EMA26)
  ↓
├─ 趋势正确 + 保证金充足 → 加仓
├─ 趋势正确 + 保证金不足 → 持有
├─ 趋势错误 → 平仓
└─ 无趋势 → 观察或平仓

Real Example (2026-07-02)

币种 方向 EMA12 EMA26 斜率 趋势 决定
ETH 🟩 1646.37 1616.26 +1.86% strong_up 持有
BTC 🟥 60567 60090 +0.79% strong_up 平仓
SNDK 🟩 1961.92 2029.02 -3.31% strong_down 平仓
SKHYNIX 🟩 1513.35 1605.48 -5.74% strong_down 平仓
MU 🟩 1032.60 1075.03 -3.95% strong_down 平仓
HYPE 🟥 64.90 64.29 +0.96% strong_up 平仓
SOL 🟥 78.81 76.28 +3.31% strong_up 平仓

Result: Closed 6 incorrect positions, kept ETH (trend correct).