https://github.com/trsdn/meta-strategy
https://github.com/trsdn/meta-strategy
ai-scrum algorithmic-trading backtesting bitcoin bollinger-bands crypto pine-script python quantitative-finance strategy supertrend trading tradingview
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/trsdn/meta-strategy
- Owner: trsdn
- License: mit
- Created: 2026-02-13T12:29:38.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-02-13T20:22:42.000Z (3 months ago)
- Last Synced: 2026-02-13T21:37:34.716Z (3 months ago)
- Topics: ai-scrum, algorithmic-trading, backtesting, bitcoin, bollinger-bands, crypto, pine-script, python, quantitative-finance, strategy, supertrend, trading, tradingview
- Language: Python
- Size: 479 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
- Agents: AGENTS.md
Awesome Lists containing this project
README
# Meta Strategy
[](https://github.com/trsdn/meta-strategy/actions/workflows/ci.yml)
[](https://github.com/trsdn/meta-strategy/releases/tag/v1.0.0)
[](https://www.python.org)
[](LICENSE)
[](tests/)
[](pyproject.toml)
[](https://trsdn.github.io/ai-scrum/)
> 🤖 **Built by using [AI Scrum](https://trsdn.github.io/ai-scrum/)** — autonomous AI-driven development with structured sprints, quality gates, and continuous delivery.
> 📊 **[View the Strategy Validation Report](docs/validation-report.html)** — backtested results with equity curves, trade lists, and statistical significance tests.
> 🎬 **Based on:** [Convert TradingView Indicators into Strategies with AI](https://www.youtube.com/watch?v=ETuIpsL_7Mc) by Michael Automates
AI-powered TradingView indicator-to-strategy converter with a full local backtesting engine. Translates Pine Script indicators into backtestable strategies, runs them locally on real market data, and provides optimization, risk analysis, and reporting tools.
## What This Does
TradingView **indicators** show signals on a chart but can't be backtested. TradingView **strategies** can be backtested (Win Rate, Profit Factor, Drawdown). This tool:
1. **Converts** indicators → strategies via structured AI prompts
2. **Backtests** strategies locally with real market data (no TradingView needed)
3. **Optimizes** parameters via grid search with train/test split
4. **Validates** walk-forward with rolling/expanding windows and overfitting detection
5. **Analyzes** risk with Monte Carlo simulation and extended metrics
6. **Reports** results as HTML dashboards, CSV, or JSON
## Strategy Catalog
All 6 strategies have YAML definitions, indicator sources, and generated AI prompts.
| Strategy | Entry | Exit |
|----------|-------|------|
| **Bollinger Bands** | Close > Upper Band (breakout) | Close < Lower Band |
| **SuperTrend** | Direction flips to +1 (bullish) | Direction flips to -1 (bearish) |
| **Bull Market Support Band** | EMA > SMA crossover | SMA > EMA crossunder |
| **RSI** | RSI < 30 + above 200 SMA | RSI > 70 |
| **MACD** | MACD crosses above signal | MACD crosses below signal |
| **Confluence** | BB breakout + RSI < 70 + MACD > Signal | Close < BB lower OR RSI > 80 |
> **Note:** `backtest-all` normalizes Buy & Hold returns across strategies by accounting for indicator warmup periods. Use `--interval` to test on different timeframes (1h, 4h, 1d).
## Quick Start
```bash
# Install
uv sync --extra dev
# Run all backtests (daily candles, BTC-USD)
meta-strategy backtest-all
# Backtest on hourly candles
meta-strategy backtest bollinger-bands --symbol BTC-USD --interval 1h
# Optimize parameters with train/test split
meta-strategy optimize bollinger-bands --top 10 --split 0.7
# Walk-forward analysis (rolling windows)
meta-strategy walk-forward bollinger-bands --mode rolling --train-bars 500 --step 100
# Monte Carlo simulation
meta-strategy monte-carlo bollinger-bands --simulations 1000
# Extended risk metrics
meta-strategy risk-metrics bollinger-bands
# Multi-asset comparison
meta-strategy multi-asset bollinger-bands --symbols BTC-USD,ETH-USD,SPY
# Generate HTML dashboard
meta-strategy dashboard --output dashboard.html
# Export results
meta-strategy export --fmt json
meta-strategy export --fmt csv
```
## CLI Commands
| Command | Description |
|---------|-------------|
| `backtest` | Run backtest for a single strategy |
| `backtest-all` | Run all strategies with normalized B&H comparison |
| `multi-asset` | Run a strategy across multiple assets |
| `optimize` | Grid search with train/test split and overfitting detection |
| `walk-forward` | Walk-forward validation (sequential/rolling/expanding) |
| `monte-carlo` | Monte Carlo trade resampling simulation |
| `risk-metrics` | Extended risk metrics (Sortino, Calmar, etc.) |
| `report` | Generate HTML report with equity curve |
| `dashboard` | Generate comparison dashboard for all strategies |
| `export` | Export results to CSV or JSON |
| `generate` | Generate AI prompt from strategy definition |
| `validate` | Validate a YAML strategy definition |
| `validate-pine` | Validate Pine Script for common pitfalls |
| `list` | List available strategy definitions |
### Key Options
| Option | Available On | Description |
|--------|-------------|-------------|
| `--interval` | backtest, backtest-all, optimize, walk-forward | Candle interval: 1h, 4h, 1d (default: 1d) |
| `--split` | optimize | Train/test split ratio (default: 0.7) |
| `--mode` | walk-forward | Window mode: sequential, rolling, expanding |
| `--cash` | all backtest commands | Initial capital (default: $100k) |
## Development
```bash
uv run pytest tests/ -v # Run tests (85+ tests)
uv run ruff check src/ # Lint
uv run ruff format src/ # Format
uv run mypy src/ # Type check
```
## Project Structure
```
├── src/meta_strategy/
│ ├── backtest.py # 6 strategy classes, indicators, optimization, walk-forward
│ ├── reports.py # HTML reports, SVG equity charts, CSV/JSON export
│ ├── risk.py # Monte Carlo simulation, extended risk metrics
│ ├── models.py # StrategyDefinition Pydantic model
│ ├── engine.py # Prompt template engine
│ ├── validator.py # Pine Script pitfall validator
│ └── cli.py # Typer CLI (14 commands)
├── strategies/
│ ├── definitions/ # 6 YAML strategy definitions
│ ├── indicators/ # 6 Pine Script indicator sources
│ └── ai-*.pine # Generated AI conversion prompts
├── tests/ # 85+ tests
└── docs/
├── sprints/ # Sprint logs and velocity tracking
└── architecture/ # ADRs
```
## Limitations
- **Not a substitute for TradingView backtesting.** Local backtests use `backtesting.py` with yfinance data. Fill logic, slippage, and commission handling differ from TradingView's engine. Results are directionally useful but not identical.
- **No slippage modeling.** All trades fill at the next bar's open price. Real-world slippage on volatile assets (especially crypto) can significantly reduce returns.
- **Commission approximation.** Default 0.1% per trade. Actual exchange fees vary by platform and volume tier.
- **Sub-daily data limited to ~730 days** (yfinance constraint). Daily candles have no lookback limit.
- **BMSB on sub-daily timeframes** uses simulated weekly moving averages from daily-equivalent rolling windows, which may not match TradingView's `request.security()` behavior.
## License
MIT