Skip to main content
Glama
Swigler

ai-trader-station

by Swigler
README.md
# ai-trader-station

**AI-powered trading workstation built on PySide6 and MetaTrader 5.**

Bill Williams signal cascade, MCP protocol surface, AI price forecasting on RunPod serverless GPU. Built for real trading — runs anywhere Python and MetaTrader 5 are installed.

---

### ChaosPanel — Fib-Based Order Execution

![ChaosPanel](docs/main_chaos.png)

One-click order execution. Auto-detects BUY/SELL from fib direction, risk%-based lot sizing, BUY STOP / SELL STOP / market orders with pre-send price validation. Fibonacci levels drawn on chart, risk/reward calculated live.

---

### BW Screener — Multi-Symbol Signal Scan

![BW Screener](docs/screener.png)

Scan any number of symbols across all timeframes (M1 to MN1) for Bill Williams setups. Color-coded AO signals (Cross, Saucer, Twin Peaks), MFI analysis (Green, Fade, Fake, Squat), fractal markers — all updating in real time with auto-refresh.

---

### AO Chart — Interactive Analysis

![AO Chart](docs/screener_chart.png)

Drill into any symbol. Alligator overlay (Jaw/Teeth/Lips), Awesome Oscillator histogram, fractal arrows, signal annotations. BW status bar shows current AO state, MFI reading, and Alligator alignment at a glance.

---

### AI Chat — Natural Language Trading

![Chat Window](docs/chat_win.png)

DeepSeek + Qwen3-VL powered chat with MCP tool use. Ask questions about market data, run analysis, execute trades — all through natural language. Full MCP protocol surface with schema-validated tool calls.

---

### Trade Management — Live Positions & Orders

![Active Trades](docs/active_trade.png)

Monitor open positions and pending orders in real time. BUY STOP orders placed by the bot show source, SL/TP levels, and one-click cancel. P&L tracking across all positions.

---

## Features

- **Bill Williams Signal Cascade** — Alligator, AO, Fractals, Gator, Zone Trading, Twin Peaks divergence. Multi-timeframe confirmation: fractal trigger → AO confirm → higher-TF filter.
- **ChaosPanel** — Order execution with auto BUY/SELL detection, risk%-based lot sizing, BUY/SELL STOP + market orders, filling-mode handling.
- **AO Screener** — Scan multiple symbols for BW setups across all timeframes.
- **Kronos AI Forecaster** — 102M parameter price prediction model on RunPod serverless. Lot-sizing advisor: agrees with signal → x1.5, disagrees → x0.5, neutral → x1.0.
- **MCP Protocol Surface** — Model Context Protocol tool interface for agentic AI access to all trading capabilities. Thread-safe Qt bridge.
- **AI Chat** — DeepSeek/Qwen3-VL with MCP tool use for natural language trading.
- **Plugin System** — Modular plugin registry with ordered loading and dependency flags.

## Architecture

```
┌──────────────────────────────────────┐
│  ai-trader-station                   │
│                                      │
│  ┌────────────────┐  ┌───────────┐  │
│  │ Signal Engine   │  │ MetaTrader│  │
│  │ BW Cascade      │──│ 5 (broker)│  │
│  ├────────────────┤  └───────────┘  │
│  │ ChaosPanel      │                │
│  │ Order Execution  │                │
│  ├────────────────┤                 │
│  │ MCP Surface     │                │
│  │ AI Tool Use     │                │
│  ├────────────────┤                 │
│  │ Chat Window     │                │
│  │ DeepSeek/Qwen   │                │
│  └────────┬───────┘                 │
└───────────┼──────────────────────────┘
            │ HTTPS (optional)
  ┌─────────▼─────────┐
  │  RunPod Serverless  │
  │  Kronos 102M       │
  │  Price Forecast    │
  └────────────────────┘
```

## Tech Stack

| Layer | Technology |
|-------|-----------|
| UI | PySide6/Qt6, pyqtgraph |
| Broker | MetaTrader 5 (Python API) |
| AI Chat | DeepSeek API (OpenAI-compatible) |
| AI Vision | Qwen3-VL via RunPod |
| AI Forecast | Kronos 102M on RunPod Serverless |
| MCP | Custom implementation with schema validation |
| Language | Python 3.11+ |

## Installation

### Prerequisites

- **Python 3.11+**
- **MetaTrader 5** installed and logged into a broker
- A RunPod account (for Kronos AI forecasts — optional)
- A DeepSeek API key (for AI chat — optional)

### Setup

```bash
git clone https://github.com/Swigler/ai-trader-station.git
cd ai-trader-station

# Install with all dependencies
pip install -e ".[qt,mt5]"

# Copy env template and add your keys
cp .env.example .env
```

### Environment Variables

```env
# Required for AI chat
DEEPSEEK_API_KEY=your-deepseek-key

# Required for Kronos AI forecasts (optional)
RUNPOD_ENDPOINT=https://api.runpod.ai/v2/{endpoint-id}/run
RUNPOD_API_KEY=your-runpod-key

# Optional — Kronos local server
KRONOS_URL=http://localhost:7600
```

### Run

```bash
python -m trade_app
```

## Kronos AI Setup (RunPod Serverless)

Kronos is a 102.3M parameter price prediction model running on RunPod serverless GPU. Scales to zero when idle, spins up on demand.

### Docker Image

```
radu372/kronos-serverless:v2
```

### Step 1 — Create a Network Volume

1. Go to [RunPod Console](https://www.runpod.io/console/serverless) → Storage → Network Volumes
2. Create a new volume: **10 GB**, pick a datacenter close to you
3. Note the volume ID

### Step 2 — Download Model Weights

Spin up a temporary GPU pod with the network volume attached, then:

```python
from huggingface_hub import snapshot_download

snapshot_download('NeoQuasar/Kronos-base',           local_dir='/workspace/kronos/model')
snapshot_download('NeoQuasar/Kronos-Tokenizer-base', local_dir='/workspace/kronos/tokenizer')
```

Terminate the pod after download — the weights persist on the volume.

### Step 3 — Create Serverless Endpoint

1. Go to Serverless → New Endpoint
2. **Container Image:** `radu372/kronos-serverless:v2`
3. **GPU:** Any Ampere GPU (RTX 3060+ / A4000+ / A100)
4. **Workers:** Min 0, Max 1 (scale to zero)
5. **Idle Timeout:** 5 seconds
6. **Advanced → Network Volume:** attach the volume from Step 1
7. **Environment Variables:**

| Variable | Value |
|----------|-------|
| `KRONOS_MODEL_PATH` | `/workspace/kronos/model` |
| `KRONOS_TOKENIZER_PATH` | `/workspace/kronos/tokenizer` |

### Step 4 — Test

```bash
curl -X POST "https://api.runpod.ai/v2/{endpoint-id}/runsync" \
  -H "Authorization: Bearer ${RUNPOD_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{"input": {"action": "health"}}'
```

Expected response:
```json
{"output": {"status": "ok", "device": "cuda:0", "model_path": "/workspace/kronos/model"}}
```

### Step 5 — Connect to the App

Add your endpoint URL and API key to `.env` or enter them in the launcher UI.

### Kronos API

**Single prediction:**
```json
POST /predict
{
  "bars": [{"timestamp": "...", "open": 1.1, "high": 1.2, "low": 1.0, "close": 1.15, "volume": 100, "amount": 0}],
  "pred_len": 10,
  "sample_count": 1
}
```

**Response:**
```json
{
  "direction": "long",
  "confidence": 0.73,
  "predictions": [{"timestamp": "...", "open": ..., "high": ..., "low": ..., "close": ..., "volume": ..., "amount": ...}]
}
```

Kronos is a lot-sizing advisor, never a gatekeeper. Signal agrees → x1.5 lot. Disagrees → x0.5. Neutral → x1.0. The BW cascade always has final authority.

## Signal Cascade

The signal engine implements Bill Williams' Trading Chaos methodology as a cascading gate system:

```
Fractal Trigger
  → Alligator Trend Filter (SMMA 13/8/5)
    → AO Momentum Confirmation
      → Higher Timeframe Filter
        → Zone Trading (AO + AC color)
          → Execution via ChaosPanel
```


## Project Structure

```
ai-trader-station/
├── pyproject.toml
├── .env.example
├── src/
│   └── trade_app/
│       ├── __main__.py              # Entry point
│       ├── app.py                   # Launcher + plugin loading
│       ├── constants.py
│       ├── core/
│       │   ├── signal_engine.py     # Bill Williams indicator engine
│       │   ├── executor.py          # MT5 order execution + risk sizing
│       │   └── kronos_client.py     # Kronos forecast client
│       ├── ui/
│       │   ├── trading_hub.py       # Main window + tab management
│       │   ├── ao_chart.py          # AO chart widget
│       │   ├── ao_screener.py       # Multi-symbol BW screener
│       │   ├── chat_window.py       # AI chat with MCP tool use
│       │   └── control_board.py     # ChaosPanel order execution
│       ├── integrations/
│       │   ├── mt5_utils.py         # MetaTrader 5 helpers
│       │   ├── mcp_app.py           # MCP entry point
│       │   └── mcp/
│       │       ├── bridge.py        # Thread-safe Qt bridge
│       │       ├── schema.py        # MCP tool schemas
│       │       └── interface.py     # MCP interface
│       └── plugins/
│           └── registry.py          # Plugin discovery + loading
├── tests/
│   ├── test_signal_engine.py
│   └── test_indicators.py
└── docs/                            # Screenshots
```

## License

MIT