# Strategies Spec

## Strategy functions

Each strategy is a function in `strategies.py`:

```python
def strategy_name(df: pd.DataFrame, params: dict, idx: int) -> dict:
    return {'signal': 'CALL' | 'PUT' | None, 'confidence': 0-100, 'reason': str}
```

**No look-ahead**: `idx` is current candle. Future data (idx+1) never accessed.

## 1. EMA+RSI Trend («Трендовый импульс»)

**Logic:** EMA9/EMA21 crossover with RSI(14) momentum zone filter.

- CALL: EMA9 crosses above EMA21 AND price > both EMAs AND 50 < RSI < 70
- PUT: EMA9 crosses below EMA21 AND price < both EMAs AND 30 < RSI < 50
- Avoid: RSI > 75 or < 25 (exhausted moves)
- Confidence: based on RSI distance from 50

**Rationale:** Captures trend continuation with confirmed momentum. RSI 50-70 zone shows impulse without exhaustion. Works best for EUR/USD during London/NY sessions, for BTC watch for RSI extremes.

## 2. BB+Price Action («Отскок от границ»)

**Logic:** Bollinger Bands(20,2) mean reversion with candlestick pattern confirmation.

- CALL: price touched BB_lower + bullish pattern (pin bar / hammer / engulfing) + candle closes up
- PUT: price touched BB_upper + bearish pattern (shooting star / bear engulfing) + candle closes down
- Pin bar detection: lower/upper shadow > 60% of candle range
- Confidence: 70 (confirmed patterns)

**Rationale:** H1 candles respect BB as dynamic S/R. Candle patterns at extremes filter false breakouts. Avoid during strong news events. For BTC, wait for candle close to confirm.

## 3. RSI Divergence («Дивергенция на ключевых уровнях»)

**Logic:** RSI(14) divergence at 20-bar horizontal support/resistance.

- CALL: price at support + RSI bullish divergence (lower price low + higher RSI low, RSI < 50)
- PUT: price at resistance + RSI bearish divergence (higher price high + lower RSI high, RSI > 50)
- Entry: open of next candle after divergence confirmation
- Confidence: 75

**Rationale:** Divergence at S/R is one of the most reliable H1 reversal signals. EUR/USD levels work precisely. BTC: use zones, not exact lines; confirm divergence at bar close.

## 4. MACD+Stochastic («Двойной фильтр тренда»)

**Logic:** MACD trend direction + Stochastic(5,3,3) entry timing.

- CALL: MACD_hist > 0 (uptrend) AND Stoch crosses up from oversold (<20)
- PUT: MACD_hist < 0 (downtrend) AND Stoch crosses down from overbought (>80)
- Confidence: based on Stoch depth in OV/OS zone

**Rationale:** MACD filters trend direction, Stoch times the entry on pullbacks. Excellent for EUR/USD in calm markets. For BTC, MACD may lag — prioritize clear Stoch crossover from extremes.

## 5. Breakout+Retest («Пробой и ретест»)

**Logic:** Pure price action — breakout of S/R with retest and bounce confirmation.

- CALL: strong bull candle breaks above 20-bar resistance → price retests the level → forms bullish bounce candle (body up or long lower wick)
- PUT: strong bear candle breaks below 20-bar support → retest → bearish rejection candle
- Strong candle: body > 60% of range
- Confidence: 65

**Rationale:** Breakout-retest pattern has high win rate on H1. EUR/USD retests typically within 1-2 hours. BTC breakouts can be violent with deep retests — consider 2h expiry to let price breathe.

## Strategy registration

```python
STRATEGIES = {
    'ema_rsi_trend': ema_rsi_trend,
    'bb_pa': bb_pa,
    'rsi_divergence': rsi_divergence,
    'macd_stoch': macd_stoch,
    'breakout_retest': breakout_retest,
}
```
