# MyTrader User-Defined Indicators (UDI) Documentation

**Quick navigation:** This documentation is split into logical chunks to make targeted lookups faster. Start with the section that matches your task.

---

## Core Concepts & Setup

- **[001-introduction.md](https://api.fxblue.com/mytrader/udi/markdown/001-introduction.md)** — What UDIs can do, how to add them to charts, lifecycle, common pitfalls. Start here if you're new to UDIs.
- **[002-myindicator-class.md](https://api.fxblue.com/mytrader/udi/markdown/002-myindicator-class.md)** — Class structure and the UserDefinedIndicator base class.

## Writing Indicators

- **[003-initialization-oninit.md](https://api.fxblue.com/mytrader/udi/markdown/003-initialization-oninit.md)** — `onInit()` function, defining plots, settings fields, context data.
- **[004-calculating-data-oncalculate.md](https://api.fxblue.com/mytrader/udi/markdown/004-calculating-data-oncalculate.md)** — `onCalculate()` function, input data, efficiency patterns, technical analysis (FXB.ta library).
- **[005-chart-changes.md](https://api.fxblue.com/mytrader/udi/markdown/005-chart-changes.md)** — `onContextChange()` and `onParameterChange()` handlers.

## Visual Output & Interaction

- **[006-drawings-markers-highlights.md](https://api.fxblue.com/mytrader/udi/markdown/006-drawings-markers-highlights.md)** — Creating drawings (rectangles, lines, channels etc.), event markers, bar highlights. Includes all drawing types and properties.
- **[007-notifications.md](https://api.fxblue.com/mytrader/udi/markdown/007-notifications.md)** — Toast notifications, background color changes.
- **[008-html-in-chart.md](https://api.fxblue.com/mytrader/udi/markdown/008-html-in-chart.md)** — Embedding HTML iframes, bidirectional messaging between HTML and UDI.

## Trading & Account Integration

- **[009-deal-ticket-and-trade.md](https://api.fxblue.com/mytrader/udi/markdown/009-deal-ticket-and-trade.md)** — Recommended trades, opening the deal ticket, order definitions.
- **[010-account-order-data.md](https://api.fxblue.com/mytrader/udi/markdown/010-account-order-data.md)** — Subscribing for account metrics and order data without UDIX access.

## Advanced Topics

- **[011-other-topics.md](https://api.fxblue.com/mytrader/udi/markdown/011-other-topics.md)** — External data collection (XMLHttpRequest, CORS), date/timezone conversion, multi-timeframe indicators, remote C#/Python indicators.
- **[012-legacy-code.md](https://api.fxblue.com/mytrader/udi/markdown/012-legacy-code.md)** — Legacy UDI format (UDI namespace vs. MyIndicator class), migration guide.

## Reference

- **[A10-examples-reference.md](https://api.fxblue.com/mytrader/udi/markdown/A10-examples-reference.md)** — Complete list of 21 example UDI files with descriptions and links. Browse by pattern: basics, histograms, plot variants, drawings, event markers, bar highlights, HTML, multi-timeframe, capstone.

---

## For LLMs Building UDIs

⚠️ **Before writing code:**
- Modern format uses `class MyIndicator extends UserDefinedIndicator { ... }` with `this.createDrawing()` — **not** legacy `UDI.onInit = function() { ... }` format.
- Always fetch the freshly-documented API before guessing—the framework is large enough that "this seems like it should work" is unreliable.
- **Do not invent functions or properties.** If it's not in the docs you just read, it doesn't exist.
- Drawings cannot be created from `onInit()` — defer to first `onCalculate()` call.
- `select` field values arrive as strings, not numbers — use `parseInt()`/`parseFloat()`.
- Dates are milliseconds in **chart time**, not UTC — convert with `convertChartDateToUTC()` / `convertUTCToChartDate()`.

---

## Quick Lookups

| Task | File |
|------|------|
| Trying to plot values on the chart | [003-initialization-oninit.md](https://api.fxblue.com/mytrader/udi/markdown/003-initialization-oninit.md) → Plots array |
| Need a parameter the user can configure | [003-initialization-oninit.md](https://api.fxblue.com/mytrader/udi/markdown/003-initialization-oninit.md) → Settings fields |
| Calculating indicators from candle data | [004-calculating-data-oncalculate.md](https://api.fxblue.com/mytrader/udi/markdown/004-calculating-data-oncalculate.md) |
| Using moving averages, ATR, RSI etc. | [004-calculating-data-oncalculate.md](https://api.fxblue.com/mytrader/udi/markdown/004-calculating-data-oncalculate.md) → Technical analysis (FXB.ta) |
| Drawing lines, rectangles on the chart | [006-drawings-markers-highlights.md](https://api.fxblue.com/mytrader/udi/markdown/006-drawings-markers-highlights.md) |
| Responding to user clicks on markers | [006-drawings-markers-highlights.md](https://api.fxblue.com/mytrader/udi/markdown/006-drawings-markers-highlights.md) → Event markers |
| Putting a button or form in the chart | [008-html-in-chart.md](https://api.fxblue.com/mytrader/udi/markdown/008-html-in-chart.md) |
| Suggesting a trade or opening deal ticket | [009-deal-ticket-and-trade.md](https://api.fxblue.com/mytrader/udi/markdown/009-deal-ticket-and-trade.md) |
| Reading account balance, open positions | [010-account-order-data.md](https://api.fxblue.com/mytrader/udi/markdown/010-account-order-data.md) |
| Fetching external data (calendar, signals) | [011-other-topics.md](https://api.fxblue.com/mytrader/udi/markdown/011-other-topics.md) → External data |
| Multi-timeframe without time-travelling | [011-other-topics.md](https://api.fxblue.com/mytrader/udi/markdown/011-other-topics.md) → Multi-timeframe indicators |
| Converting between UTC and chart time | [011-other-topics.md](https://api.fxblue.com/mytrader/udi/markdown/011-other-topics.md) → Date conversion |

---

**Framework access:** Without UDIX (framework access), UDIs can plot, draw, and suggest trades. With UDIX, they can place trades, cancel orders, and more. See [001-introduction.md](https://api.fxblue.com/mytrader/udi/markdown/001-introduction.md) § 1.1 for the distinction.

**Examples:** 21 example files walk through basics, histograms, drawings, HTML, multi-timeframe, and more. See [A10-examples-reference.md](https://api.fxblue.com/mytrader/udi/markdown/A10-examples-reference.md) for the full list.
