# AGENTS.md

## Overview
Binary options strategy development system for H1 timeframe: backtesting engine, strategy library, and neural network signal classifier. Instruments: BITCOIN, EURUSD. Data source: MySQL.

## Project workflow

```
1. Fetch data      → python main.py --fetch    (MySQL → data/{INSTR}_H1_indicators.csv)
2. Backtest        → python main.py --test     (run all 5 strategies, save results)
3. Filter          → python main.py --best     (show profitable strategies)
4. Detail          → python main.py --report X (deep-dive into one strategy)
5. ML training     → (future: NN on strategy signals)
```

## Entrypoint
`main.py` — single CLI with subcommands:
- `--fetch` — download H1 OHLCV from DB, compute indicators, save CSV
- `--test` — backtest all 5 strategies on cached CSV data, export JSON results
- `--best` — show strategies that pass win_rate/pf/trade_count thresholds
- `--report KEY` — detailed stats for specific strategy (e.g. `BITCOIN_ema_rsi_trend`)

## 5 Strategies

| # | Strategy | Logic | Indicators |
|---|----------|-------|------------|
| 1 | EMA+RSI Trend | EMA9/21 cross + RSI 30-70 zone + price vs EMA | EMA, RSI |
| 2 | BB+Price Action | BB touch + pin bar/engulfing + direction confirm | BB(20,2), candle patterns |
| 3 | RSI Divergence | RSI divergence at 20-bar S/R levels | RSI(14), S/R levels |
| 4 | MACD+Stochastic | MACD trend filter + Stoch(5,3,3) entry from OV/OS | MACD, Stochastic |
| 5 | Breakout+Retest | Breakout of S/R + retest + bounce candle (no indicators) | Price action, S/R levels |

## Architecture
- `config.py` — DB, params, paths, backtest config
- `data_fetcher.py` — MySQL H1 data fetch
- `indicators.py` — TA-Lib wrappers (EMA, RSI, MACD, BB, ATR, ADX, Stoch, CCI, patterns)
- `strategies.py` — 5 strategy functions: each returns `{signal, confidence, reason}`
- `tester.py` — backtesting engine: equity curve, win rate, profit factor, max DD
- `main.py` — CLI router

## Database
MySQL at `nlbotinterface.ru:3306`, DB `bitcoin_tickers`. Tables: `BITCOIN_H1`, `EURUSD_H1`. Credentials via `.env`.

## Dependencies
- `mysql.connector`
- `talib`
- `numpy`, `pandas`
- `python-dotenv`

## Backtest parameters
- Trade amount: $100 fixed
- Payout: 80%
- Filter thresholds: win_rate ≥ 55%, profit_factor ≥ 0.8, min 50 trades

## Conventions
- Each strategy function receives DataFrame + params dict + index → returns signal dict
- Signal dict: `{'signal': 'CALL'/'PUT'/None, 'confidence': 0-100, 'reason': str}`
- Future close used only for win/loss check (no look-ahead bias in signal logic)
- All indicators computed upfront once, stored in CSV cache
