> ## Documentation Index
> Fetch the complete documentation index at: https://docs.miteos.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Trading Agent

> Backtest strategies, scan signals, paper/live trade with safety guards.

# Trading Agent

The Trading vertical provides quantitative backtesting, signal generation, and execution with comprehensive safety controls.

## Capabilities

* **Backtesting** — Test any strategy against historical data with realistic slippage and commission modeling
* **Signal Scanner** — 452 quantitative factors across RSI, MACD, momentum, volume, volatility, cross-asset correlations
* **Paper Trading** — Simulated execution with real-time market prices
* **Live Trading** — Real broker execution (Alpaca, Binance, Coinbase, Tradier) with safety guards
* **Pine Script Export** — Generate TradingView-compatible strategy code
* **MT5 Export** — Generate MetaTrader 5 Expert Advisors

## API Endpoints

### Run a Backtest

```bash theme={null}
POST /trading/backtest
{
  "symbol": "SPY",
  "strategy": "momentum",
  "timeframe": "1d",
  "start_date": "2024-01-01",
  "end_date": "2024-12-31"
}
```

Returns win rate, profit factor, Sharpe ratio, max drawdown, net P\&L.

### Scan Signals

```bash theme={null}
POST /trading/signals
{
  "symbols": ["SPY", "QQQ", "AAPL", "MSFT", "NVDA"],
  "factors": ["rsi", "macd", "momentum", "volume"],
  "timeframe": "1d"
}
```

### Open Position (Paper)

```bash theme={null}
POST /trading/positions/open
{
  "symbol": "AAPL",
  "side": "long",
  "quantity": 10,
  "stop_loss": 170.00,
  "take_profit": 195.00
}
```

### Close Position

```bash theme={null}
POST /trading/positions/{position_id}/close
```

### Kill All Positions (Emergency)

```bash theme={null}
POST /trading/positions/kill-all
```

### Export to Pine Script

```bash theme={null}
POST /trading/export/pinescript
{"strategy_id": "strat-abc123"}
```

## Broker Connections

Connect a live broker for real execution:

```bash theme={null}
GET /trading/brokers          # List available brokers
POST /trading/brokers/connect # Connect with API keys
```

Supported brokers:

* **Alpaca** — US equities, paper + live
* **Binance** — Crypto spot and futures
* **Coinbase** — Crypto spot
* **Tradier** — US equities and options
* **Interactive Brokers** — Multi-asset (coming)
* **MetaTrader 5** — Forex and CFDs (coming)

## Safety Guards

Every trade passes through the SafetyGuard before execution:

| Guard              | Default  | Purpose                         |
| ------------------ | -------- | ------------------------------- |
| Max position size  | \$10,000 | Cap per-trade risk              |
| Max daily loss     | \$500    | Stop trading if losing too much |
| Max drawdown       | 5%       | Kill switch if portfolio drops  |
| Max open positions | 20       | Prevent over-concentration      |
| Mandate expiry     | 24 hours | Auto-revoke trading authority   |
| Require stop loss  | Yes      | Every position must have a stop |

## Desktop Integration

In the Desktop app, the Trading Operator can:

* Open TradingView charts directly in the embedded browser
* Visually identify setups from chart patterns (via LLM vision)
* Execute trades with one-click confirmation
* Monitor positions with real-time P\&L
