# Indicator architecture

## Flow

```text
Market data (OANDA API or warehouse API)
        ↓
Normalized / chart candles (IndicatorCandle)
        ↓
Indicator engine (runIndicator)
        ↓
Indicator definition (calculate)
        ↓
Structured outputs (line / marker)
        ↓
Chart renderer (overlay line today)
```

Indicators never call brokers or SQLite. They only receive candle arrays that already match the platform OHLCV semantics.

## Modules

| Path | Role |
|------|------|
| `lib/indicators/types.ts` | Contract, output models |
| `lib/indicators/parameters.ts` | Typed parameter parsing |
| `lib/indicators/registry.ts` | Register / list / get |
| `lib/indicators/engine.ts` | `runIndicator()` pipeline |
| `lib/indicators/reference/sma.ts` | F1 test indicator |
| `lib/indicators/builtin.ts` | Built-in registration |

## Render placements

- **overlay** — line on price chart (SMA implemented)
- **panel** — separate pane (contract only; renderer later)
- **marker** — discrete events (contract only; renderer later)

## Future Pine ports

New indicators implement `IndicatorDefinition`, register in `builtin.ts` (or a future plugin loader), and map outputs to chart layers without changing the engine.
