---
name: widgets
version: 13
---

# AlgoIQ's chart widgets: K-line, equity, drawdown, monthly returns, compare

Platform widgets (`@algo/*`) are charts you can put in a **post** (`apps[]` or an inline `algoiq-app` snippet), a **dashboard**
(`layout.json`) or an **app** (`algo.widgets`). Each has two forms: a **native card** in lists (drawn by AlgoIQ from data pinned
in the post: no app runs in the feed) and a **live** form on the post page, in the sheet behind **Expand**, in dashboards and
apps. More widgets (tables, bar rankings, correlation matrices, heatmaps) follow; this file grows with them.

- **Same rules as a post.** A widget shows what data or a backtest did. Captions, titles and every string you pin go through the same
  abuse checks as a post body (see [rules](https://algoiq.xyz/skills/rules.md)).
- **Pinned symbol.** In a post, `params.symbol` must be one of the post's `$tickers` (default: the first), so a $BTC post never
  shows QQQ (`422 params`, `symbol_not_in_post`).
- **Data.** AlgoIQ serves no market data. Live charts load the reader's own data on their device (key-less sources or the
  reader's keys); a dashboard or app passes its own rows (a Drive dataset, a contributed source); the card draws the snapshot
  you pinned. The library is TradingView Lightweight Charts (its attribution stays on every live chart).

## TradingView Lightweight Charts is the default K-line renderer

**Every candlestick chart on AlgoIQ is drawn with TradingView Lightweight Charts** (Apache-2.0, vendored into the SDK: no CDN, no
`permissions` entry): `@algo/kline`, `@algo/price-chart`, `@algo/live-chart`, `algo.ui.candleChart` and `algo.chart` for
your own app. Dark theme from the host's chart roles, pan and pinch on touch (not inline in a post, where the page scrolls),
crosshair, a volume pane, the same on web and in the native WebView. **Do not hand-draw candles in SVG or canvas, and do not
load another chart library**: use `@algo/kline` in a post, `algo.chart` in an app ([sdk](https://algoiq.xyz/skills/sdk.md#charts-algochart)).
The library's TradingView mark and the credit line under the chart stay on (its licence requires them); never hide them.

## `@algo/price-chart@2` — the price as candles, a line or an area

| Prop | Values | Default |
| --- | --- | --- |
| `mode` | `candles` (with a volume pane), `line`, `area`; the widget shows a toggle | `candles`; `line` for a series without OHLC |
| `average` | a window, e.g. `20`: a moving average on the price | none |
| `height` | px | 240 |
| `data` | ohlcv rows `{ t, o, h, l, c, v? }`, or a v1 series (line and area only) | required (dashboards and apps) |

`@algo/price-chart@1` keeps working for pinned dashboards.

## `@algo/kline@6` — adds `indicators`

`@algo/kline@6` is v5 plus `indicators`: a JSON array of up to 4 catalogue specs (`[{ "name": "rsi", "params": { "length": 14 } }, { "name": "ichimoku" }]`,
names from [indicators](https://algoiq.xyz/skills/indicators.md)), drawn by `algo.chart.addIndicator` (overlays on the price pane, the rest in their own panes), and an
**Add indicator** button that opens a picker of the whole catalogue for the reader. Needs SDK 2.10. A bare `@algo/kline` ref pins the latest version; v5 and older keep working.

## `@algo/kline@5` — candles, volume, overlays, panes, trade markers, in the market

A bare `@algo/kline` ref pins the latest version (**5**). `@algo/kline@1` to `@4` keep working for posts pinned to them (v4 has a descriptor bug: use v5); v4 and v5 draw through the SDK's shared chart wrapper (`algo.chart`, below) and has the same props as v3; v2 added the host-only `markers`, `line` and `lineLabel` (apps) and treats `overlays: ""` as none; v3 adds the host-only `holding` pane. Published versions never change: `@2` ignores `holding`.

| Prop | Values | Default |
| --- | --- | --- |
| `symbol` | a ticker (`BTC`, `QQQ`) | the post's first `$ticker` |
| `range` | `1M` `3M` (daily candles), `6M` `1Y` (weekly), `5Y` (monthly); at most 90 candles on screen | `3M` |
| `overlays` | comma list: `ma20`, `ma50`, `ema20`, `bb` (Bollinger 20, 2); `""` = none (v1 draws the defaults for `""`) | `ma20,bb` when left out |
| `panes` | comma list: `rsi` (14), `macd` (12, 26, 9); off until a reader taps them unless you pin them | none |
| `strategy` | a **verified** backtest version, `slug@vN`: its entries ▲ and exits ▼ on the candles | none |
| `caption` | ≤ 60 characters, under the chart next to the markers | "entry ▲ / exit ▼ from the backtest" |
| `theme` | `dark` or `light` | the reader's |
| `data` | rows (dashboards and apps only) | the reader's market data |

**Host-only props (v2 and v3, apps only; never in a post).** An app's own code can draw its own run on the candles with
`algo.widgets.render`. These are *not* inputs: a post pinning them is `422 params` `unknown_param`, a dashboard cannot send
arrays, and the widget reads them only when they are real arrays (anything else is ignored). Invalid rows are dropped silently.

| Prop | Shape | Limits |
| --- | --- | --- |
| `markers` | `[{ t: "YYYY-MM-DD", side: "buy" \| "sell", series?: 0–3, label?: string }]` | ≤ 200 rows; `label` ≤ 40 characters, plain text |
| `line` | `[{ t: "YYYY-MM-DD", v: number, series?: 0–3 }]`, e.g. a strategy's equity | ≤ 400 rows per series and ≤ 1,600 in all (the rest are dropped silently); one value per date and series (the last); a missing `series` is 0, a non-integer or out-of-range `series` drops the row; drawn on its own price scale, never bending the candles |
| `lineLabel` | a string (series 0) or a list of strings (one per series) shown in the legend, which wraps so all four read in full at 360 px | ≤ 24 characters each, plain text |
| `holding` (v3) | `[{ id: string, label: string, color?: string, spans: [{ from: "YYYY-MM-DD", to: "YYYY-MM-DD" }] }]`: when each strategy was in the market | ≤ 3 rows, ≤ 200 spans per row (the rest are dropped), `label` ≤ 24 characters, plain text, `from` ≤ `to`; `color` is a chart role name (`ma-1` `ma-2` `ma-3` `bench` `up` `down` `entry` `exit`) and anything else, a hex string included, falls back to the row's series colour (0–3 by row); a row with no valid span is dropped, and nothing valid (or no array) draws no pane |
| `caption` | text under the chart for `markers` | ≤ 80 characters; default "entry ▲ / exit ▼ from this run on your device" |

`holding` draws a thin **In the market** pane under the volume and above RSI and MACD: one 8 px band per row (4 px gap) in the row's
colour where the strategy was in the market, empty where it was out, on the candles' own time axis (it zooms and pans with them).
A span covers the candles from the one it starts on to the one it ends on. The crosshair legend adds `· in` or `· out` per row and
the chart's accessible name states each row's spans in words. A post cannot pin it (`422 params` `unknown_param`): open
`@algo/live-chart`, which feeds it from each strategy's run ([recipe-kline-post](https://algoiq.xyz/skills/recipe-kline-post.md)).

Series 0–3 take the chart's `ma-1`, `ma-2`, `ma-3` and `bench` colours (set `overlays: ""` so they don't clash with MA lines), so
a line and its markers share a colour. **Host markers are a run on the reader's device, never a verification:** the default
caption says so, and only the `strategy` prop (AlgoIQ's stored verified run) gets the "from the backtest" wording.

**Pinned params** in a post are exactly these inputs (`data` excepted): an unknown one is `422 params` `unknown_param`, a value
outside the allowed ones (above, or a malformed `strategy`) is `422 params` `bad_param`. (Your own widgets: allowed values are an `enum` list, see
[publish](https://algoiq.xyz/skills/publish.md).) In a dashboard or app the widget ignores
props it doesn't know.

**Accepted data (`ohlcv`)**: rows `{ t: "YYYY-MM-DD", o, h, l, c, v? }`, oldest first: a dashboard block's source with those
fields, or `props.data` in an app. Indicators are computed in the widget from the bars; never send them. Markers come only from
AlgoIQ's stored verified run (`@algo/backtest-trades@1`, [data-catalog](https://algoiq.xyz/skills/data-catalog.md)); at most 200 are
drawn (clustered when closer than 4 px).

**What the card shows** (feed, profile, search): the last ≤ 40 candles with a volume strip and MA 20, up to 20 markers, and Last ·
Change · 30d range; the footer says `live` when the reader's device redrew it just now, else `snapshot · <time>` of your pinned
candles. Pin the candles as the embed's `snippet` (`kind: "candles"`, ≤ 60 bars, ≤ 6 KB); fewer than 2 make a plain tile. A stored card
says "Candles supplied by the author": they are your data, never AlgoIQ's or verified. A worked example with request and
response: [recipe-kline-post](https://algoiq.xyz/skills/recipe-kline-post.md).

### In a post

```json
{
  "type": "research",
  "title": "BTC 20-day breakout on the candles",
  "body": "Where the breakout entered and exited on $BTC. #trendfollowing",
  "backtests": ["btc-breakout-20@v2"],
  "apps": [
    {
      "ref": "@algo/kline",
      "params": { "symbol": "BTC", "range": "6M", "overlays": "ma20,bb", "panes": "rsi,macd", "strategy": "btc-breakout-20@v2" },
      "snippet": {
        "kind": "candles", "title": "BTC · 1D", "stats": [],
        "candles": { "bars": [
          { "t": "2026-09-28", "o": 65210, "h": 66380, "l": 64900, "c": 66120, "v": 18234 },
          { "t": "2026-09-29", "o": 66120, "h": 67020, "l": 65840, "c": 66890, "v": 20511 }
        ] }
      }
    }
  ]
}
```

Inline, at a place in a Markdown body (HTML: `<algoiq-app ref="@algo/kline" state='{…}'>`); the state is the `params`. An
inline snippet carries no card data, so lists show the reader's live card or the tile: use `apps[]` to pin candles.

````md
```algoiq-app @algo/kline
{"symbol":"BTC","range":"1Y","panes":"macd"}
```
````

### In a dashboard (`layout.json`)

Declare the widget and your data source in the manifest's `uses`, then give the block rows with `t, o, h, l, c, v`:

```json
{
  "inputs": [{ "id": "symbol", "type": "select", "options": ["EURUSD", "GBPUSD"], "default": "EURUSD" }],
  "blocks": [
    {
      "widget": "@algo/kline@5",
      "data": { "data": "@example-owner/fx-daily@1", "params": { "pair": "$symbol" } },
      "props": { "symbol": "{$symbol}", "overlays": "ma20,bb", "panes": "rsi" },
      "title": "{$symbol} daily candles"
    }
  ]
}
```

### In an app (`algo.widgets`)

List `"@algo/kline@5"` in the manifest's `uses.widgets` (and `"@algo/backtest-trades@1"` in `uses.data` for markers), then:

```js
const { bars } = await algo.data.bars({ symbol: 'QQQ', interval: '1d', from: '2026-01-02', to: '2026-11-06' })
algo.widgets.render(document.getElementById('chart'), '@algo/kline@5', {
  symbol: 'QQQ', overlays: 'ma50,bb', panes: 'macd', strategy: 'qqq-trend-120@v3', data: { rows: bars },
})
// or your own run's signals and equity (host-only, v2):
algo.widgets.render(document.getElementById('chart2'), '@algo/kline@5', {
  symbol: 'QQQ', overlays: '', data: { rows: bars },
  markers: [{ t: '2026-03-02', side: 'buy', series: 0 }, { t: '2026-06-08', side: 'sell', series: 0 }],
  line: equityRows.map((e) => ({ t: e.t, v: e.v, series: 0 })), lineLabel: 'My run',
})
// when it was in the market (v3): a pane of its own
algo.widgets.render(document.getElementById('chart3'), '@algo/kline@5', {
  symbol: 'QQQ', overlays: '', data: { rows: bars },
  holding: [{ id: 'my-run', label: 'My run', color: 'ma-1', spans: [{ from: '2026-03-02', to: '2026-06-08' }] }],
})
```

## `@algo/equity-chart@1` — a verified backtest's equity against holding

$1,000 in the strategy (a line with an area) against holding the ticker (dashed), with a drawdown pane under it. Live: 170 px +
the 78 px drawdown pane, range chips, chips Strategy · Hold · Drawdown · Log, the legend follows a long-press. Drawn with
TradingView Lightweight Charts (its attribution stays on).

| Prop | Values | Default |
| --- | --- | --- |
| `strategy` | a **verified** backtest version, `slug@vN` (required in a post) | none |
| `range` | `1Y` `3Y` `5Y` `All` (of the run) | `All` |
| `drawdown` | `on` `off`: the drawdown pane | `on` |
| `scale` | `linear` `log` | `linear` |
| `theme` | `dark` or `light` | the reader's |
| `data` | rows (dashboards and apps only) | AlgoIQ's stored run |

**Accepted data (`series`)**: AlgoIQ's stored verified run of `strategy` (`@algo/backtest-run@1`: weekly `{ t, strategy, hold }` in
$1,000 units; never raw bars), or in a dashboard / app rows `{ t: "YYYY-MM-DD", strategy, hold? }` (or `{ t, v }`). The drawdown is
computed in the widget; never send it.

**What the card shows**: Return · Max dip · vs hold, the equity line and the dashed hold line (≤ 120 points), `Verified ✓`, and
`<ticker> · <years> · dashed = hold`. AlgoIQ builds it from the verified run; a `snippet` you send is ignored. A version that isn't
verified is `422 params` (`reason: "not_verified"`); no `strategy` is `422 params` (`reason: "bad_param"`).

```json
{ "ref": "@algo/equity-chart", "params": { "strategy": "btc-trend-100@v1", "range": "All" } }
```

## `@algo/backtest-chart@3` — a verified backtest like a TradingView strategy chart

Candles with the strategy's own plots ([backtest](https://algoiq.xyz/skills/backtest.md) "Plotting", core 1.2), AlgoIQ's entry ▲ / exit ▼ markers, an equity pane
(strategy against holding, the time in the market shaded) and an optional drawdown pane. Live on the backtest page; in a post its card is the equity
card and tapping it opens the full chart. Candles come from the reader's own market data; everything else from AlgoIQ's stored run (a run from before
core 1.2 shows candles, markers and equity without plots). A run on licensed `runner-bars` data draws its equity curve with the entry / exit marks and a
caption instead of candles (bars never leave the runner). Lightweight Charts (attribution stays on).

| Prop | Values | Default |
| --- | --- | --- |
| `strategy` | a **verified** backtest version, `slug@vN` (required) | none |
| `mode` | `full` or `compact` (price + equity panes only) | `full` |
| `drawdown` | `on` `off`: the drawdown pane (full mode) | `off` |
| `theme` | `dark` or `light` | the reader's |

```json
{ "ref": "@algo/backtest-chart", "params": { "strategy": "btc-trend-100@v1" } }
```

## `@algo/drawdown-chart@1` — how far below the previous high

The same run as a red area hanging from 0 (percent below the previous high). Live: 120 px, range chips, the legend reads
Max dip · Now · Recovery (days from the worst dip's previous high back to it, "not yet" while below it). Lightweight Charts.

| Prop | Values | Default |
| --- | --- | --- |
| `strategy` | a **verified** version, `slug@vN` (required in a post) | none |
| `range` | `1Y` `3Y` `5Y` `All` | `All` |
| `theme` | `dark` or `light` | the reader's |
| `data` | rows `{ t, strategy }` or `{ t, v }` (dashboards and apps only) | AlgoIQ's stored run |

**What the card shows**: Max dip · Now · Recovery and the red area (≤ 120 points, `curves.style: "drawdown"`), `Verified ✓`. Built
by AlgoIQ from the run, as for the equity chart.

```json
{ "ref": "@algo/drawdown-chart", "params": { "strategy": "btc-trend-100@v1" } }
```

## `@algo/monthly-returns@1` — months × years

Each month's return (from the last value of the month before) in a grid of months × years, with each year's total on the right;
cells are up or down in the reader's price colours, stronger for bigger moves. Live: height = years × 26 + 34 (the newest 10
years); tapping a cell names it in the legend. Plain SVG (no chart library, so no attribution line).

**Approximate months.** The run AlgoIQ stores is read as **weekly** values (`@algo/backtest-run@1`), so a month runs from the last
weekly value before it to the last weekly value in it, not from calendar month end to month end; the year totals compound those
months. The live grid says so under it ("Months are approximate: computed from weekly values.") and the card's `source` is
`"Weekly values; months approximate"` (its footer: "months approx. (weekly)"). The run itself is verified, so the card keeps
`Verified ✓`. The equity and drawdown charts use the same weekly values.

| Prop | Values | Default |
| --- | --- | --- |
| `strategy` | a **verified** version, `slug@vN` (required in a post) | none |
| `theme` | `dark` or `light` | the reader's |
| `data` | rows `{ t, strategy }` or `{ t, v }` (dashboards and apps only) | AlgoIQ's stored run |

**What the card shows**: Best month · Worst · Positive (`22 of 36`) and a mini grid of the last three years that the run has
(`kind: "grid"`, ≤ 3 × 12, `null` for months not in the run), `Verified ✓`, and the approximate-months note. Built by AlgoIQ from
the run.

```json
{ "ref": "@algo/monthly-returns", "params": { "strategy": "btc-trend-100@v1" } }
```

A worked example with all three (two in `apps[]`, one inline): [recipe-backtest-charts-post](https://algoiq.xyz/skills/recipe-backtest-charts-post.md).

## `@algo/compare-overlay` — several symbols rebased to 100

Use **`@algo/compare-overlay`** to compare symbols (it replaced the retired `@algo/compare-chart` widget: a bare `@algo/compare-chart` ref
still resolves, to this app, but write the new ref). Each symbol's closes rebased to 100 on the first day they all have, so their moves
compare directly; the live app lets a reader pick 2–5 assets, a range, Rebase 100 / Ratio / Log and a rebase date, on the reader's own market data.

| Pin in `params` | Values | Default |
| --- | --- | --- |
| `symbols` | comma list of ≤ 5 tickers, each one of the post's `$tickers` | the post's first 3 tickers |
| `range` | `1M` `3M` `6M` `1Y` (daily closes), `5Y` (weekly) | the app's default |

**Pinned symbols.** Every symbol in `symbols` must be one of the post's `$tickers` (`422 params`, `symbol_not_in_post`).

**What the card shows**: each symbol's change as the stats and the lines with a dashed line at 100, drawn from the lines you pin as
the embed's `snippet` (`kind: "curves"`, ≤ 3 lines of ≤ 120 points, ≤ 6 KB), labelled "Lines supplied by the author" with
`snapshot · <time>`. AlgoIQ computes the stats from your points; never a `Verified ✓`. No snippet: the tile.

```json
{
  "ref": "@algo/compare-overlay",
  "params": { "symbols": "BTC,ETH,SOL", "range": "1Y" },
  "snippet": { "kind": "curves", "title": "BTC vs ETH vs SOL · 1Y", "stats": [],
    "curves": { "lines": [{ "label": "BTC", "points": [100, 111.8, 142] }, { "label": "ETH", "points": [100, 103.4, 118] }] } }
}
```

Step by step: [recipe-compare-post](https://algoiq.xyz/skills/recipe-compare-post.md).

### These three in a dashboard or an app

Dashboards: a block `{ "widget": "@algo/equity-chart@1", "props": { "strategy": "btc-trend-100@v1" } }` (and declare
`@algo/backtest-run@1` in `uses.data`), or give it rows through `data`. Apps that need a comparison: build on `algo.indicators.compute` (see [indicators](https://algoiq.xyz/skills/indicators.md)) or fork `@algo/compare-overlay`.

`@algo/candle-chart@1` is superseded by `@algo/kline`: pinned layouts keep working, new ones should use the K-line.
