Refactor BTC1h strategy: EMA crossover trend-following

Replaced pullback strategy with EMA 12/26 crossover on 1h, filtered by 4h EMA50
uptrend and 1h EMA200. Exits via bearish cross or trailing stop.

Dec 2025-May 2026 backtest: +1.89 USDT (+0.19%), 27 trades, 37% win rate,
0.29% max drawdown, while BTC dropped 6.7%.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
jackyu66git
2026-05-07 15:30:05 +08:00
co-authored by Claude Opus 4.7
parent 88e3bf8584
commit 2bd338ad47
2 changed files with 66 additions and 99 deletions
+29 -32
View File
@@ -4,49 +4,42 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Project Overview
Freqtrade BTC 1h trading bot. Strategy buys BTC/USDT pullbacks in uptrends using EMA, RSI, and MACD signals on the 1-hour timeframe, with a 4h trend filter.
Freqtrade BTC/USDT bot on the 1h timeframe. Uses EMA crossover trend-following with 4h trend filter and trailing stop exits.
## File Structure
```
├── docker-compose.yml # Defines freqtrade + download-data services
├── config.json # Exchange, pairs, stake, API server settings
├── docker-compose.yml # freqtrade + download-data services
├── config.json # Exchange, pairs, stake, API server
├── CLAUDE.md
└── user_data/
── strategies/
── BTC_1h.py # The trading strategy class
── strategies/
── BTC_1h.py # EMA crossover strategy
│ └── TrendStructureExecutor.py # 5m trend-continuation strategy
├── data/ # Downloaded OHLCV data (gitignored)
└── backtest_results/ # Backtest results (gitignored)
```
## Commands
### Start trading (dry-run, default)
### Download data
```bash
docker compose up -d
```
### Start live trading (after configuring API keys in config.json)
```bash
docker compose up -d
```
### Download historical data
```bash
docker compose run --rm download-data
```
### Download data for custom pairs/timeframes
```bash
docker compose run --rm freqtrade download-data --exchange binance --pairs BTC/USDT ETH/USDT --timeframe 1h 4h --days 365
docker compose run --rm freqtrade download-data --exchange binance --pairs BTC/USDT --timeframe 1h 4h --days 400
```
### Backtest
```bash
docker compose run --rm freqtrade backtesting --strategy BTC1h --timeframe 1h
docker compose run --rm freqtrade backtesting --strategy BTC1h --timeframe 1h --timerange 20251201-
```
### Hyperopt
```bash
docker compose run --rm freqtrade hyperopt --strategy BTC1h --timeframe 1h --epochs 200 --spaces buy sell roi stoploss
docker compose run --rm freqtrade hyperopt --strategy BTC1h --timeframe 1h --epochs 500 --spaces buy sell stoploss
```
### Start live/dry-run
```bash
docker compose up -d
```
### View logs
@@ -61,14 +54,18 @@ docker compose down
## Configuration Notes
- Dry-run is enabled by default (`dry_run: true`). Set to `false` and add exchange API key/secret to trade live.
- The API server runs on `127.0.0.1:8080` (not exposed externally).
- Data persists in `user_data/` across container restarts.
- Update `pair_whitelist` in `config.json` to trade additional pairs.
- Dry-run is enabled by default (`dry_run: true`). Set to `false` and add exchange API key/secret to `exchange.key` / `exchange.secret` to trade live.
- The API server runs on `127.0.0.1:8080`. Default credentials: `freqtrader` / `changeme`.
- Data and backtest results persist in `user_data/` across restarts.
## Strategy (BTC1h)
- **Timeframe**: 1h with 4h trend filter
- **Entry**: 4h bullish + pullback to short EMA + RSI dip + MACD turning up + volume confirmation
- **Exit**: RSI overbought or MACD bearish cross
- **Hyperoptable**: EMA periods, RSI thresholds
| Aspect | Detail |
|--------|--------|
| **Type** | Trend-following EMA crossover |
| **Entry** | 4h price > EMA50 + 1h price > EMA200 + 12 EMA crosses above 26 EMA |
| **Exit** | 12 EMA crosses below 26 EMA, or trailing stop at +1% after +2.5% peak |
| **Stop** | -2.5% fixed |
| **Performance** | +1.89 USDT in 157 days (BTC dropped 6.7%). 27 trades, 37% win rate, 0.29% drawdown. Winners avg +2.48%, losers avg -1.24%. |
The strategy is asymmetric: it wins big (trailing stop at +2.48% avg on 37% of trades) and loses small (exit signal at -1.24% avg on 63%). It loses on most trades but profits overall.