acttrader-charts 1.3.0-beta.3 → 1.3.0-beta.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1900 -41
- package/dist/MACD-qgMFBxWV.d.cts +3890 -0
- package/dist/MACD-qgMFBxWV.d.ts +3890 -0
- package/dist/chunk-H7VQODXR.js +5766 -0
- package/dist/chunk-H7VQODXR.js.map +1 -0
- package/dist/index.cjs +25661 -8175
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2715 -22
- package/dist/index.d.ts +2715 -22
- package/dist/index.js +20064 -5966
- package/dist/index.js.map +1 -1
- package/dist/indicators/index.cjs +3424 -58
- package/dist/indicators/index.cjs.map +1 -1
- package/dist/indicators/index.d.cts +470 -3
- package/dist/indicators/index.d.ts +470 -3
- package/dist/indicators/index.js +1 -1
- package/dist/webview/chart.html +130 -82
- package/package.json +1 -1
- package/dist/MACD-D1i-sEFR.d.cts +0 -1904
- package/dist/MACD-D1i-sEFR.d.ts +0 -1904
- package/dist/chunk-3H3T5S77.js +0 -2512
- package/dist/chunk-3H3T5S77.js.map +0 -1
package/README.md
CHANGED
|
@@ -58,12 +58,15 @@ chart.on('durationChange', ({ duration, timeframe }) => {
|
|
|
58
58
|
```ts
|
|
59
59
|
const chart = new ChartEngine({
|
|
60
60
|
container,
|
|
61
|
-
dataLoader: async ({ start, end, interval }) => {
|
|
62
|
-
|
|
61
|
+
dataLoader: async ({ start, end, interval, priceSource }) => {
|
|
62
|
+
// `priceSource` ('bid' | 'ask' | 'ltp') is the candle source the chart is showing —
|
|
63
|
+
// pass it to your history API so the bars match (dealing feeds: LTP vs BID candles).
|
|
64
|
+
const res = await fetch(`/api/bars?from=${start.getTime()}&to=${end.getTime()}&tf=${interval}&source=${priceSource}`);
|
|
63
65
|
return res.json(); // OHLCVBar[]
|
|
64
66
|
},
|
|
65
67
|
});
|
|
66
|
-
// No manual loadData() needed — the engine calls dataLoader on start
|
|
68
|
+
// No manual loadData() needed — the engine calls dataLoader on start, on timeframe/duration
|
|
69
|
+
// changes, and (unless `reloadOnPriceSourceChange: false`) whenever the price source changes.
|
|
67
70
|
```
|
|
68
71
|
|
|
69
72
|
If the first fetch returns fewer than `minInitialBars` (default `10`), the engine automatically widens the lookback window and calls `dataLoader` again — up to the `maxLookbackMs` ceiling (default 365 days). This keeps the chart useful on weekends, holidays, or for instruments that just listed. If retries still yield zero bars, the engine shows a **"No data available"** overlay (customise the text via `labels.chart.noData`).
|
|
@@ -152,6 +155,9 @@ const dealingChart = new ChartEngine({
|
|
|
152
155
|
container,
|
|
153
156
|
// "Show chart by" toggle: 'ltp' | 'ask' | 'bid' (candle close/high/low source)
|
|
154
157
|
tickClosePriceSource: 'ltp',
|
|
158
|
+
// Header dropdown so the user can switch the source on the chart itself
|
|
159
|
+
// (rendered next to the timeframe dropdown; omit to hide):
|
|
160
|
+
priceSourceSelector: ['ltp', 'bid'],
|
|
155
161
|
// Chart line checkboxes — each price line is independent:
|
|
156
162
|
showAskLine: true, // Show AskLine
|
|
157
163
|
showBidLine: true, // Show BidLine
|
|
@@ -161,8 +167,15 @@ const dealingChart = new ChartEngine({
|
|
|
161
167
|
dealingChart.setShowAskLine(false); // hide the ask line
|
|
162
168
|
dealingChart.setShowBidLine(true); // show the bid line
|
|
163
169
|
dealingChart.setShowLtpPrice(true); // show the LTP line
|
|
170
|
+
// Switch the candle source programmatically (e.g. from a trade-settings page);
|
|
171
|
+
// the header dropdown label follows automatically:
|
|
172
|
+
dealingChart.setTickClosePriceSource('bid');
|
|
173
|
+
// A user pick from the dropdown emits `priceSourceChange` — persist it:
|
|
174
|
+
dealingChart.on('priceSourceChange', ({ source }) => saveTradeSetting(source));
|
|
164
175
|
```
|
|
165
176
|
|
|
177
|
+
**History follows the source.** Switching the source (dropdown pick or `setTickClosePriceSource()`) does not just change how live ticks extend the last candle — the engine re-runs your `dataLoader` with `params.priceSource` set to the new value and replaces the loaded bars, keeping the visible time window. Forward `priceSource` to your charting API (e.g. as a query parameter) so it returns LTP-built or BID-built candles accordingly; without it the API keeps serving the old source and the chart cannot change. Set `reloadOnPriceSourceChange: false` to opt out of the re-fetch.
|
|
178
|
+
|
|
166
179
|
### Compare symbols
|
|
167
180
|
|
|
168
181
|
Overlay one or more comparison instruments on the main chart, normalized to
|
|
@@ -249,6 +262,12 @@ chart.setLevels(
|
|
|
249
262
|
);
|
|
250
263
|
```
|
|
251
264
|
|
|
265
|
+
**Trailing stop:** a trade with a trail always has a working stop, so keep passing its price as `stopLossPrice` and set `stopLossTrailing: true`. The line renders as usual but its pill reads **TSL** instead of SL, and it is read-only on the chart — no drag handle, no × — because the trail is a pip distance edited from the host's own panel. The level's TP stays fully editable.
|
|
266
|
+
|
|
267
|
+
```ts
|
|
268
|
+
{ label: 'POS-2', price: 1.0850, side: 'buy', lots: 1, stopLossPrice: 1.0800, stopLossTrailing: true }
|
|
269
|
+
```
|
|
270
|
+
|
|
252
271
|
**Bracket orders via `ToClose`** — link a separate SL/TP pending order to a parent level:
|
|
253
272
|
|
|
254
273
|
```ts
|
|
@@ -333,13 +352,15 @@ When `enableTrading` is on and live BID/ASK data is streaming, hovering / activa
|
|
|
333
352
|
|
|
334
353
|
### Horizontal (time-axis) order-line dragging
|
|
335
354
|
|
|
336
|
-
Opt-in via `features.orderLineTimeDrag` (off by default; enable it per broker from the host app — e.g. only for Hankotrade users). When enabled, any level flagged `timeDraggable: true` can have its **info-box badge** dragged left/right to re-anchor the order to a different candle.
|
|
355
|
+
Opt-in via `features.orderLineTimeDrag` (off by default; enable it per broker from the host app — e.g. only for Hankotrade users). When enabled, any level flagged `timeDraggable: true` — open positions **and pending orders** alike — can have its **info-box badge** dragged left/right to re-anchor the order to a different candle. During a horizontal drag the **price line stays locked** — only the time anchor moves. A fixed-price position's badge grabs horizontally at once (`grab` / `grabbing` cursor). A pending order (or entry-editable position) keeps its price drag: its badge shows a `move` cursor and the **first movement decides the axis** — sideways moves the time anchor, up/down moves the entry price exactly as before, and the full-width line still drags vertically.
|
|
337
356
|
|
|
338
357
|
```ts
|
|
339
358
|
const chart = new ChartEngine({
|
|
340
359
|
container,
|
|
341
360
|
features: { orderLineTimeDrag: true }, // host enables this only for the gated broker
|
|
342
361
|
orderLineDragSnap: true, // snap to nearest candle on release (default)
|
|
362
|
+
orderLineAnchorPersistence: true, // remember dropped positions in localStorage (default)
|
|
363
|
+
orderLineDefaultAnchor: 'center', // un-dragged badges start mid-chart (default: 'timestamp')
|
|
343
364
|
});
|
|
344
365
|
|
|
345
366
|
chart.setLevels(
|
|
@@ -354,13 +375,101 @@ chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, data }) => {
|
|
|
354
375
|
```
|
|
355
376
|
|
|
356
377
|
- **Bounds:** the badge is clamped to the visible viewport — it can't be dragged past the left/right edge.
|
|
378
|
+
- **Pending orders:** flag them `timeDraggable: true` too. The pill follows the drag direction — a sideways pull re-anchors the order in time (price locked, `orderLineMoved` on release), a vertical pull moves the entry price and its SL/TP brackets as usual (`tradeLevelDrag` / `tradeLevelEdit`). The axis is fixed after about 6px of movement and does not change mid-drag. Touch follows the same rule, and a tap that never moves still opens the edit form.
|
|
357
379
|
- **Snap:** controlled by `orderLineDragSnap` (default `true`); set `false` to keep the exact released time.
|
|
358
380
|
- **Escape / touch-cancel:** reverts the badge to its starting candle without emitting `orderLineMoved`.
|
|
359
381
|
- **Stays put after release:** the chart holds the dropped position across `setLevels` refreshes until you echo the new `timestamp` back (auto-released on match).
|
|
382
|
+
- **Survives reloads:** with `orderLineAnchorPersistence` (default `true`) the dropped candle time is saved in `localStorage` under `finchart.orderLineTimeAnchors`, keyed by the level's label. After a page reload the badge returns to that candle even if your `setLevels()` payload still carries the order's original `timestamp` — the persisted anchor wins until the badge is dragged again. Capped at the 500 most recently dragged labels; set `false` if you persist anchors server-side instead.
|
|
383
|
+
- **New orders at the center:** with `orderLineDefaultAnchor: 'center'` a `timeDraggable` level that has never been dragged ignores its `timestamp` and renders mid-chart — so a freshly filled market order arrives in the middle of the chart rather than pinned to the latest candle at the right edge. Levels that are not `timeDraggable` still honor `timestamp`. Default `'timestamp'` keeps the previous behavior.
|
|
360
384
|
- A level **without** `timestamp` renders exactly as before (badge centered), so existing consumers are unaffected.
|
|
361
385
|
|
|
362
386
|
---
|
|
363
387
|
|
|
388
|
+
### Trade action bar — `features.tradeActionBar`
|
|
389
|
+
|
|
390
|
+
With the flag on, the floating trade button opens a segmented bar at the clicked
|
|
391
|
+
price instead of the two-row Buy/Sell popup:
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
Alert | Pending | SL | TP | TSL | ×
|
|
395
|
+
```
|
|
396
|
+
|
|
397
|
+
- No price readout — the axis already shows the price at that point.
|
|
398
|
+
- **Alert** calls `onAddAlert(price)`. The chip is only rendered when that callback is set. The same callback also backs the **Alert** entry of the advanced header's ⋯ menu (`headerOverflowMenu`), which passes the current market price (live ask, else bid, else last close) so the host opens the same form.
|
|
399
|
+
- **Pending** opens a sub-menu just above the bar — an `Above · 1.17586` / `Below · …`
|
|
400
|
+
header, then the two orders that make sense at that price (`Buy Limit` / `Sell Stop`
|
|
401
|
+
below the market, `Sell Limit` / `Buy Stop` above), each with its `@ price`. Picking a
|
|
402
|
+
row creates the draft order exactly as before and closes both.
|
|
403
|
+
- **SL / TP / TSL** emit `bulkLevelsRequested` with `{ kind, price }` and close the
|
|
404
|
+
bar — the host opens its Bulk Levels dialog pre-focused on that kind. The chart
|
|
405
|
+
never calls a broker. The chips grey out, with a tooltip saying why, when the
|
|
406
|
+
symbol has no open positions or has buys and sells open at once — one stop or
|
|
407
|
+
target price cannot sit on the right side of the market for both directions.
|
|
408
|
+
- **×**, a click elsewhere, Escape, TFC off and `dismissAllUI()` all close it.
|
|
409
|
+
|
|
410
|
+
Chip labels and the × tooltip live under `labels.trade` (`actionAlert`, `actionPending`,
|
|
411
|
+
`actionSl`, `actionTp`, `actionTsl`, `actionCloseTitle`).
|
|
412
|
+
|
|
413
|
+
### On-chart P/L pill — `features.pnlPill`
|
|
414
|
+
|
|
415
|
+
A floating summary of the open positions on the chart, for the trader who wants
|
|
416
|
+
the total without opening the positions panel:
|
|
417
|
+
|
|
418
|
+
```
|
|
419
|
+
⋮⋮ 3 POS +72.65 USD | ◎ ✕
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
- **`3 POS`** — how many position levels are on the chart. Pending orders,
|
|
423
|
+
position-style entry orders (`entryPriceEditable`) and an unconfirmed draft
|
|
424
|
+
are not counted.
|
|
425
|
+
- **`+72.65 USD`** — the sum of the numeric `pnl` those levels carry, i.e. the
|
|
426
|
+
`pnlKey` column you pass to `setLevels`. The chart computes no money itself;
|
|
427
|
+
while no position has a `pnl` yet the pill shows `—`. Profit is drawn in the
|
|
428
|
+
buy colour, loss in the sell colour.
|
|
429
|
+
- **Click the body** (the grip, the count or the amount) to fan every position
|
|
430
|
+
badge out on the chart — clustered levels expand, and TFC is switched on if it
|
|
431
|
+
was off — with an accent ring on the pill while they are shown. Click again to
|
|
432
|
+
collapse.
|
|
433
|
+
- **◎** (the same target glyph as the Bulk Levels dialog header) emits
|
|
434
|
+
`bulkLevelsRequested` with `source: 'pill'` and a `null` price, so your Bulk Levels
|
|
435
|
+
dialog opens pre-scoped to every open position on the symbol. Tooltip:
|
|
436
|
+
"Set SL · TP · TSL on all N {symbol} positions". Greyed out while buys and sells are
|
|
437
|
+
both open ("Bulk levels need all N {symbol} positions in one direction").
|
|
438
|
+
- **✕** (amber) emits `pnlPillCloseAll` with every counted position. Your app
|
|
439
|
+
confirms and closes them; the chart never calls a broker.
|
|
440
|
+
|
|
441
|
+
The pill sits top-right of the plot, clear of the price axis. Drag it anywhere
|
|
442
|
+
inside the plot; double-click puts it back. It hides itself while the chart has
|
|
443
|
+
no positions and follows the chart theme. Every element sits on one shared row
|
|
444
|
+
height, and the grip and both buttons have fixed widths, so a long or negative
|
|
445
|
+
amount never shifts or squeezes them.
|
|
446
|
+
|
|
447
|
+
With the feature on, the header (advanced toolbar and default top bar) also gets a
|
|
448
|
+
**P/L** switch — wallet icon, `P/L`, the same 24px `rounded-sm` button tinted while the
|
|
449
|
+
pill is shown. It hides or shows the pill on the user's say-so, wins over the position
|
|
450
|
+
count, and emits `pnlPillToggle` so you can persist the choice; `pnlPill.visible` seeds
|
|
451
|
+
it and `setPnlPillVisible()` drives it from code.
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
const chart = new ChartEngine({
|
|
455
|
+
container,
|
|
456
|
+
features: { pnlPill: true },
|
|
457
|
+
pnlPill: { currency: 'USD' }, // → "+72.65 USD"; or format: (pnl) => myMoney(pnl)
|
|
458
|
+
});
|
|
459
|
+
|
|
460
|
+
chart.setLevels(positions, 'TradeID', 'Price', 'position', 'pnl', 'pnlText');
|
|
461
|
+
|
|
462
|
+
chart.on('pnlPillCloseAll', async ({ count, pnl, data }) => {
|
|
463
|
+
if (!(await confirmDialog(`Close all ${count} positions?`))) return;
|
|
464
|
+
for (const row of data) closeTrade(row);
|
|
465
|
+
});
|
|
466
|
+
```
|
|
467
|
+
|
|
468
|
+
Labels live under `labels.pnlPill`: `positionsAbbrev` (`'POS'`), `showPositionsTitle`,
|
|
469
|
+
`hidePositionsTitle`, `bulkLevelsTitle`, `closeAllTitle` — titles may
|
|
470
|
+
use `{symbol}` and `{count}`. The maths behind the pill is exported as
|
|
471
|
+
`summarisePositionLevels(levels, draftLabel?)` and `formatPnlPillValue(pnl, currency?)`.
|
|
472
|
+
|
|
364
473
|
## Default Configuration
|
|
365
474
|
|
|
366
475
|
### `ChartConfig`
|
|
@@ -375,9 +484,13 @@ chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, data }) => {
|
|
|
375
484
|
| `hideHeader` | | `false` | Hide only the chart header (TopBar / AdvancedToolbar / CompactToolbar, per `headerLayout`). Bottom bar, left drawing tools, and on-canvas overlays remain on their own flags. Drive the chart from your own UI via `setTimeframe(tf)`, `setSeries(type)`, `addIndicatorByName(name)`, `removeIndicator(name)` |
|
|
376
485
|
| `showDrawingTools` | | `true` | Show drawing toolbar and pencil button |
|
|
377
486
|
| `showFullscreenButton` | | `true` | Show the fullscreen toggle button in the top bar. Set to `false` to hide it entirely. Mobile wrappers (Android / iOS) default this to `false` |
|
|
378
|
-
| `timeframe` | | `"1D"` | Initial timeframe |
|
|
487
|
+
| `timeframe` | | `"1D"` | Initial timeframe. Values: `1m` `3m` `4m` `5m` `10m` `15m` `30m` `1h` `2h` `4h` `8h` `1D` `1W` `1M`; `3m` / `4m` / `10m` / `30m` are requested from `dataLoader` as `3min` / `4min` / `10min` / `30min`. If your API lacks them, point `aggregateFrom` at a finer interval it does serve, e.g. `{ '3m': '1m', '4m': '1m', '10m': '5m', '30m': '15m' }` — the chart merges the candles |
|
|
488
|
+
| `timeframes` | | classic set | Timeframes offered in the header, in order: the advanced row's pills, the classic dropdown, and the rest of the reference header's ⌄ menu after its six fixed pills. Omit to keep `1m 5m 15m 1h 4h 1D 1W` (row) / `… 30m 2h 8h 1M` (dropdown, ⌄), so the newer minute timeframes only appear for hosts that list them |
|
|
379
489
|
| `duration` | | — | Initial active duration button |
|
|
380
490
|
| `symbol` | | — | Symbol name shown in the top bar |
|
|
491
|
+
| `features` | | `{}` | Opt-in feature gates. See [Feature flags](#feature-flags) |
|
|
492
|
+
| `instrument` | | — | Contract specs for `symbol` — pip size, contract size, money conversion. See [`InstrumentSpec`](#instrumentspec) |
|
|
493
|
+
| `account` | | — | Account equity and per-trade risk used to size the position tools. See [`AccountSpec`](#accountspec) |
|
|
381
494
|
| `isins` | | — | Symbol list for the picker modal |
|
|
382
495
|
| `onIsinSelect` | | — | Called when user picks a symbol from the picker modal |
|
|
383
496
|
| `padding` | | `{top:8,right:0,bottom:0,left:0}` | Canvas padding (px) |
|
|
@@ -394,7 +507,7 @@ chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, data }) => {
|
|
|
394
507
|
| `momentumMaxVelocity` | | `6.0` | Max launch velocity (px/ms) — caps hard-flick speed |
|
|
395
508
|
| `targetCandleWidth` | | `10` | Target px width per candle for auto-calculating initial bar count |
|
|
396
509
|
| `durationTimeframeMap` | | *(see below)* | Override duration → timeframe pairings |
|
|
397
|
-
| `dataLoader` | | — | `(
|
|
510
|
+
| `dataLoader` | | — | `({ start, end, interval, priceSource }) => Promise<OHLCVBar[]>` auto-called on load, timeframe/duration change, and price-source change. `priceSource` is the candle source to fetch (`'bid'`, `'ask'` or `'ltp'`) |
|
|
398
511
|
| `compareDataLoader` | | — | `({ symbol, start, end, interval }) => Promise<OHLCVBar[]>` — fetches bars for a compare symbol. Set this to enable the library-owned Compare flow. |
|
|
399
512
|
| `initialCompares` | | — | Symbols to auto-add as compares once the initial primary range is loaded |
|
|
400
513
|
| `maxCompares` | | `8` | Maximum concurrent compare symbols. Adding beyond emits `compareError` |
|
|
@@ -403,6 +516,8 @@ chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, data }) => {
|
|
|
403
516
|
| `labels` | | `DEFAULT_LABELS` | Deep-partial string overrides for i18n/translation |
|
|
404
517
|
| `tickClosePriceSource` | | `"bid"` | Which price drives live tick close/high/low: `"bid"`, `"ask"`, or `"ltp"` (build candles from the last traded price — exchange/dealing feeds; ticks without a valid LTP fall back to the bid) |
|
|
405
518
|
| `showLtpPrice` | | unset | Show the LTP marker (dashed price line + axis tag). Unset: shown only in `"ltp"` mode. `true`: always shown when the feed supplies an LTP. `false`: hidden even in `"ltp"` mode (candles still build from the LTP). Toggle at runtime with `chart.setShowLtpPrice(show)` |
|
|
519
|
+
| `priceSourceSelector` | | unset | Show a price-source dropdown in the chart header listing the given sources, e.g. `["ltp", "bid"]` (dealing feeds). A user pick switches the candle source, re-fetches history via `dataLoader` (see `reloadOnPriceSourceChange`) and emits `priceSourceChange`; sync it programmatically with `chart.setTickClosePriceSource(source)`. Hidden when unset/empty. Default header layout only |
|
|
520
|
+
| `reloadOnPriceSourceChange` | | `true` | Re-run `dataLoader` with the new `params.priceSource` whenever the candle price source changes, so historical candles are rebuilt from the selected price (LTP vs BID) and not only the live one. The visible time window is preserved. Set `false` to keep only live ticks following the new source |
|
|
406
521
|
| `showBidAskLines` | | `false` | **Deprecated** — show both bid and ask as dashed lines during a live stream. Prefer the per-line checks `showAskLine` / `showBidLine`, which override it when set |
|
|
407
522
|
| `showAskLine` | | unset | Show the Ask price line (dashed line + axis tag) independently. Unset: legacy `showBidAskLines` behavior. Toggle at runtime with `chart.setShowAskLine(show)` |
|
|
408
523
|
| `showBidLine` | | unset | Show the Bid price line (dashed line + axis tag) independently. Unset: legacy `showBidAskLines` behavior. Toggle at runtime with `chart.setShowBidLine(show)` |
|
|
@@ -412,31 +527,150 @@ chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, data }) => {
|
|
|
412
527
|
| `showPriceAxisCountdown` | | `false` | Show candle countdown timer on the right price axis, just below the live price tag. Honours `candleCountdownTimeframes`. Toggleable from the Settings dialog (Appearance tab). |
|
|
413
528
|
| `maxSubPanes` | | `3` | Max simultaneous oscillator sub-panes |
|
|
414
529
|
| `tradeDisplayFilter` | | `"all"` | Which TFC levels are visible: `"all"` · `"positions"` · `"orders"` · `"none"` |
|
|
530
|
+
| `pnlPill` | | — | `{ currency?, format?, visible? }` for the on-chart P/L pill — currency code appended to the amount, or your own formatter. Only read when `features.pnlPill` is on |
|
|
415
531
|
| `positionRenderStyle` | | auto | Force position render style: `"line"` or `"dot"` |
|
|
416
532
|
| `hideLevelConfirmCancel` | | `false` | Hide on-canvas ✓/✗ confirm-cancel buttons for TFC level edits |
|
|
417
533
|
| `deselectActiveOnOutsideClick` | | `false` | When `true`, clicking/tapping anywhere outside a selected trade level dismisses it (reverting any pending edits, mirroring ✗ Cancel). Default `false` keeps the level active so incidental clicks — price-axis resize, taps outside the QTY input — don't drop an in-progress edit. The level can still be dismissed via ✓/✗, tapping the level again, or `setLevels()` removing it |
|
|
418
534
|
| `showTradeLevelsAlways` | | `false` | Always render SL/TP bracket lines + price pills, even when the parent level is not hovered or selected. The close (×) button stays hover-only so the chart isn't cluttered. Toggleable from the Settings dialog (Trading tab). Persisted in `localStorage`. |
|
|
535
|
+
| `revealNewBrackets` | | `false` | When a level gains a **new** SL/TP — placed from the host's order panel, so it arrives via `setLevels()`, `updateLevelBracket()` or `updateDraftOrderBracket()` — whose price sits outside the visible price range, widen (compress) the price axis so the new line comes into view together with the candles already on screen. Animated, and the trader can drag or reset the axis afterwards as usual. A bracket dragged on the chart is visible by construction and never triggers it. Inert in compare (percent) mode |
|
|
419
536
|
| `tradeLevelButtonScale` | | `1` | Multiplier for trade-level Confirm/Cancel/Edit/Close button radii and gaps. Scales visuals **and** hit/drag areas together — raise it on touch devices for larger tap targets. Clamped to `[1, 3]`. Also settable at runtime via `chart.setTradeLevelButtonScale(scale)` |
|
|
537
|
+
| `tradeLevelBadgeScale` | | `1` | Shrinks the on-chart position / order tag — font, padding, grip, ✎ × buttons and their hit areas together. `0.6` is about half the default area. Clamped `[0.5, 1]` |
|
|
538
|
+
| `tradeLevelBadgeAnchor` | | `"auto"` | `"left"` homes the tag at the plot's left edge like an axis label, whatever the open price or time anchor, so it never covers candles until the trader drags it. With `features.orderLineTimeDrag` the tag stays draggable along the time axis and the drop is remembered as before |
|
|
420
539
|
| `tfcEnabled` | | `true` | Enable the TFC toggle button in the top bar. When `false`, TFC is completely disabled — the toggle button is hidden and all trade levels, draft orders, and the floating trade button are suppressed |
|
|
421
|
-
| `
|
|
540
|
+
| `crosshairEnabled` | | `true` | Draw the mouse crosshair. `false` hides it **and** the floating "place order at this price" button that rides on its horizontal line, ignores mirrored `setCrosshair()` calls and keeps the mobile long-press crosshair from arming. Trade levels, drawings and TFC are unaffected. Runtime: `chart.setCrosshairEnabled(enabled)` |
|
|
541
|
+
| `enableCrossHairHeader` | | `false` | Crosshair on/off switch in the header (advanced toolbar, default top bar, the compact per-pane strip and the mobile header): the reference `rounded-sm` button. The crosshair is on by default, so the icon starts tinted; a click hides the crosshair (and the trade button riding on it) and drops the icon to its plain state, the next click brings both back. Calls `setCrosshairEnabled()` and emits `crosshairToggle` so the host can persist the choice — see [Header crosshair switch](#header-crosshair-switch--enablecrosshairheader) |
|
|
542
|
+
| `enableCrosshairToggle` | | `false` | **Deprecated** — alias of `enableCrossHairHeader`; either flag renders the switch |
|
|
543
|
+
| `headerOverflowMenu` | | `false` | Advanced header only: the reference Hanko header. A 32px bar with six lowercase timeframe pills (`1m 5m 15m 1h 4h 1d`) and a ⌄ for the rest, then crosshair · P/L · Layout (grid icon) · ⋯ · fullscreen at 24px. Draw, Chart type, Indicators, Compare, Snapshot and Chart settings fold into the ⋯ menu; each keeps its behaviour. With `onAddAlert` set the menu also offers **Alert** (own group, before Snapshot) at the current market price |
|
|
544
|
+
| `features.orderLineTimeDrag` | | `false` | Enable **horizontal (time-axis) order-line dragging**. A level with `timeDraggable: true` (position or pending order) can have its info-box badge dragged left/right to re-anchor the order to a different candle — **price stays locked** while dragging sideways. Pending orders keep their vertical price drag: the badge's first movement picks the axis. Emits `orderLineMoved` on release. Off by default; intended to be enabled per broker (e.g. Hankotrade) by the host app |
|
|
422
545
|
| `orderLineDragSnap` | | `true` | When horizontal dragging is enabled, snap the badge to the nearest candle on release. Set `false` to keep the exact released time |
|
|
546
|
+
| `orderLineAnchorPersistence` | | `true` | When horizontal dragging is enabled, remember where each badge was dropped in `localStorage` (key `finchart.orderLineTimeAnchors`, keyed by level label) so it comes back to the same candle after a reload. A persisted anchor overrides the level's `timestamp` until the badge is dragged again. Set `false` to persist anchors yourself |
|
|
547
|
+
| `orderLineDefaultAnchor` | | `'timestamp'` | Where an un-dragged `timeDraggable` badge sits: `'timestamp'` = over the candle at the level's `timestamp`; `'center'` = the chart's horizontal center (ignores `timestamp`), so a new market order lands mid-chart. Non-draggable levels always honor `timestamp` |
|
|
423
548
|
| `levelClusteringEnabled` | | `true` | Enable trade-level fan-out clustering; overlapping levels group into expandable badges |
|
|
424
549
|
| `clusterThresholdDistance` | | `20` | Pixel proximity threshold for clustering (only when `levelClusteringEnabled` is `true`) |
|
|
425
550
|
| `hideSymbolAndTick` | | `false` | Hide the symbol name and tick-activity (streaming) dot in the top-left overlay. Does **not** affect the OHLC(V) strip — use `hideOHLCV` for that |
|
|
426
551
|
| `hideOHLCV` | | `false` | Hide the OHLC(V) data strip (`O: H: L: C: V:`) in the top-left overlay. Independent of `hideSymbolAndTick` — set both to `true` to hide the entire overlay |
|
|
427
552
|
| `showBottomBar` | | `false` | Show the bottom duration-selector bar |
|
|
553
|
+
| `features.enableScaleControls` | | `false` | Bottom-bar **Go to date**, **timezone** and **%** / **log** / **auto** cluster, left of the duration buttons. Needs `showBottomBar: true`. Off by default — see [Bottom Bar & Price Scale](#bottom-bar--price-scale) |
|
|
554
|
+
| `features.enableSidePanels` | | `false` | Right-hand docked **Data Window** / **Objects** panel (232px out of the plot). Off by default; toggle at runtime with `setSidePanelVisible()` — see [Side Panels](#side-panels) |
|
|
428
555
|
| `hideQtyButton` | | `false` | Hide the floating Qty input overlay on draft orders |
|
|
429
556
|
| `showQuantityField` | | `false` | Render an editable QTY pill at the left of the draft order info box. Clicking the pill opens a flyout input to edit the quantity before submitting |
|
|
430
557
|
| `quantityFieldConfig` | | — | Constraints for the draft order QTY field (only relevant when `showQuantityField` is `true`). Object: `{ minLots?: number, maxLots?: number }`. `minLots` also sets the initial quantity and the step value for the flyout input (default: `1`). `maxLots` caps the input (default: `100`) |
|
|
431
558
|
| `tradesThresholdForHorizontalLine` | | `2` | Level count above which render auto-switches to `"dot"` mode |
|
|
432
559
|
| `timezone` | | `"UTC"` | IANA timezone string for time-axis and crosshair labels. `"UTC"` (default), `"local"` (browser/device timezone), or any IANA string (`"America/New_York"`, `"Europe/London"`, etc.) |
|
|
433
|
-
| `canvasColors` | | — | Per-theme
|
|
560
|
+
| `canvasColors` | | — | Per-theme colour overrides for the **canvas only** (persisted from the Settings dialog; runtime: `chart.setCanvasColors()`). The surface picks — `background`, `grid`, `axisText`, `axisBorder`, `crosshair` — repaint the chart canvas and leave the chart chrome (top/bottom/left bars, dialogs, popovers) on the theme from `themeOverrides`. Series picks (`candleUp`/`candleDown`/`wickUp`/`wickDown`/`borderUp`/`borderDown`/`volumeUp`/`volumeDown`) apply everywhere, so legends and indicator pills keep tracking them |
|
|
434
561
|
| `aggregateFrom` | | — | Fetch finer-grained data and aggregate client-side per timeframe |
|
|
435
562
|
| `onOrderSubmit` | | — | Called when user submits a trade via the floating button |
|
|
436
563
|
| `onLevelEdit` | | — | Called when user confirms a TFC level edit |
|
|
437
564
|
| `onLotsChange` | | — | Called when user changes qty on a draft order |
|
|
438
565
|
| `onLevelDragEnd` | | — | *(deprecated — use `onLevelEdit`)* |
|
|
439
566
|
|
|
567
|
+
### `InstrumentSpec`
|
|
568
|
+
|
|
569
|
+
The chart reads prices, never contract specs — so a tool that reports a distance
|
|
570
|
+
in **pips**, or converts one to money, has to be told how. Pass `instrument` at
|
|
571
|
+
construction and swap it with `setInstrument()` whenever the symbol changes.
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
const chart = new ChartEngine({
|
|
575
|
+
container,
|
|
576
|
+
symbol: 'EURUSD',
|
|
577
|
+
instrument: {
|
|
578
|
+
pipSize: 0.0001, // 0.01 for JPY crosses
|
|
579
|
+
contractSize: 100_000, // units per lot
|
|
580
|
+
valuePerPoint: 1, // account-currency value of one price unit per unit
|
|
581
|
+
currencySymbol: '$',
|
|
582
|
+
},
|
|
583
|
+
});
|
|
584
|
+
|
|
585
|
+
chart.setSymbol('USDJPY').setInstrument({ pipSize: 0.01, contractSize: 100_000 });
|
|
586
|
+
```
|
|
587
|
+
|
|
588
|
+
| Field | Default | Description |
|
|
589
|
+
|---|---|---|
|
|
590
|
+
| `pipSize` | inferred | Price distance counted as one pip |
|
|
591
|
+
| `contractSize` | `1` | Units per lot (`100` for XAUUSD, `100000` for most FX pairs) |
|
|
592
|
+
| `valuePerPoint` | `1` | Account-currency value of one price unit per contract unit |
|
|
593
|
+
| `currencySymbol` | `'$'` | Prefixed to money figures |
|
|
594
|
+
|
|
595
|
+
**Every field is optional and the whole block can be omitted** — tools fall back
|
|
596
|
+
to price-only readouts, so existing integrations keep working untouched.
|
|
597
|
+
|
|
598
|
+
When `pipSize` is absent it is inferred from how many decimals the feed quotes:
|
|
599
|
+
five-decimal (`1.08531`) and three-decimal (`151.234`) feeds carry fractional
|
|
600
|
+
pips, so the pip is the second-to-last digit; two- and four-decimal feeds quote
|
|
601
|
+
whole pips. **That convention is wrong for metals, indices and crypto** — pass
|
|
602
|
+
`pipSize` explicitly if pips matter.
|
|
603
|
+
|
|
604
|
+
The same fallbacks are exported for hosts that want to compute alongside the
|
|
605
|
+
chart:
|
|
606
|
+
|
|
607
|
+
```ts
|
|
608
|
+
import { resolveInstrument, inferPipSize, toPips, toMoney } from 'acttrader-charts';
|
|
609
|
+
```
|
|
610
|
+
|
|
611
|
+
> Per-position values still travel on the individual `TradeLevel`
|
|
612
|
+
> (`contractSize` / `valuePerPoint`). `InstrumentSpec` is the chart-wide default
|
|
613
|
+
> for tools that aren't attached to a position.
|
|
614
|
+
|
|
615
|
+
### Feature flags
|
|
616
|
+
|
|
617
|
+
Newer tools ship behind `ChartConfig.features` so each host opts in. **Every flag
|
|
618
|
+
defaults to `false`** — a chart that sets none behaves exactly as it did before
|
|
619
|
+
the flag existed, including its toolbar contents.
|
|
620
|
+
|
|
621
|
+
```ts
|
|
622
|
+
const chart = new ChartEngine({
|
|
623
|
+
container,
|
|
624
|
+
features: { enableForecasting: true },
|
|
625
|
+
});
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
| Flag | Default | What it changes |
|
|
629
|
+
|---|---|---|
|
|
630
|
+
| `enableForecasting` | `false` | The reworked drawing tools, as one switch — see below |
|
|
631
|
+
| `orderLineTimeDrag` | `false` | Horizontal (time-axis) order-line dragging for positions and pending orders — see [Horizontal order-line dragging](#horizontal-time-axis-order-line-dragging) |
|
|
632
|
+
| `pnlPill` | `false` | Floating on-chart P/L pill — count and summed P/L of the positions on the chart — see [On-chart P/L pill](#on-chart-pl-pill--featurespnlpill) |
|
|
633
|
+
| `tradeActionBar` | `false` | The trade button opens a segmented `Alert · Pending · SL · TP · TSL · ×` bar at the clicked price instead of the two-row Buy/Sell popup — see [Trade action bar](#trade-action-bar--featurestradeactionbar) |
|
|
634
|
+
|
|
635
|
+
`enableForecasting` turns on three things together:
|
|
636
|
+
|
|
637
|
+
- **Long Position** / **Short Position** in a new **Forecasting** group in the
|
|
638
|
+
drawing toolbar. With the flag off the group is not rendered at all.
|
|
639
|
+
- **Brush** and **Highlighter** draw freehand — press, drag, release. Off, they
|
|
640
|
+
keep the click-per-point gesture ended by a double-click.
|
|
641
|
+
- **Ruler** reports percent, pips, calendar duration and volume. Off, it reports
|
|
642
|
+
the bar count and raw price delta as before.
|
|
643
|
+
|
|
644
|
+
They share one flag because they ship and roll back together: a broker either has
|
|
645
|
+
the reworked drawing tools or it doesn't.
|
|
646
|
+
|
|
647
|
+
Related config, independent of the flag: the position tools show quantity and
|
|
648
|
+
money only when [`account`](#accountspec) is supplied, and pips on both the
|
|
649
|
+
position tools and the ruler come from [`instrument`](#instrumentspec) — without
|
|
650
|
+
it, pip size is inferred from the feed's decimal count.
|
|
651
|
+
|
|
652
|
+
### `AccountSpec`
|
|
653
|
+
|
|
654
|
+
What the **Long / Short position** tools size themselves against.
|
|
655
|
+
|
|
656
|
+
TradingView asks the user to type these because it has no broker connection. We
|
|
657
|
+
do have one — so pass real equity and keep it current.
|
|
658
|
+
|
|
659
|
+
```ts
|
|
660
|
+
chart.setAccount({ size: 10_000, riskPercent: 1 });
|
|
661
|
+
```
|
|
662
|
+
|
|
663
|
+
| Field | Default | Description |
|
|
664
|
+
|---|---|---|
|
|
665
|
+
| `size` | — | Account equity in the account currency |
|
|
666
|
+
| `riskPercent` | `1` | Percent of the account risked per trade |
|
|
667
|
+
|
|
668
|
+
Omit the block and the position tools still draw — price, percent, pips and
|
|
669
|
+
risk/reward all render; only the quantity and money amounts are left out.
|
|
670
|
+
|
|
671
|
+
> A sketch drawn against a stale balance reports the wrong quantity rather than
|
|
672
|
+
> failing visibly, so push `setAccount()` whenever equity moves.
|
|
673
|
+
|
|
440
674
|
### `OHLCVBar`
|
|
441
675
|
|
|
442
676
|
| Field | Required | Type | Description |
|
|
@@ -477,7 +711,7 @@ import { DEFAULT_UI_CONFIG } from 'acttrader-charts';
|
|
|
477
711
|
|
|
478
712
|
| Component key | Configurable properties |
|
|
479
713
|
|---|---|
|
|
480
|
-
| `drawingToolbar` | `iconBtnSize`, `iconFontSize`, `iconFontFamily`, `flyoutLabelFontSize`, `flyoutLabelFontFamily`, `shortcutFontSize`, `soonBadgeFontSize`, `flyoutHeadingFontSize`, `flyoutHeadingLetterSpacing`, `scrollBtnHeight`, `scrollBtnFontSize`, `barPadding`, `btnGap` |
|
|
714
|
+
| `drawingToolbar` | `iconBtnSize`, `iconFontSize`, `iconFontFamily`, `flyoutLabelFontSize`, `flyoutLabelFontFamily`, `shortcutFontSize`, `soonBadgeFontSize`, `flyoutHeadingFontSize`, `flyoutHeadingLetterSpacing`, `scrollBtnHeight`, `scrollBtnFontSize`, `barPadding`, `btnGap`, `modernIcons`, `actionsButtonIcon` (`'default'` \| `'lock'` — lock glyph on the Actions button, for hosts that relabel Lock All as "Save Charts") |
|
|
481
715
|
| `topBar` | `height`, `dropBtnFontSize`, `dropBtnFontFamily`, `drawBtnSize`, `drawBtnIconFontSize`, `iconBtnSize`, `mobileIconBtnSize`, `mobileDrawBtnIconSize`, `flyoutRowFontSize`, `flyoutRowFontFamily`, `flyoutCategoryFontSize`, `flyoutCategoryLetterSpacing`, `flyoutCheckFontSize`, `streamDotSize` |
|
|
482
716
|
| `bottomBar` | `height`, `btnFontSize`, `btnFontFamily` |
|
|
483
717
|
| `priceAxis` | `fontSize`, `fontFamily` |
|
|
@@ -555,6 +789,11 @@ new ChartEngine({
|
|
|
555
789
|
| `topBar.series` | `area` | `'Area'` | |
|
|
556
790
|
| `topBar` | `indicatorsBtn` | `'Indicators'` | Indicators button (no active) |
|
|
557
791
|
| `topBar` | `indicatorsBtnActive` | `'Indicators ({count})'` | `{count}` replaced at runtime |
|
|
792
|
+
| `topBar` | `disableCrosshairTitle` | `'Disable crosshair'` | Header crosshair switch tooltip while on (`enableCrossHairHeader`) |
|
|
793
|
+
| `topBar` | `enableCrosshairTitle` | `'Enable crosshair'` | Header crosshair switch tooltip while off |
|
|
794
|
+
| `topBar` | `pnlPillBtn` | `'P/L'` | Header P/L pill switch label (`features.pnlPill`) |
|
|
795
|
+
| `topBar` | `hidePnlPillTitle` | `'Hide P/L pill for {symbol}'` | P/L switch tooltip while the pill is shown |
|
|
796
|
+
| `topBar` | `showPnlPillTitle` | `'Show P/L pill for {symbol}'` | P/L switch tooltip while the pill is hidden |
|
|
558
797
|
| `topBar` | `toggleDrawingTitle` | `'Toggle Drawing Tools'` | Toolbar toggle tooltip |
|
|
559
798
|
| `topBar` | `toggleFullscreenTitle` | `'Toggle Fullscreen'` | Fullscreen button tooltip |
|
|
560
799
|
| `topBar` | `exitFullscreenTitle` | `'Exit Fullscreen'` | |
|
|
@@ -597,6 +836,16 @@ new ChartEngine({
|
|
|
597
836
|
| `trade` | `market` | `'Market'` | |
|
|
598
837
|
| `trade` | `qty` | `'Qty'` | Draft order qty input label |
|
|
599
838
|
| `trade` | `placeOrderTitle` | `'Place order at this price'` | Trade button tooltip |
|
|
839
|
+
| `trade` | `actionAlert` … `actionTsl` | `'Alert'`, `'Pending'`, `'SL'`, `'TP'`, `'TSL'` | Trade action bar chips (`features.tradeActionBar`) |
|
|
840
|
+
| `trade` | `actionCloseTitle` | `'Close'` | Trade action bar × tooltip |
|
|
841
|
+
| `trade` | `directionAbove`, `directionBelow` | `'Above'`, `'Below'` | Pending sub-menu header — side of the market the clicked price is on |
|
|
842
|
+
| `trade` | `actionBulkNoPositionsTitle`, `actionBulkMixedTitle` | `'No open {symbol} positions'`, `'Bulk levels need all {symbol} positions in one direction'` | SL / TP / TSL chips greyed out — why |
|
|
843
|
+
| `pnlPill` | `positionsAbbrev` | `'POS'` | On-chart P/L pill — word after the count (`3 POS`), shown uppercase |
|
|
844
|
+
| `pnlPill` | `showPositionsTitle` | `'Show positions on chart · drag handle to move · double-click to reset'` | Pill tooltip while collapsed — a body click fans the positions out |
|
|
845
|
+
| `pnlPill` | `hidePositionsTitle` | `'Hide positions on chart · drag handle to move · double-click to reset'` | Pill tooltip while fanned out |
|
|
846
|
+
| `pnlPill` | `bulkLevelsTitle` | `'Set SL · TP · TSL on all {count} {symbol} positions'` | ◎ tooltip — opens the host's Bulk Levels dialog |
|
|
847
|
+
| `pnlPill` | `bulkLevelsMixedTitle` | `'Bulk levels need all {count} {symbol} positions in one direction'` | ◎ tooltip while greyed out for mixed sides |
|
|
848
|
+
| `pnlPill` | `closeAllTitle` | `'Close all {symbol} positions'` | Amber ✕ tooltip; `{symbol}` and `{count}` are filled in |
|
|
600
849
|
| `dialogs.settings` | `title` | `'Chart Settings'` | Dialog title |
|
|
601
850
|
| `dialogs.settings` | `tfcSection` | `'Trade from Charts'` | Section heading |
|
|
602
851
|
| `dialogs.settings` | `showLabel` | `'Show'` | Radio group label |
|
|
@@ -637,8 +886,8 @@ chart.setTheme('light');
|
|
|
637
886
|
|---|---|---|
|
|
638
887
|
| `background` | `string` | Canvas background color |
|
|
639
888
|
| `grid` | `string` | Grid line color |
|
|
640
|
-
| `axisText` | `string` | Axis tick label color |
|
|
641
|
-
| `axisBorder` | `string` | Axis border / separator color |
|
|
889
|
+
| `axisText` | `string` | Axis tick label color. Also the default label colour for the chart chrome (dialog text, toolbar labels) — set it via `themeOverrides` to restyle both, or via the Settings dialog to restyle the canvas axis alone |
|
|
890
|
+
| `axisBorder` | `string` | Axis border / separator color. Also the default border colour for the chart chrome (dialog frames, toolbar dividers) — same split as `axisText` |
|
|
642
891
|
| `crosshair` | `string` | Crosshair line color |
|
|
643
892
|
| `tooltip` | `{background, text, border}` | Floating label colors |
|
|
644
893
|
| `candle` | `{up, down, wickUp, wickDown}` | Candlestick colors |
|
|
@@ -673,7 +922,7 @@ chart.resetData(): this
|
|
|
673
922
|
|
|
674
923
|
**Symbol switch pattern:**
|
|
675
924
|
```ts
|
|
676
|
-
chart.setSymbol('GBPUSD').resetData();
|
|
925
|
+
chart.setSymbol('GBPUSD').setInstrument({ pipSize: 0.0001 }).resetData();
|
|
677
926
|
// … fetch new bars …
|
|
678
927
|
chart.loadData(newBars);
|
|
679
928
|
```
|
|
@@ -682,9 +931,17 @@ chart.loadData(newBars);
|
|
|
682
931
|
|
|
683
932
|
```ts
|
|
684
933
|
chart.setSeries(series: SeriesType): this
|
|
934
|
+
chart.setInstrument(spec: InstrumentSpec | undefined): this // contract specs for pips / money readouts
|
|
935
|
+
chart.getInstrument(): ResolvedInstrument // specs with fallbacks applied
|
|
936
|
+
chart.setAccount(account: AccountSpec | undefined): this // equity + risk for the position tools
|
|
937
|
+
chart.getAccount(): AccountSpec | undefined
|
|
685
938
|
chart.setTheme('dark' | 'light'): this
|
|
686
939
|
chart.setTimeframe(tf: Timeframe): this // change timeframe and reload data
|
|
687
|
-
chart.
|
|
940
|
+
chart.setDuration(d: Duration, timeframe?: Timeframe): this // select a duration; pairs the timeframe and reloads
|
|
941
|
+
chart.getDuration(): Duration | null // currently selected duration
|
|
942
|
+
chart.setBracketLabelMode(mode, currencySymbol?): this // SL/TP pills: 'price' (default) or 'amount'
|
|
943
|
+
chart.setThemeOverrides(overrides: ThemeOverrides): this // update per-theme color overrides at runtime — canvas AND chrome
|
|
944
|
+
chart.setCanvasColors(colors: ChartConfig['canvasColors'] | null): this // recolour the canvas only at runtime (same picks as the Settings dialog); null clears
|
|
688
945
|
chart.setTimezone(tz: string): this // change display timezone at runtime
|
|
689
946
|
chart.setVolume(show: boolean): this
|
|
690
947
|
```
|
|
@@ -722,6 +979,7 @@ chart.cancelCurrentEdit(): this // cancel the active draft order or any in-pro
|
|
|
722
979
|
chart.addLevelBracket(label: string, bracketType: 'sl' | 'tp'): this // auto-place a SL or TP bracket at a default offset; emits tradeLevelBracketActivated with the computed price
|
|
723
980
|
chart.setDraftBracketPnl(bracketType: 'sl' | 'tp', pnlText: string | null): this // set estimated P&L text on the active bracket host — the draft order while drafting, or the currently selected existing pending order / position while modifying; pass null to clear
|
|
724
981
|
chart.setTfcActive(enabled: boolean): this // toggle TFC on/off at runtime; hides/shows all trade levels, draft orders, and floating trade button; fires tfcToggle event
|
|
982
|
+
chart.setPnlPillVisible(visible: boolean): this // show/hide the on-chart P/L pill (features.pnlPill) — what the header's P/L switch does; emits pnlPillToggle
|
|
725
983
|
```
|
|
726
984
|
|
|
727
985
|
> **Staging semantics for `updateLevelMainPrice` / `updateLevelBracket`.** Calls to these methods register the change in the chart's pending-edit buffer (the same buffer chart-initiated drags use), so the edit stays visible even when the host app keeps pushing fresh server state via `setLevels` (e.g. per-tick PnL refreshes). When the server echoes back the new price in a later `setLevels` call, the staged edit is auto-released (mobile, i.e. `hideLevelConfirmCancel: true`). If a panel closes without submitting, call `cancelLevelEdit(label)` or `cancelCurrentEdit()` to drop the staged edit — otherwise it will keep overriding server state on the chart.
|
|
@@ -730,8 +988,39 @@ chart.setTfcActive(enabled: boolean): this // toggle TFC on/off at runtime; hi
|
|
|
730
988
|
|
|
731
989
|
```ts
|
|
732
990
|
chart.setOrderLots(lots: number): void // update default qty at runtime
|
|
991
|
+
chart.setCrosshairEnabled(enabled: boolean): this // off hides the crosshair AND this button — it rides on the crosshair line, so it has no place once the line is gone
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
The button follows the crosshair's horizontal line, so it is only ever shown while the
|
|
995
|
+
crosshair is (`crosshairEnabled`, default `true`). Hosts with a crosshair on/off control
|
|
996
|
+
should call `setCrosshairEnabled()` rather than painting the crosshair transparent — the
|
|
997
|
+
latter leaves the button riding an invisible line.
|
|
998
|
+
|
|
999
|
+
### Header crosshair switch — `enableCrossHairHeader`
|
|
1000
|
+
|
|
1001
|
+
```ts
|
|
1002
|
+
const chart = new ChartEngine({
|
|
1003
|
+
container,
|
|
1004
|
+
enableCrossHairHeader: true, // crosshair icon in the header; the crosshair itself starts on
|
|
1005
|
+
});
|
|
1006
|
+
chart.on('crosshairToggle', ({ enabled }) => saveUserPref('crosshair', enabled));
|
|
733
1007
|
```
|
|
734
1008
|
|
|
1009
|
+
With the flag on, a crosshair icon sits in the header's right cluster (advanced toolbar and
|
|
1010
|
+
default top bar) or at the end of the compact per-pane strip (`headerLayout: 'compact'`). The chart crosshair is shown as usual on load and the icon is tinted. Clicking
|
|
1011
|
+
the icon hides the crosshair — and the floating trade button that rides on it — and the icon
|
|
1012
|
+
drops to its plain state; clicking again brings both back. Each click goes through
|
|
1013
|
+
`setCrosshairEnabled()` and emits `crosshairToggle`, so a host can persist the choice and seed
|
|
1014
|
+
it on the next load with `crosshairEnabled: false`. `enableCrosshairToggle` is the deprecated
|
|
1015
|
+
name of the same flag and still works. Native wrappers get the same switch via their
|
|
1016
|
+
`enableCrossHairHeader` init option, the `onCrosshairToggle` callback and `setCrosshairEnabled()`.
|
|
1017
|
+
|
|
1018
|
+
### Native UI catalog (webview bridge only)
|
|
1019
|
+
|
|
1020
|
+
The webview bridge used by the Android and iOS wrappers posts a **`catalog`** event right after every `init` command, and again on the **`getCatalog`** command (which also works before `init`). It lists everything a native app needs to build its own header, drawing-tools sheet, indicators list and chart-settings screen: timeframes, chart types, cursors, drawing tool groups (with point counts and style fields), drawing-toolbar options, indicators (with pane and editable settings fields), the Chart Settings dialog (tabs → sections → items with types, options and defaults), canvas colour keys, price sources and limits. Every entry carries `available` (`true` = works in this version, `false` = planned). `catalogVersion` is the library version, stamped at build time.
|
|
1021
|
+
|
|
1022
|
+
Source: `src/core/mobileCatalog.ts`. `src/__tests__/mobileCatalog.test.ts` fails the build if an `available: true` id does not exist in the engine, or an engine tool / indicator is missing from the catalog — update the catalog together with any new chart type, tool or indicator. The web `ChartEngine` API is unchanged.
|
|
1023
|
+
|
|
735
1024
|
### Viewport
|
|
736
1025
|
|
|
737
1026
|
```ts
|
|
@@ -888,6 +1177,39 @@ Sub-pane heights are user-resizable by dragging the separator between panes.
|
|
|
888
1177
|
| `flatChannel` | Flat Channel | 2 clicks |
|
|
889
1178
|
| `disjointChannel` | Disjoint Channel | 3 clicks |
|
|
890
1179
|
|
|
1180
|
+
### SL/TP bracket labels — price or amount
|
|
1181
|
+
|
|
1182
|
+
By default an SL/TP pill reads `SL @4159.00` — the currency sign is never shown on
|
|
1183
|
+
a price. With `bracketLabelMode: 'amount'` it reads `SL -$290.80` — the money the
|
|
1184
|
+
position gains or loses if that bracket is hit, currency symbol in front and a
|
|
1185
|
+
minus only on a loss. `'priceAndAmount'` shows `SL @4159.00` at rest and
|
|
1186
|
+
`SL @4159.00 -$290.80` while the bracket is dragged.
|
|
1187
|
+
|
|
1188
|
+
The chart has no access to contract specs or the account currency, so each level
|
|
1189
|
+
supplies what the maths needs:
|
|
1190
|
+
|
|
1191
|
+
```ts
|
|
1192
|
+
new ChartEngine({ container, bracketLabelMode: 'amount', currencySymbol: '$' });
|
|
1193
|
+
|
|
1194
|
+
chart.setLevels([{
|
|
1195
|
+
label: 'POS-1', price: 4173.54, side: 'buy', lots: 0.20,
|
|
1196
|
+
stopLossPrice: 4159.00, takeProfitPrice: 4183.00,
|
|
1197
|
+
contractSize: 100, // units per lot (100 for XAUUSD, 100000 for most FX)
|
|
1198
|
+
valuePerPoint: 1, // account-currency value of one price unit
|
|
1199
|
+
currencySymbol: '$', // optional per-level override
|
|
1200
|
+
}], 'label', 'price', 'position');
|
|
1201
|
+
// pills render: SL -$290.80 TP $189.20
|
|
1202
|
+
```
|
|
1203
|
+
|
|
1204
|
+
```
|
|
1205
|
+
amount = (bracket − entry) × direction × lots × contractSize × valuePerPoint
|
|
1206
|
+
```
|
|
1207
|
+
|
|
1208
|
+
`valuePerPoint` is where a quote → account currency conversion goes. A level
|
|
1209
|
+
missing `lots` or `contractSize` keeps showing its price, so a partial rollout
|
|
1210
|
+
degrades level by level rather than rendering `NaN`. Toggle at runtime with
|
|
1211
|
+
`chart.setBracketLabelMode('amount')`.
|
|
1212
|
+
|
|
891
1213
|
### Fibonacci & Gann
|
|
892
1214
|
|
|
893
1215
|
`fibRetracement` · `fibExtension` · `fibChannel` · `fibTimezone` · `fibCircles` · `fibSpiral` · `fibFan` · `fibProjection` · `gannFan` · `gannSquare` · `gannBox`
|
|
@@ -920,10 +1242,78 @@ In a **per-drawing** style (`SerializedDrawing.style.levels`), a level may also
|
|
|
920
1242
|
|
|
921
1243
|
`rectangle` · `rotatedRectangle` · `ellipse` · `triangle` · `circle` · `arc` · `polyline` · `path` · `brush` · `highlighter`
|
|
922
1244
|
|
|
1245
|
+
**`brush` and `highlighter` draw freehand** when `features.enableForecasting` is on
|
|
1246
|
+
(see [Feature flags](#feature-flags)): press, drag, release — the pointer
|
|
1247
|
+
path is sampled continuously and the finished stroke is thinned to the points
|
|
1248
|
+
that carry its shape. (`polyline` and `path` remain click-per-point, ended with a
|
|
1249
|
+
double-click.)
|
|
1250
|
+
|
|
923
1251
|
### Measurements & Annotations
|
|
924
1252
|
|
|
925
1253
|
`priceRange` · `dateRange` · `datePriceRange` · `ruler` · `priceLabel` · `priceNote` · `priceProjection` · `projection` · `arrowUp` · `arrowDown` · `arrowMarker` · `text` · `callout` · `anchoredNote` · `flag` · `sineLine` · `regressionTrend` · `ghostFeed`
|
|
926
1254
|
|
|
1255
|
+
**`ruler`**, with `features.enableForecasting` on (see [Feature flags](#feature-flags)),
|
|
1256
|
+
draws a direction-tinted box over the span it measures and reports:
|
|
1257
|
+
|
|
1258
|
+
```
|
|
1259
|
+
0.00455 (0.80%) 45.5
|
|
1260
|
+
43 bars, 9d 4h
|
|
1261
|
+
Vol 102.27K
|
|
1262
|
+
```
|
|
1263
|
+
|
|
1264
|
+
Price delta, percent, and **pips**; bar count and calendar duration; volume
|
|
1265
|
+
traded across the span.
|
|
1266
|
+
|
|
1267
|
+
A pip figure is always shown — but it is only *correct* when the host supplies
|
|
1268
|
+
[`instrument.pipSize`](#instrumentspec). Without it the chart infers pip size
|
|
1269
|
+
from how many decimals the feed quotes, which follows the usual FX convention
|
|
1270
|
+
and is wrong for metals, indices and crypto.
|
|
1271
|
+
|
|
1272
|
+
Duration needs bar timestamps, and the volume line is omitted entirely when the
|
|
1273
|
+
bars carry no volume, rather than showing a `0` that would read as "no volume
|
|
1274
|
+
traded".
|
|
1275
|
+
|
|
1276
|
+
The box takes its colour from `candle.up` / `candle.down` so a measurement never
|
|
1277
|
+
disagrees with the candles underneath it; picking a colour in the style popover
|
|
1278
|
+
overrides that. All four corners resize.
|
|
1279
|
+
|
|
1280
|
+
With the flag off it reports the bar count and raw price delta, as it always has.
|
|
1281
|
+
|
|
1282
|
+
### Forecasting
|
|
1283
|
+
|
|
1284
|
+
`longPosition` · `shortPosition`
|
|
1285
|
+
|
|
1286
|
+
> Requires `features.enableForecasting` — see [Feature flags](#feature-flags).
|
|
1287
|
+
> With the flag off the group is not rendered, on the desktop toolbar or in the
|
|
1288
|
+
> mobile tools sheet.
|
|
1289
|
+
>
|
|
1290
|
+
> `ghostFeed` and `projection` stay in **Advanced Tools** and are ungated — they
|
|
1291
|
+
> predate this group.
|
|
1292
|
+
|
|
1293
|
+
**`longPosition` / `shortPosition`** sketch a trade that hasn't been placed: a
|
|
1294
|
+
green profit zone from entry to target, a red risk zone from entry to stop, and
|
|
1295
|
+
live readouts.
|
|
1296
|
+
|
|
1297
|
+
```
|
|
1298
|
+
Target: 0.00313 (0.549%) 31.3, Amount: 5622.13
|
|
1299
|
+
Open PnL: 0.00146, Qty: 11323
|
|
1300
|
+
Risk/reward ratio: 1.84
|
|
1301
|
+
Stop: 0.00170 (0.298%) 17.0, Amount: 2887.5
|
|
1302
|
+
```
|
|
1303
|
+
|
|
1304
|
+
Two clicks place it — entry, then target — and the stop lands at a 2:1
|
|
1305
|
+
reward:risk for you to drag. All three prices have handles.
|
|
1306
|
+
|
|
1307
|
+
Quantity is sized so that hitting the stop costs exactly `riskPercent` of the
|
|
1308
|
+
account, which needs [`account`](#accountspec); the money amounts and pips also
|
|
1309
|
+
need [`instrument`](#instrumentspec). Without them the tool still draws and still
|
|
1310
|
+
reports price, percent and risk/reward.
|
|
1311
|
+
|
|
1312
|
+
> **This is a drawing, not an order.** Trade-From-Chart (`setLevels`) is what
|
|
1313
|
+
> puts real broker orders on the chart — see [Trade From Chart
|
|
1314
|
+
> (TFC)](#trade-from-chart-tfc--setlevels). Nothing on a position tool reaches
|
|
1315
|
+
> the broker.
|
|
1316
|
+
|
|
927
1317
|
### Volume Profile
|
|
928
1318
|
|
|
929
1319
|
`volumeProfile` · `anchoredVP` · `fixedRangeVP`
|
|
@@ -932,6 +1322,10 @@ In a **per-drawing** style (`SerializedDrawing.style.levels`), a level may also
|
|
|
932
1322
|
|
|
933
1323
|
`cyclicLines` · `timeCycles`
|
|
934
1324
|
|
|
1325
|
+
> `ghostFeed` and `projection` remain here and are ungated. TradingView files
|
|
1326
|
+
> them under Forecasting, but moving them would have reshuffled the toolbar for
|
|
1327
|
+
> hosts that never enabled the new group.
|
|
1328
|
+
|
|
935
1329
|
### Harmonic & Elliott Patterns
|
|
936
1330
|
|
|
937
1331
|
`abcdPattern` · `headShoulders` · `trianglePattern` · `batPattern` · `butterflyPattern` · `crabPattern` · `gartleyPattern` · `cypherPattern` · `sharkPattern` · `threeDrives` · `elliottImpulse` · `elliottCorrective` · `elliottTriangle` · `elliottCombination` · `elliottWxy`
|
|
@@ -952,8 +1346,9 @@ chart.on('pan', ({ viewport }) => {});
|
|
|
952
1346
|
chart.on('timeframeChange',({ timeframe }) => {});
|
|
953
1347
|
chart.on('durationChange', ({ duration, timeframe }) => {});
|
|
954
1348
|
chart.on('seriesChange', ({ series }) => {});
|
|
1349
|
+
chart.on('priceSourceChange', ({ source }) => {}); // header BID/ASK/LTP dropdown pick
|
|
955
1350
|
chart.on('streamStatus', ({ status }) => {}); // 'connected' | 'reconnecting' | 'disconnected'
|
|
956
|
-
chart.on('dataLoaded', ({ timeframe, interval, start, end }) => {});
|
|
1351
|
+
chart.on('dataLoaded', ({ timeframe, interval, start, end, priceSource }) => {});
|
|
957
1352
|
chart.on('newBar', ({ completedBar, openingBar, intervalMs }) => {});
|
|
958
1353
|
chart.on('indicatorAdded', ({ instanceId, shortName, params }) => {}); // a study instance was added — keep instanceId to remove it later
|
|
959
1354
|
chart.on('indicatorRemoved', ({ instanceId, shortName }) => {});
|
|
@@ -976,6 +1371,10 @@ chart.on('tradeLevelEditCancelled', ({ label, type, isFullscreen }) => {}); // E
|
|
|
976
1371
|
chart.on('draftInitiated', ({ side, price, orderType, isFullscreen }) => {}); // new draft order shown — open buy/sell form
|
|
977
1372
|
chart.on('draftCancelled', ({ label, isFullscreen }) => {}); // draft order dismissed without confirming
|
|
978
1373
|
chart.on('tfcToggle', ({ enabled }) => {}); // TFC toggled on or off via top bar button or setTfcActive()
|
|
1374
|
+
chart.on('crosshairToggle', ({ enabled }) => {}); // crosshair switched on or off — header switch (enableCrossHairHeader) or setCrosshairEnabled(); persist it here
|
|
1375
|
+
chart.on('pnlPillCloseAll', ({ count, pnl, labels, data, isFullscreen }) => {}); // the on-chart P/L pill's ✕ — close these positions (features.pnlPill)
|
|
1376
|
+
chart.on('pnlPillToggle', ({ visible }) => {}); // the header's P/L switch showed or hid the pill — persist it here (features.pnlPill)
|
|
1377
|
+
chart.on('bulkLevelsRequested', ({ kind, price, source, isFullscreen }) => {}); // action-bar chip (price) or the P/L pill's ◎ (price null) — open your Bulk Levels dialog for `kind`
|
|
979
1378
|
chart.on('tradeLevelDragEnd', ({ label, type, newPrice, data }) => {}); // deprecated — use tradeLevelEdit
|
|
980
1379
|
chart.on('tradeLevelBracketDrag', ({ label, bracketType, newPrice, data }) => {}); // deprecated
|
|
981
1380
|
|
|
@@ -984,8 +1383,8 @@ chart.on('tradeLevelBracketDrag', ({ label, bracketType, newPrice, data }) => {}
|
|
|
984
1383
|
chart.on('orderLineMoveStart', ({ label, fromTimestamp, fromBarIndex, isFullscreen }) => {});
|
|
985
1384
|
chart.on('orderLineMoving', ({ label, toTimestamp, toBarIndex, isFullscreen }) => {}); // fires on every move
|
|
986
1385
|
chart.on('orderLineMoved', ({ label, fromTimestamp, toTimestamp, fromBarIndex, toBarIndex, data, isFullscreen }) => {
|
|
987
|
-
//
|
|
988
|
-
//
|
|
1386
|
+
// The chart already remembers the drop in localStorage (orderLineAnchorPersistence, default on).
|
|
1387
|
+
// Hook here only if you also want to persist the new time anchor server-side.
|
|
989
1388
|
});
|
|
990
1389
|
|
|
991
1390
|
// Fires after addLevelBracket() auto-places a bracket, delivering the computed price back to the caller
|
|
@@ -1126,45 +1525,1505 @@ The composite excludes trade levels (positions, SL/TP) — same rule as `chart.t
|
|
|
1126
1525
|
|
|
1127
1526
|
---
|
|
1128
1527
|
|
|
1129
|
-
##
|
|
1528
|
+
## Icons & Drawing Toolbar Options
|
|
1130
1529
|
|
|
1131
|
-
|
|
1530
|
+
### Icons, Emojis & Stickers — `'icon'`
|
|
1531
|
+
|
|
1532
|
+
A glyph placed at a bar and price, behind `features.enableIconTools`. **One tool,
|
|
1533
|
+
not three**: emojis, stickers and icons are the same drawing with a different
|
|
1534
|
+
character, so the picker chooses the glyph and the glyph lives in `text` like any
|
|
1535
|
+
other annotation's content. They serialise, re-anchor and re-style through
|
|
1536
|
+
machinery that already exists rather than needing three parallel implementations.
|
|
1132
1537
|
|
|
1133
1538
|
```ts
|
|
1134
|
-
|
|
1539
|
+
const chart = new ChartEngine({
|
|
1540
|
+
container,
|
|
1541
|
+
features: { enableIconTools: true },
|
|
1542
|
+
});
|
|
1543
|
+
chart.setDrawingTool('icon'); // uses the last glyph picked
|
|
1544
|
+
```
|
|
1135
1545
|
|
|
1136
|
-
|
|
1137
|
-
name = 'MyInd';
|
|
1138
|
-
color = '#e91e63';
|
|
1139
|
-
pane = 'sub' as const; // 'main' = overlay, 'sub' = dedicated pane
|
|
1140
|
-
paneHeight = 80;
|
|
1546
|
+
#### The picker
|
|
1141
1547
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1548
|
+
Opening the **Icons & Emojis** group gives a panel, not a list of rows: a row per
|
|
1549
|
+
glyph is unusable past a couple of dozen, and this is the one category whose
|
|
1550
|
+
items *are* the icon rather than being labelled by one.
|
|
1145
1551
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1552
|
+
```
|
|
1553
|
+
┌────────────────────────────────┐
|
|
1554
|
+
│ 😊 🐻 🍔 🏀 🚀 💡 ❤️ 🏳️ │ category tabs
|
|
1555
|
+
├────────────────────────────────┤
|
|
1556
|
+
│ 😀 😃 😄 😁 😆 😅 🤣 😂 │
|
|
1557
|
+
│ 🙂 🙃 😉 😊 😇 🥰 😍 🤩 │ scrolling grid
|
|
1558
|
+
├────────────────────────────────┤
|
|
1559
|
+
│ Emojis Stickers Icons │ kind tabs
|
|
1560
|
+
└────────────────────────────────┘
|
|
1561
|
+
```
|
|
1150
1562
|
|
|
1151
|
-
|
|
1563
|
+
The three bottom tabs are not three copies of the same thing:
|
|
1564
|
+
|
|
1565
|
+
| Tab | Holds | Draws as |
|
|
1566
|
+
| --- | --- | --- |
|
|
1567
|
+
| **Emojis** | ~900 across the eight Unicode groups | System colour font, 22px |
|
|
1568
|
+
| **Stickers** | Trading-flavoured sets — bull & bear, reactions, money, warnings, awards | The same characters at 44px |
|
|
1569
|
+
| **Icons** | Monochrome arrows, shapes, marks, currency | Takes the drawing's colour |
|
|
1570
|
+
|
|
1571
|
+
That last row is why **Icons** is worth having at all. An emoji is a colour
|
|
1572
|
+
bitmap in the system font: it ignores `fillStyle`, so it can never be recoloured
|
|
1573
|
+
to match a palette or printed legibly in mono. Everything under Icons is a plain
|
|
1574
|
+
text character, and does tint.
|
|
1575
|
+
|
|
1576
|
+
The panel renders into the toolbar's existing flyout rather than adding a second
|
|
1577
|
+
floating layer, so it inherits that popover's positioning, outside-click
|
|
1578
|
+
dismissal and teardown. It remembers the tab and category per session — reopening
|
|
1579
|
+
a picker to find yourself back on the first page of smileys is the single most
|
|
1580
|
+
irritating thing a picker can do.
|
|
1581
|
+
|
|
1582
|
+
#### Resizing
|
|
1583
|
+
|
|
1584
|
+
A placed icon is selectable and **resizable by dragging any of its four corner
|
|
1585
|
+
handles**. Size is also in the style popover, which offers a colour swatch and a
|
|
1586
|
+
px picker rather than the default stroke/width/style — three controls that would
|
|
1587
|
+
do nothing to a glyph.
|
|
1588
|
+
|
|
1589
|
+
```ts
|
|
1590
|
+
chart.getDrawings()
|
|
1591
|
+
.filter(d => d.type === 'icon')
|
|
1592
|
+
.forEach(d => { d.style = { ...d.style, fontSize: 64 }; });
|
|
1593
|
+
```
|
|
1594
|
+
|
|
1595
|
+
**The size is in pixels, not price.** It does not rescale when the chart is
|
|
1596
|
+
zoomed. Deriving it from two data points would have fit the existing drag
|
|
1597
|
+
machinery with no new concepts, but a pin dropped on a bar would then become a
|
|
1598
|
+
billboard three zoom steps out and vanish three steps in — and the user would
|
|
1599
|
+
have to resize it again every time they changed the view. So `DrawingHandle`
|
|
1600
|
+
grew a `mode: 'size'`, and handles marked that way route to
|
|
1601
|
+
`IDrawing.resizeToPixel(px, py)` instead of the point writer.
|
|
1602
|
+
|
|
1603
|
+
`resizeToPixel` takes pixels because the size it sets is in pixels — converting
|
|
1604
|
+
through price and back would make the result depend on the zoom level it was
|
|
1605
|
+
dragged at. It measures against the anchor position cached during `render`,
|
|
1606
|
+
which is the only place a drawing is handed the scale.
|
|
1607
|
+
|
|
1608
|
+
The new size is the larger of the two axis distances, not the diagonal, so
|
|
1609
|
+
pulling straight out sideways grows the glyph as much as pulling corner to
|
|
1610
|
+
corner. A glyph is square; a user dragging one edge means "bigger", not "bigger
|
|
1611
|
+
by cos 45°". Clamped to 10–400px and rounded, since the value is shown in a px
|
|
1612
|
+
picker and round-trips through JSON.
|
|
1613
|
+
|
|
1614
|
+
Glyphs render through the system emoji font, so colour emoji stay colour on every
|
|
1615
|
+
platform that has them.
|
|
1616
|
+
|
|
1617
|
+
### Drawing toolbar options
|
|
1618
|
+
|
|
1619
|
+
Five toggles in the toolbar's actions menu (⋯).
|
|
1620
|
+
|
|
1621
|
+
| Option | What it does |
|
|
1622
|
+
| --- | --- |
|
|
1623
|
+
| **Magnet Mode** | Drawing points snap to the nearest open/high/low/close of the bar under the cursor. |
|
|
1624
|
+
| **Keep Drawing Mode** | The tool stays armed after each drawing, so a series can be placed without returning to the toolbar. |
|
|
1625
|
+
| **Copy to All Charts** | New drawings are announced for replication across a layout. |
|
|
1626
|
+
| **Hide Drawings Toolbar** | Hides the toolbar at runtime; bring it back with `setDrawingToolbarVisible(true)`. |
|
|
1627
|
+
| **Zoom In** | In the Cursors group — drag a box and the chart zooms to it. |
|
|
1628
|
+
|
|
1629
|
+
```ts
|
|
1630
|
+
const chart = new ChartEngine({
|
|
1631
|
+
container,
|
|
1632
|
+
magnetMode: true,
|
|
1633
|
+
keepDrawingMode: true,
|
|
1634
|
+
copyDrawingsToAllCharts: true,
|
|
1635
|
+
});
|
|
1636
|
+
|
|
1637
|
+
chart.setMagnetMode(false);
|
|
1638
|
+
chart.on('magnetModeChange', ({ enabled }) => persist(enabled));
|
|
1639
|
+
```
|
|
1640
|
+
|
|
1641
|
+
**Magnet snaps within a pixel threshold, not always.** A trend line deliberately
|
|
1642
|
+
drawn through the middle of a range should stay there. The threshold is in
|
|
1643
|
+
pixels rather than price so it feels identical at every zoom — a price-space
|
|
1644
|
+
tolerance would snap from far away on a zoomed-out chart and never trigger on a
|
|
1645
|
+
zoomed-in one.
|
|
1646
|
+
|
|
1647
|
+
**Keep-drawing mode routes through one place.** There are four separate
|
|
1648
|
+
completion paths in the drawing manager; a mode that held for only some of them
|
|
1649
|
+
would look broken in exactly the cases a user reached for it.
|
|
1650
|
+
|
|
1651
|
+
**Copy-to-all is announced, not performed.** The chart emits `drawingCreated`
|
|
1652
|
+
with `copyToAll`, because only the host knows which other panes exist:
|
|
1653
|
+
|
|
1654
|
+
```ts
|
|
1655
|
+
chart.on('drawingCreated', ({ drawing, copyToAll }) => {
|
|
1656
|
+
if (copyToAll) group.broadcastDrawing(drawing, thisPaneId);
|
|
1657
|
+
});
|
|
1152
1658
|
```
|
|
1153
1659
|
|
|
1660
|
+
`ChartGroup.broadcastDrawing(drawing, fromPaneId?)` hands the payload to every
|
|
1661
|
+
other pane's `ChartEngine.addDrawing(drawing)`. Unlike `broadcastSymbol` there
|
|
1662
|
+
is no `LayoutSyncState` flag gating it — the toggle already lives on the chart
|
|
1663
|
+
the user drew on, and that is what `copyToAll` reports.
|
|
1664
|
+
|
|
1665
|
+
`addDrawing` **appends and is undoable**, where `setState` would replace the
|
|
1666
|
+
list and flatten the target pane's history. Each pane's copy also gets a fresh
|
|
1667
|
+
id, so dragging the mirrored drawing in one pane leaves the others alone.
|
|
1668
|
+
|
|
1669
|
+
**Zoom In is a drawing internally.** It reuses the two-point press-preview-release
|
|
1670
|
+
gesture rather than duplicating it as a bespoke drag mode, then applies the zoom
|
|
1671
|
+
and removes itself — so nothing is left on the chart and it never reaches
|
|
1672
|
+
`ChartState`. It sets *both* axes: zooming only time would leave the chosen
|
|
1673
|
+
prices no larger than before, which is not what dragging a box asks for.
|
|
1674
|
+
|
|
1675
|
+
### Native wrapper parity
|
|
1676
|
+
|
|
1677
|
+
`'icon'` and `'zoomIn'` are `DrawingToolType` strings and need no wrapper change.
|
|
1678
|
+
The toolbar options are new bridge commands — see
|
|
1679
|
+
[charts-android](../charts-android) and [charts-ios](../charts-ios).
|
|
1680
|
+
|
|
1154
1681
|
---
|
|
1155
1682
|
|
|
1156
|
-
##
|
|
1683
|
+
## Notes & Text
|
|
1157
1684
|
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1685
|
+
Six annotation tools, all single-click: place, then type.
|
|
1686
|
+
|
|
1687
|
+
| Tool | `DrawingToolType` | Form |
|
|
1688
|
+
| --- | --- | --- |
|
|
1689
|
+
| **Anchored Text** | `'anchoredText'` | Free text with a dot on the bar and price it refers to. |
|
|
1690
|
+
| **Note** | `'note'` | A compact page marker with the text beside it. |
|
|
1691
|
+
| **Pin** | `'pin'` | A teardrop whose **tip** sits exactly on the price. |
|
|
1692
|
+
| **Table** | `'table'` | Rows of text in a bordered grid. |
|
|
1693
|
+
| **Comment** | `'comment'` | A rounded speech bubble with its tail on the anchor. |
|
|
1694
|
+
| **Signpost** | `'signpost'` | A plaque on a post, rising clear of the candles. |
|
|
1695
|
+
|
|
1696
|
+
```ts
|
|
1697
|
+
chart.setDrawingTool('signpost');
|
|
1698
|
+
```
|
|
1699
|
+
|
|
1700
|
+
All six anchor to a bar and price like every other drawing, so they re-anchor
|
|
1701
|
+
correctly after a data reload and serialise into `ChartState` unchanged.
|
|
1702
|
+
|
|
1703
|
+
### Editing
|
|
1704
|
+
|
|
1705
|
+
| | |
|
|
1706
|
+
| --- | --- |
|
|
1707
|
+
| **Place** | Click — the editor opens focused |
|
|
1708
|
+
| **Re-edit** | Select, then double-click |
|
|
1709
|
+
| **New line** | `Enter` (multi-line tools) |
|
|
1710
|
+
| **Commit** | `Ctrl`/`⌘`+`Enter`, or click away |
|
|
1711
|
+
| **Discard** | `Escape` |
|
|
1712
|
+
|
|
1713
|
+
**Anchored Text, Note, Table, Comment and Signpost get a multi-line editor**;
|
|
1714
|
+
Text, Callout, Anchored Note and Pin keep the single-line field where `Enter`
|
|
1715
|
+
commits, exactly as before. A Table is unusable without this — its rows *are*
|
|
1716
|
+
newlines, so `Enter` has to insert one.
|
|
1717
|
+
|
|
1718
|
+
The box grows with its content as you type, so adding rows is visible rather
|
|
1719
|
+
than feeling like it has a row limit.
|
|
1720
|
+
|
|
1721
|
+
### Why these are separate tools rather than one with options
|
|
1722
|
+
|
|
1723
|
+
The shape *is* the choice. Someone reaching for a Pin wants a precise marker at
|
|
1724
|
+
a level; someone reaching for a Signpost wants a dated flag that does not cover
|
|
1725
|
+
the candles; someone reaching for a Table wants several values at once.
|
|
1726
|
+
Collapsing them into "text with a style dropdown" would make each one harder to
|
|
1727
|
+
reach than the thing it replaced.
|
|
1728
|
+
|
|
1729
|
+
### Details worth knowing
|
|
1730
|
+
|
|
1731
|
+
**Table syntax** — newlines are rows and `|` separates columns, so a table is
|
|
1732
|
+
typed into the same single text field as everything else rather than needing a
|
|
1733
|
+
bespoke editor. The first row is tinted as a header; short rows are padded so the
|
|
1734
|
+
grid stays rectangular, and empty cells are kept (clearing a value is editing the
|
|
1735
|
+
table, not asking for the column to vanish).
|
|
1736
|
+
|
|
1737
|
+
**A new table arrives already a grid** — four rows by two columns, with the
|
|
1738
|
+
syntax visible in the editor:
|
|
1739
|
+
|
|
1740
|
+
```
|
|
1741
|
+
Level | Price
|
|
1742
|
+
Entry |
|
|
1743
|
+
Stop |
|
|
1744
|
+
Target |
|
|
1164
1745
|
```
|
|
1165
1746
|
|
|
1747
|
+
That is deliberate. An empty table rendered a single placeholder row and opened a
|
|
1748
|
+
blank editor, so nothing told you rows are newlines and columns are `|` — the
|
|
1749
|
+
tool looked as though it had no rows or columns at all. Overtyping a grid is also
|
|
1750
|
+
faster than building one from nothing.
|
|
1751
|
+
|
|
1752
|
+
**Pin anchors by its tip, not its centre.** A marker whose middle sits on the
|
|
1753
|
+
level is ambiguous about which price it means.
|
|
1754
|
+
|
|
1755
|
+
**Anchored Text vs Text** — plain `text` floats with no indication of what it
|
|
1756
|
+
refers to. Anchored Text draws its anchor, so a note about one specific candle
|
|
1757
|
+
still points at that candle after panning and zooming.
|
|
1758
|
+
|
|
1759
|
+
**Comment vs Callout** — `callout` is a square-cornered box with a straight
|
|
1760
|
+
pointer; `comment` is the softer rounded bubble. Both are kept because the
|
|
1761
|
+
difference is exactly what the user is choosing between.
|
|
1762
|
+
|
|
1763
|
+
Empty tools render a placeholder (`Text`, `Note`, `Event`…) rather than nothing,
|
|
1764
|
+
so a drawing placed but not yet typed into is still visible and selectable.
|
|
1765
|
+
|
|
1766
|
+
### Native wrapper parity
|
|
1767
|
+
|
|
1768
|
+
All six are `DrawingToolType` strings, so `setDrawingTool('pin')` works on
|
|
1769
|
+
[charts-android](../charts-android) and [charts-ios](../charts-ios) with no
|
|
1770
|
+
wrapper change.
|
|
1771
|
+
|
|
1166
1772
|
---
|
|
1167
1773
|
|
|
1168
|
-
##
|
|
1774
|
+
## Indicator Library
|
|
1169
1775
|
|
|
1170
|
-
|
|
1776
|
+
**78 studies added**, taking the library from 30 to 108.
|
|
1777
|
+
|
|
1778
|
+
```ts
|
|
1779
|
+
chart.addIndicatorByName('TRIX');
|
|
1780
|
+
chart.addIndicatorByName('Vortex');
|
|
1781
|
+
```
|
|
1782
|
+
|
|
1783
|
+
They appear in the Indicators flyout alongside the originals, grouped by the
|
|
1784
|
+
same categories, and each is configurable through the settings dialog.
|
|
1785
|
+
|
|
1786
|
+
### How they are registered
|
|
1787
|
+
|
|
1788
|
+
The original thirty are registered by hand in three places — a preset list, a
|
|
1789
|
+
param-schema list, and `indicators.json`. Repeating that seventy-eight times
|
|
1790
|
+
would be seventy-eight chances to register an indicator in two places and not
|
|
1791
|
+
the third, which fails *silently*: the tool appears in the menu and does
|
|
1792
|
+
nothing, or computes and never appears.
|
|
1793
|
+
|
|
1794
|
+
So each new indicator is declared once in `indicators/registry.ts` and the three
|
|
1795
|
+
views are derived:
|
|
1796
|
+
|
|
1797
|
+
```ts
|
|
1798
|
+
{
|
|
1799
|
+
shortName: 'TRIX', name: 'TRIX', type: 'Momentum',
|
|
1800
|
+
fields: [periodField(18), colorField('#00BFA5'), sourceField()],
|
|
1801
|
+
factory: (p) => new SimpleOscillator('TRIX', p.color, …),
|
|
1802
|
+
}
|
|
1803
|
+
```
|
|
1804
|
+
|
|
1805
|
+
### Shared foundations
|
|
1806
|
+
|
|
1807
|
+
| Module | What it holds |
|
|
1808
|
+
| --- | --- |
|
|
1809
|
+
| `indicators/math.ts` | `sma`, `ema`, `rma`, `wma`, `hma`, `vwma`, `alma`, `dema`, `tema`, `mcginley`, `lsma`, `stdev`, `standardError`, `correlation`, `atr`, … |
|
|
1810
|
+
| `indicators/base.ts` | `LineIndicatorBase`, `BandIndicatorBase`, `HistogramIndicatorBase` |
|
|
1811
|
+
|
|
1812
|
+
All exported, so a host can compute the same series off-chart.
|
|
1813
|
+
|
|
1814
|
+
Two conventions the maths holds to throughout:
|
|
1815
|
+
|
|
1816
|
+
- **`null` means undefined and propagates.** An EMA of an RSI is null wherever
|
|
1817
|
+
the RSI is. Returning `0` instead would draw a line through a period where the
|
|
1818
|
+
indicator does not exist, which reads as data and is not.
|
|
1819
|
+
- **`stdev` is the population form**, because Bollinger Bands and everything
|
|
1820
|
+
derived from them are defined that way; using `n−1` shifts every band visibly
|
|
1821
|
+
on short periods.
|
|
1822
|
+
|
|
1823
|
+
### The comparative studies
|
|
1824
|
+
|
|
1825
|
+
**Correlation Coefficient**, **Correlation – Log**, **Ratio**, **Spread** and
|
|
1826
|
+
**Advance/Decline** are undefined against a single series — they need a second
|
|
1827
|
+
instrument. `IIndicator.compute` gained an optional second argument for this:
|
|
1828
|
+
|
|
1829
|
+
```ts
|
|
1830
|
+
compute(data: OHLCVBar[], context?: IndicatorComputeContext): IndicatorResult[]
|
|
1831
|
+
```
|
|
1832
|
+
|
|
1833
|
+
`context.compares` carries the bars for each symbol added through the Compare
|
|
1834
|
+
feature. The parameter is optional, so every existing indicator is unaffected.
|
|
1835
|
+
|
|
1836
|
+
**With no compare symbol added, these draw nothing.** Substituting a stand-in
|
|
1837
|
+
series — correlating price against its own average, say — would produce a
|
|
1838
|
+
confident-looking line answering a different question than the indicator's name
|
|
1839
|
+
promises.
|
|
1840
|
+
|
|
1841
|
+
### Two things worth knowing
|
|
1842
|
+
|
|
1843
|
+
**Volume Profile Visible Range** distributes each bar's real volume across the
|
|
1844
|
+
price levels that bar actually traded through, and marks the Point of Control.
|
|
1845
|
+
The existing `anchoredVP` *drawing tool* is a different thing: its bar heights
|
|
1846
|
+
come from a hardcoded bell curve, not from the feed.
|
|
1847
|
+
|
|
1848
|
+
**`maxSubPanes` caps concurrent sub-pane indicators.** Most of these 78 live in
|
|
1849
|
+
their own pane, so adding many at once silently stops at the cap. Raise
|
|
1850
|
+
`maxSubPanes` if you need more on screen together.
|
|
1851
|
+
|
|
1852
|
+
### Native wrapper parity
|
|
1853
|
+
|
|
1854
|
+
All 78 are reachable through the existing `addIndicator` bridge command by short
|
|
1855
|
+
name — no wrapper change:
|
|
1856
|
+
|
|
1857
|
+
```kotlin
|
|
1858
|
+
chartView.addIndicatorByName("TRIX")
|
|
1859
|
+
```
|
|
1860
|
+
|
|
1861
|
+
### What was added
|
|
1862
|
+
|
|
1863
|
+
| Group | Studies |
|
|
1864
|
+
| --- | --- |
|
|
1865
|
+
| Moving averages (14) | ALMA, DEMA, TEMA, LSMA, McGinley, SMMA, VWMA, Hamming, Adaptive (KAMA), MA Channel, MA Double, MA Triple, MA Multiple, Guppy |
|
|
1866
|
+
| Momentum (23) | Accelerator, ASI, Balance of Power, CMO, Connors RSI, Coppock, DPO, Fisher, KST, Majority Rule, Momentum, Price Oscillator, Rank Correlation, Relative Vigor, SMI Ergodic, TRIX, TSI, Ultimate, Correlation, Correlation Log, + crosses |
|
|
1867
|
+
| Volatility (16) | %B, BB Width, Historical, Close-to-Close, Zero Trend, O-H-L-C, Volatility Index, StdDev, StdError, StdError Bands, Choppiness, Chop Zone, Chaikin Volatility, Mass Index, RVI, Envelopes |
|
|
1868
|
+
| Trend (12) | Aroon, DMI, Vortex, Trend Strength, LinReg Slope, Price Channel, Chande Kroll, 52W H/L, Alligator, Fractal, Zig Zag, MA/EMA crosses |
|
|
1869
|
+
| Volume (9) | Ease of Movement, Elder's Force, Klinger, Volume Oscillator, Net Volume, PVT, Chaikin Oscillator, Advance/Decline, VPVR |
|
|
1870
|
+
| Price transforms (4) | Average Price, Median Price, Typical Price, Ratio, Spread |
|
|
1871
|
+
|
|
1872
|
+
---
|
|
1873
|
+
|
|
1874
|
+
## Shapes & Arrows
|
|
1875
|
+
|
|
1876
|
+
### Already shipped: the line arrow
|
|
1877
|
+
|
|
1878
|
+
**`'arrowMarker'`** is TradingView's Arrow — a line from tail to tip with a
|
|
1879
|
+
filled arrowhead. It was only ever *labelled* "Arrow Marker", which hid it. The
|
|
1880
|
+
label now reads **Arrow**.
|
|
1881
|
+
|
|
1882
|
+
The `DrawingToolType` string is unchanged, and labels are i18n-overridable
|
|
1883
|
+
through `labels.drawingToolbar.tools`, so nothing breaks — but it is a
|
|
1884
|
+
user-visible string change worth knowing about.
|
|
1885
|
+
|
|
1886
|
+
### Arrow Mark Left / Right — `'arrowMarkLeft'`, `'arrowMarkRight'`
|
|
1887
|
+
|
|
1888
|
+
Single-click marks that point *at* a price level from the side — the horizontal
|
|
1889
|
+
siblings of `arrowUp` / `arrowDown`. Where those call out a move's direction,
|
|
1890
|
+
these call out a level: the arm runs along the price, so the mark reads as "this
|
|
1891
|
+
price, from the left" rather than "up from here".
|
|
1892
|
+
|
|
1893
|
+
Fixed pixel geometry, not price-space — a marker is chrome and should stay the
|
|
1894
|
+
same size whatever the axis is doing. The hit box covers the whole glyph, stem
|
|
1895
|
+
and head, so you grab what you can see.
|
|
1896
|
+
|
|
1897
|
+
### Curve — `'curve'`
|
|
1898
|
+
|
|
1899
|
+
Two endpoints and a handle that bends the line between them: a **quadratic
|
|
1900
|
+
Bézier**, not a circular arc.
|
|
1901
|
+
|
|
1902
|
+
The existing `'arc'` tool fits a circle through three points, and a circle's
|
|
1903
|
+
curvature is constant — it cannot leave one endpoint steeply and arrive at the
|
|
1904
|
+
other gently. A Bézier can, which is what you want for sketching a rounding top
|
|
1905
|
+
or a decelerating trend.
|
|
1906
|
+
|
|
1907
|
+
One handle is exactly what a quadratic takes, so every position you can drag to
|
|
1908
|
+
maps to a curve, and every curve the tool can draw is reachable by dragging. A
|
|
1909
|
+
cubic would need a second handle to be fully controllable, or would hide half its
|
|
1910
|
+
shape. The handle and its guides are drawn only while selected.
|
|
1911
|
+
|
|
1912
|
+
### Double Curve — `'doubleCurve'`
|
|
1913
|
+
|
|
1914
|
+
An S, from the same three clicks as a single Curve. The chord is split at its
|
|
1915
|
+
midpoint and each half gets its own quadratic, bent by equal and **opposite**
|
|
1916
|
+
offsets — so one handle controls both bends, and dragging across the chord
|
|
1917
|
+
inverts the S.
|
|
1918
|
+
|
|
1919
|
+
Deriving the second bend from the first, rather than asking for a fourth click,
|
|
1920
|
+
is the point: an S whose halves are set independently is just two curves. The
|
|
1921
|
+
shape only reads as one gesture if the halves stay symmetric, and making that
|
|
1922
|
+
automatic is cheaper for the user than making it their job.
|
|
1923
|
+
|
|
1924
|
+
### Curve maths
|
|
1925
|
+
|
|
1926
|
+
Exported, so a host can reproduce the same geometry:
|
|
1927
|
+
|
|
1928
|
+
```ts
|
|
1929
|
+
import { quadraticAt, controlFromOffset, offsetFromHandle } from 'acttrader-charts';
|
|
1930
|
+
```
|
|
1931
|
+
|
|
1932
|
+
`controlFromOffset` and `offsetFromHandle` are **true inverses**, both speaking
|
|
1933
|
+
in *apex* distance — how far the curve itself lands from the chord, not how far
|
|
1934
|
+
the control point does. A quadratic's apex sits halfway between chord and
|
|
1935
|
+
control, so the conversion doubles in one direction and halves in the other.
|
|
1936
|
+
|
|
1937
|
+
### Native wrapper parity
|
|
1938
|
+
|
|
1939
|
+
All four are `DrawingToolType` strings, so `setDrawingTool('doubleCurve')` works
|
|
1940
|
+
on [charts-android](../charts-android) and [charts-ios](../charts-ios) with no
|
|
1941
|
+
wrapper change.
|
|
1942
|
+
|
|
1943
|
+
---
|
|
1944
|
+
|
|
1945
|
+
## Projection & Measurement
|
|
1946
|
+
|
|
1947
|
+
### Already shipped: Long Position / Short Position
|
|
1948
|
+
|
|
1949
|
+
`'longPosition'` and `'shortPosition'` exist today and are complete risk/reward
|
|
1950
|
+
tools: three prices (entry, target, stop) drawn as a green profit zone and a red
|
|
1951
|
+
risk zone, with the money and quantity the account's risk budget implies. You
|
|
1952
|
+
place entry and target; the stop is materialised from the default reward:risk, so
|
|
1953
|
+
the common case is two clicks rather than three.
|
|
1954
|
+
|
|
1955
|
+
They are gated behind `features.enableForecasting` and need `account` for money
|
|
1956
|
+
and quantity, and `instrument` for pips:
|
|
1957
|
+
|
|
1958
|
+
```ts
|
|
1959
|
+
new ChartEngine({
|
|
1960
|
+
container,
|
|
1961
|
+
features: { enableForecasting: true },
|
|
1962
|
+
account: { equity: 50_000, riskPercent: 1 },
|
|
1963
|
+
});
|
|
1964
|
+
```
|
|
1965
|
+
|
|
1966
|
+
Deliberately **not** Trade-From-Chart — `setLevels` draws real broker orders and
|
|
1967
|
+
committing one sends it. These are drawings; nothing here reaches the broker.
|
|
1968
|
+
|
|
1969
|
+
### Anchored VWAP — `'anchoredVwap'`
|
|
1970
|
+
|
|
1971
|
+
Volume-weighted average price accumulated from a bar you pick: the average price
|
|
1972
|
+
everyone who traded since the anchor actually paid, which is what turns a swing
|
|
1973
|
+
high or an earnings gap into support.
|
|
1974
|
+
|
|
1975
|
+
**This is not the existing `'anchoredVP'`.** That one is Anchored Volume
|
|
1976
|
+
*Profile* — a horizontal histogram of volume by price level, and its bar heights
|
|
1977
|
+
come from a hardcoded bell curve rather than from the feed. Anchored VWAP is a
|
|
1978
|
+
single line computed from real volume.
|
|
1979
|
+
|
|
1980
|
+
Placed with one click, re-accumulating as data streams in. The series is
|
|
1981
|
+
exported:
|
|
1982
|
+
|
|
1983
|
+
```ts
|
|
1984
|
+
import { anchoredVwapSeries } from 'acttrader-charts';
|
|
1985
|
+
|
|
1986
|
+
const vwap = anchoredVwapSeries(bars, anchorIndex); // number[] | null
|
|
1987
|
+
```
|
|
1988
|
+
|
|
1989
|
+
Two deliberate behaviours:
|
|
1990
|
+
|
|
1991
|
+
- It uses the **(H+L+C)/3 typical price**, the convention VWAP is defined on —
|
|
1992
|
+
not the close, which would make it a volume-weighted close.
|
|
1993
|
+
- It returns **`null` when the span carries no volume**, and the chart draws no
|
|
1994
|
+
line. A VWAP without volume silently degrades into a running mean of typical
|
|
1995
|
+
prices: it looks like a VWAP and is not one. A volume-less feed gets no line
|
|
1996
|
+
rather than a plausible wrong one. The anchor dot is still drawn, so the
|
|
1997
|
+
drawing stays selectable and deletable.
|
|
1998
|
+
|
|
1999
|
+
### Forecast — `'forecast'`
|
|
2000
|
+
|
|
2001
|
+
Three points: p1→p2 is what happened, p2→p3 is what you expect next. The base is
|
|
2002
|
+
solid, the forecast dashed, and a shaded cone opens from zero at p2 to half the
|
|
2003
|
+
base move's size at p3 — because a projection is exact where it starts and vague
|
|
2004
|
+
where it ends, and a bare line implies a precision no forecast has. A readout
|
|
2005
|
+
gives the projected change in price, percent and bars.
|
|
2006
|
+
|
|
2007
|
+
That cone is what separates it from the existing `'projection'` tool, which
|
|
2008
|
+
extrapolates a trend line to the right edge with no second leg you control and no
|
|
2009
|
+
statement of confidence.
|
|
2010
|
+
|
|
2011
|
+
### Bars Pattern — `'barsPattern'`
|
|
2012
|
+
|
|
2013
|
+
Three points: p1 and p2 bracket the bars to copy, p3 anchors the copy. It draws
|
|
2014
|
+
real candles from the source bars, re-based by price **offset** rather than ratio
|
|
2015
|
+
— the tool is for asking "the same move, from here", not "a proportional move".
|
|
2016
|
+
|
|
2017
|
+
The copy is drawn at reduced alpha inside a dashed bounding box. Without that it
|
|
2018
|
+
renders in the chart's own candle colours and becomes indistinguishable from real
|
|
2019
|
+
data, which is worse than useless.
|
|
2020
|
+
|
|
2021
|
+
### Native wrapper parity
|
|
2022
|
+
|
|
2023
|
+
All three new tools are `DrawingToolType` strings, so `setDrawingTool('forecast')`
|
|
2024
|
+
works on [charts-android](../charts-android) and [charts-ios](../charts-ios) with
|
|
2025
|
+
no wrapper change. Long/Short Position need `enableForecasting` in the native
|
|
2026
|
+
`init` payload, which both wrappers already expose.
|
|
2027
|
+
|
|
2028
|
+
---
|
|
2029
|
+
|
|
2030
|
+
## Patterns
|
|
2031
|
+
|
|
2032
|
+
### XABCD Pattern — `'xabcdPattern'`
|
|
2033
|
+
|
|
2034
|
+
The free-form harmonic, and the only one that shows its working.
|
|
2035
|
+
|
|
2036
|
+
Every named harmonic in the library — Gartley, Bat, Butterfly, Crab, Shark,
|
|
2037
|
+
Cypher — draws the identical X→A→B→C→D zigzag and dashed XD line, differing only
|
|
2038
|
+
in colour. None of them measures or validates anything. XABCD assumes nothing
|
|
2039
|
+
instead: you place five pivots and it reports the ratios those pivots actually
|
|
2040
|
+
produce, so you can decide which harmonic the structure matches.
|
|
2041
|
+
|
|
2042
|
+
That measurement is the whole point. Without it this would be an existing tool
|
|
2043
|
+
under a new name.
|
|
2044
|
+
|
|
2045
|
+
| Ratio | Measured against | Why it matters |
|
|
2046
|
+
| --- | --- | --- |
|
|
2047
|
+
| `AB/XA` | the initial leg | the first retracement |
|
|
2048
|
+
| `BC/AB` | the AB leg | the counter-move |
|
|
2049
|
+
| `CD/BC` | the BC leg | the final leg's extension |
|
|
2050
|
+
| `AD/XA` | the whole XA move | what separates a Gartley (0.786) from a Butterfly (1.27) |
|
|
2051
|
+
|
|
2052
|
+
It also shades the XAB and BCD triangles, which is what makes the shape readable
|
|
2053
|
+
at a glance — the zigzag alone is just four lines.
|
|
2054
|
+
|
|
2055
|
+
The arithmetic is exported, so a host can auto-classify a pattern with the same
|
|
2056
|
+
numbers the chart draws:
|
|
2057
|
+
|
|
2058
|
+
```ts
|
|
2059
|
+
import { xabcdRatios } from 'acttrader-charts';
|
|
2060
|
+
|
|
2061
|
+
const chips = xabcdRatios(drawing.points);
|
|
2062
|
+
// → [{ from: 1, to: 2, text: 'AB/XA 0.600' }, …]
|
|
2063
|
+
```
|
|
2064
|
+
|
|
2065
|
+
A leg of zero length has no defined ratio against it, so that entry is **omitted**
|
|
2066
|
+
rather than printed as `Infinity` or `NaN`, and ratios for pivots you have not
|
|
2067
|
+
placed yet simply do not appear.
|
|
2068
|
+
|
|
2069
|
+
### Elliott Triple Combo (WXYXZ) — `'elliottTripleCombo'`
|
|
2070
|
+
|
|
2071
|
+
The triple three: three corrective structures joined by two X waves, six points
|
|
2072
|
+
from an origin.
|
|
2073
|
+
|
|
2074
|
+
There are now three neighbouring tools and the distinction is exact:
|
|
2075
|
+
|
|
2076
|
+
| Tool | Points | Labels |
|
|
2077
|
+
| --- | --- | --- |
|
|
2078
|
+
| `'elliottWxy'` | 4 | the **double** three — W, X, Y |
|
|
2079
|
+
| `'elliottCombination'` | 7 | W, X, Y, X2, Z, X3, end |
|
|
2080
|
+
| `'elliottTripleCombo'` | 6 | 0, W, X, Y, X, Z |
|
|
2081
|
+
|
|
2082
|
+
You asked whether the existing Combination tool already covers this. It partly
|
|
2083
|
+
does — but it takes **seven** points where a triple three has six, and numbers its
|
|
2084
|
+
connectors `X2`/`X3` where Elliott notation leaves both as `X`. A trader counting
|
|
2085
|
+
a triple three places five waves after the origin, and a tool demanding six
|
|
2086
|
+
leaves them with a pivot to park somewhere meaningless. This tool matches the
|
|
2087
|
+
count and the notation; the Combination tool is unchanged.
|
|
2088
|
+
|
|
2089
|
+
Wave labels sit above a peak and below a trough, so they never land on the line
|
|
2090
|
+
that produced them.
|
|
2091
|
+
|
|
2092
|
+
### Native wrapper parity
|
|
2093
|
+
|
|
2094
|
+
Both are new `DrawingToolType` strings, so `setDrawingTool('xabcdPattern')` works
|
|
2095
|
+
on [charts-android](../charts-android) and [charts-ios](../charts-ios) with no
|
|
2096
|
+
wrapper change.
|
|
2097
|
+
|
|
2098
|
+
---
|
|
2099
|
+
|
|
2100
|
+
## Fibonacci & Gann
|
|
2101
|
+
|
|
2102
|
+
Five tools added for TradingView parity. Each exists because it answers a
|
|
2103
|
+
question an existing tool in the same group cannot.
|
|
2104
|
+
|
|
2105
|
+
| Tool | `DrawingToolType` | Points | vs. its neighbour |
|
|
2106
|
+
| --- | --- | --- | --- |
|
|
2107
|
+
| **Trend-Based Fib Time** | `'trendBasedFibTime'` | 3 | Fib Timezone measures from its own origin. This projects one leg's *duration* onto a different starting bar. |
|
|
2108
|
+
| **Fib Speed Resistance Arcs** | `'fibSpeedResistanceArcs'` | 2 | The Fan projects straight lines, so implied support stays proportional forever. Arcs curve, so it decays with distance. |
|
|
2109
|
+
| **Fib Wedge** | `'fibWedge'` | 3 | Fib Circles sweep a full turn from one centre. A wedge is bounded by two user-drawn rays. |
|
|
2110
|
+
| **Pitchfan** | `'pitchfan'` | 3 | A Pitchfork's tines run parallel — a fixed channel. A Pitchfan's radiate, so they spread with distance. |
|
|
2111
|
+
| **Gann Square Fixed** | `'gannSquareFixed'` | 2 | The plain Gann Square stretches to the drag box, so its diagonal is only 45° at one zoom. |
|
|
2112
|
+
|
|
2113
|
+
```ts
|
|
2114
|
+
chart.setDrawingTool('fibWedge');
|
|
2115
|
+
```
|
|
2116
|
+
|
|
2117
|
+
### Details that matter
|
|
2118
|
+
|
|
2119
|
+
**Trend-Based Fib Time** — p1→p2 is the base leg and p3 is where projection
|
|
2120
|
+
starts, so the verticals answer *"if this leg took N bars, when do the Fibonacci
|
|
2121
|
+
multiples of N fall from here?"*. Lines outside the viewport are skipped rather
|
|
2122
|
+
than stroked and clipped. It stays inert until the third point lands and when the
|
|
2123
|
+
base leg has zero duration — there is nothing to project in either case.
|
|
2124
|
+
|
|
2125
|
+
**Fib Speed Resistance Arcs** — drawn as **ellipses**, not circles, with the x and
|
|
2126
|
+
y radii taken separately from the trend's run and rise. A pixel-space circle
|
|
2127
|
+
would change shape the moment the price axis was rescaled, which makes the tool
|
|
2128
|
+
meaningless on a chart the user has zoomed. Only the half facing the trend is
|
|
2129
|
+
drawn; the half behind the origin would imply resistance before the move began.
|
|
2130
|
+
|
|
2131
|
+
**Fib Wedge** — the sweep always takes the short way round, so a wedge never
|
|
2132
|
+
flips to the reflex angle when an edge crosses the ±π seam. Hit testing checks
|
|
2133
|
+
the angular span first, so a click at a matching radius but outside the wedge
|
|
2134
|
+
correctly misses.
|
|
2135
|
+
|
|
2136
|
+
**Pitchfan** — rays are extended *forward* past the base, since that is the only
|
|
2137
|
+
part anyone trades off. Handle and base are dashed: construction, not signal.
|
|
2138
|
+
|
|
2139
|
+
**Gann Square Fixed** — takes the **longer** side of the drag and uses it for
|
|
2140
|
+
both, so the 45° diagonal really is 45°. That is the premise of Gann's angles and
|
|
2141
|
+
worthless if the shape skews with the axes. The cost is that the box no longer
|
|
2142
|
+
matches the drag exactly — "fixed" means fixed *proportion*, not fixed size.
|
|
2143
|
+
|
|
2144
|
+
### Native wrapper parity
|
|
2145
|
+
|
|
2146
|
+
All five are new `DrawingToolType` strings, so `setDrawingTool('pitchfan')` works
|
|
2147
|
+
on [charts-android](../charts-android) and [charts-ios](../charts-ios) with no
|
|
2148
|
+
wrapper change.
|
|
2149
|
+
|
|
2150
|
+
---
|
|
2151
|
+
|
|
2152
|
+
## Cursors & Line Tools
|
|
2153
|
+
|
|
2154
|
+
### Extending lines
|
|
2155
|
+
|
|
2156
|
+
Four tools that differ from a Trend Line only in where they stop being drawn —
|
|
2157
|
+
which is exactly why they exist as separate tools rather than a style option.
|
|
2158
|
+
|
|
2159
|
+
| Tool | `DrawingToolType` | What it does |
|
|
2160
|
+
| --- | --- | --- |
|
|
2161
|
+
| **Ray** | `'ray'` | Two anchors; continues past the second. |
|
|
2162
|
+
| **Extended Line** | `'extendedLine'` | Two anchors; continues past both. |
|
|
2163
|
+
| **Horizontal Ray** | `'horizontalRay'` | One click; a level that runs **forward only**. |
|
|
2164
|
+
| **Info Line** | `'infoLine'` | A trend line that permanently reports what it spans. |
|
|
2165
|
+
|
|
2166
|
+
```ts
|
|
2167
|
+
chart.setDrawingTool('ray');
|
|
2168
|
+
```
|
|
2169
|
+
|
|
2170
|
+
The extension is recomputed against the canvas every frame, so panning and
|
|
2171
|
+
zooming re-extend the line instead of dragging a stale endpoint around. Hit
|
|
2172
|
+
testing uses the *extended* segment, so the infinite part is clickable too — the
|
|
2173
|
+
user can grab what they can see. Anchor dots are drawn only at the anchors,
|
|
2174
|
+
never at the extended ends, because a dot at the canvas edge reads as a handle
|
|
2175
|
+
and there is nothing there to grab.
|
|
2176
|
+
|
|
2177
|
+
**Horizontal Ray vs Horizontal Line** is the one worth calling out: a level drawn
|
|
2178
|
+
from the swing high that formed it should not be painted back across the history
|
|
2179
|
+
that preceded it, because that implies support which did not yet exist.
|
|
2180
|
+
|
|
2181
|
+
**Info Line vs Ruler**: the Ruler is a transient measurement — drawn, read,
|
|
2182
|
+
discarded. An Info Line is a drawing you keep, so its readout travels with it and
|
|
2183
|
+
updates as either end is dragged. It reports price delta, percent, bar count,
|
|
2184
|
+
and — when `instrument` and bar timestamps are available — pips and calendar
|
|
2185
|
+
duration. Each is omitted rather than shown as a zero when it cannot be computed.
|
|
2186
|
+
|
|
2187
|
+
### Cursors
|
|
2188
|
+
|
|
2189
|
+
Pointer behaviour over the plot, **independent of the drawing tool**: switching
|
|
2190
|
+
mode never cancels a drawing in progress, and arming a tool never changes the
|
|
2191
|
+
mode.
|
|
2192
|
+
|
|
2193
|
+
| `CursorMode` | Behaviour |
|
|
2194
|
+
| --- | --- |
|
|
2195
|
+
| `'cross'` | The default crosshair with its axis readouts. |
|
|
2196
|
+
| `'dot'` | A dot follows the pointer instead of two lines cutting across the candles. |
|
|
2197
|
+
| `'arrow'` | A plain pointer, no crosshair. |
|
|
2198
|
+
| `'demonstration'` | A laser trail that fades behind the pointer, for screen-sharing. Draws nothing permanent and creates no drawing. |
|
|
2199
|
+
| `'eraser'` | A click deletes the drawing under it. |
|
|
2200
|
+
|
|
2201
|
+
```ts
|
|
2202
|
+
const chart = new ChartEngine({
|
|
2203
|
+
container,
|
|
2204
|
+
cursorMode: 'cross', // initial mode
|
|
2205
|
+
features: { enableCursorModes: true }, // adds the Cursors group to the toolbar
|
|
2206
|
+
});
|
|
2207
|
+
|
|
2208
|
+
chart.setCursorMode('eraser');
|
|
2209
|
+
chart.on('cursorModeChange', ({ mode }) => persist(mode));
|
|
2210
|
+
```
|
|
2211
|
+
|
|
2212
|
+
`features.enableCursorModes` is a gate because it adds a **category** to a
|
|
2213
|
+
toolbar that hosts have laid out around its current contents. With it off the
|
|
2214
|
+
group is absent and the toolbar is exactly what it was — and the modes are still
|
|
2215
|
+
reachable from `setCursorMode()`, so a host can drive them from its own chrome
|
|
2216
|
+
without taking the group.
|
|
2217
|
+
|
|
2218
|
+
Two details worth knowing:
|
|
2219
|
+
|
|
2220
|
+
- **A drawing tool owns the cursor while armed.** It needs crosshair precision
|
|
2221
|
+
whatever the mode says; clearing the tool hands the cursor back to the mode.
|
|
2222
|
+
- **The eraser consumes every click**, hit or miss. A miss must not fall through
|
|
2223
|
+
to selecting or panning — that would be a surprising thing to do with an eraser
|
|
2224
|
+
in hand. It deletes via select-then-delete, so it shares the undo history with
|
|
2225
|
+
every other delete.
|
|
2226
|
+
|
|
2227
|
+
### Value tooltip on long press
|
|
2228
|
+
|
|
2229
|
+
```ts
|
|
2230
|
+
const chart = new ChartEngine({ container, valueTooltip: true });
|
|
2231
|
+
```
|
|
2232
|
+
|
|
2233
|
+
A floating OHLCV readout beside a long press, on top of the crosshair that
|
|
2234
|
+
gesture already arms. The OHLC strip at the top of the chart carries the same
|
|
2235
|
+
numbers, but on a phone it is at the opposite end of the screen from the finger —
|
|
2236
|
+
the user has to look away from the thing they are pointing at.
|
|
2237
|
+
|
|
2238
|
+
It flips to the other side of the touch rather than running off an edge, never
|
|
2239
|
+
takes pointer events (the drag is still in progress), and omits volume rather
|
|
2240
|
+
than printing a zero when the feed carries none. Default `false`.
|
|
2241
|
+
|
|
2242
|
+
### Native wrapper parity
|
|
2243
|
+
|
|
2244
|
+
The four line tools are new `DrawingToolType` strings, so `setDrawingTool('ray')`
|
|
2245
|
+
works on [charts-android](../charts-android) and [charts-ios](../charts-ios)
|
|
2246
|
+
unchanged.
|
|
2247
|
+
|
|
2248
|
+
| JS | Android | iOS |
|
|
2249
|
+
| --- | --- | --- |
|
|
2250
|
+
| `setCursorMode(m)` | `setCursorMode(m)` | `setCursorMode(_:)` |
|
|
2251
|
+
| `cursorModeChange` | `BridgeEvent.CursorModeChange` | `.cursorModeChange` |
|
|
2252
|
+
| `cursorMode` at init | `Init(cursorMode = "…")` | `cursorMode:` argument |
|
|
2253
|
+
| `valueTooltip` | `Init(valueTooltip = true)` | `valueTooltip:` argument |
|
|
2254
|
+
| `features.enableCursorModes` | `Init(enableCursorModes = true)` | `enableCursorModes:` argument |
|
|
2255
|
+
|
|
2256
|
+
---
|
|
2257
|
+
|
|
2258
|
+
## Chart Types
|
|
2259
|
+
|
|
2260
|
+
Thirteen time-based types plus five added for TradingView parity. The five split
|
|
2261
|
+
into two kinds, and the difference matters more than the list suggests.
|
|
2262
|
+
|
|
2263
|
+
### HLC bars — `'hlc'`
|
|
2264
|
+
|
|
2265
|
+
An ordinary per-bar series: the high-low range with a close tick and no open
|
|
2266
|
+
stub. Halves the ink of an OHLC bar, which is the point — on a dense chart the
|
|
2267
|
+
closes stay legible where full bars smear. Colour still comes from open vs close.
|
|
2268
|
+
|
|
2269
|
+
### Price-transform types — `'renko'`, `'linebreak'`, `'kagi'`, `'pointfigure'`
|
|
2270
|
+
|
|
2271
|
+
These are **not drawn per time bar.** A brick, block, kagi segment or P&F column
|
|
2272
|
+
forms when *price* moves far enough, which may take fifty bars or none at all.
|
|
2273
|
+
365 daily candles might be 24 Renko bricks or 15 P&F columns.
|
|
2274
|
+
|
|
2275
|
+
So they are not renderers — the bar array itself is rebuilt. Each transform turns
|
|
2276
|
+
raw OHLCV into **synthetic** bars, one per visual element, which the rest of the
|
|
2277
|
+
chart then treats as ordinary bars. That is what keeps the feature small:
|
|
2278
|
+
viewport, zoom, price range, crosshair, the time axis, indicators and drawings
|
|
2279
|
+
all keep working unchanged. It also means **an indicator on a Renko chart is
|
|
2280
|
+
computed over the bricks**, not the underlying candles — same as TradingView.
|
|
2281
|
+
|
|
2282
|
+
Three consequences worth knowing:
|
|
2283
|
+
|
|
2284
|
+
- **The time axis is non-linear.** Labels show when each element *completed*.
|
|
2285
|
+
Several elements completing on one bar get timestamps one millisecond apart so
|
|
2286
|
+
drawing anchors and viewport restore keep working.
|
|
2287
|
+
- **Switching in or out refits the view**, because the old viewport indexes a
|
|
2288
|
+
different number of elements.
|
|
2289
|
+
- **Market price still comes off the raw feed.** Trade levels and P&L price
|
|
2290
|
+
against the real last close, never a brick top.
|
|
2291
|
+
|
|
2292
|
+
### Parameters
|
|
2293
|
+
|
|
2294
|
+
```ts
|
|
2295
|
+
const chart = new ChartEngine({
|
|
2296
|
+
container,
|
|
2297
|
+
series: 'renko',
|
|
2298
|
+
seriesOptions: {
|
|
2299
|
+
renko: { boxSize: { kind: 'atr', length: 14 } }, // the default
|
|
2300
|
+
lineBreak: { lines: 3 },
|
|
2301
|
+
kagi: { reversal: { kind: 'percent', percent: 2 } },
|
|
2302
|
+
pointFigure: { boxSize: { kind: 'fixed', size: 0.5 }, reversal: 3 },
|
|
2303
|
+
},
|
|
2304
|
+
});
|
|
2305
|
+
|
|
2306
|
+
chart.setSeriesOptions({ renko: { boxSize: { kind: 'fixed', size: 5 } } });
|
|
2307
|
+
```
|
|
2308
|
+
|
|
2309
|
+
Every box/reversal size defaults to **ATR(14)**, not a fixed price, because a
|
|
2310
|
+
fixed box is meaningless until you know the instrument: ten points is noise on an
|
|
2311
|
+
index and a lifetime on a forex pair. `setSeriesOptions` merges, so retuning
|
|
2312
|
+
Renko leaves Kagi and P&F alone.
|
|
2313
|
+
|
|
2314
|
+
| `BoxSizeMode` | Meaning |
|
|
2315
|
+
| --- | --- |
|
|
2316
|
+
| `{ kind: 'atr', length }` | Wilder ATR over the last `length` bars. Default `14`. |
|
|
2317
|
+
| `{ kind: 'fixed', size }` | A fixed price distance. |
|
|
2318
|
+
| `{ kind: 'percent', percent }` | A percentage of the latest close. |
|
|
2319
|
+
|
|
2320
|
+
When a box cannot be sized — fewer than `length + 1` bars for the ATR, or a
|
|
2321
|
+
non-positive size — the transform returns **no elements** rather than guessing. A
|
|
2322
|
+
wrong box size does not look wrong; it looks like a different market.
|
|
2323
|
+
|
|
2324
|
+
### The rules each type implements
|
|
2325
|
+
|
|
2326
|
+
| Type | Rule |
|
|
2327
|
+
| --- | --- |
|
|
2328
|
+
| **Renko** | A brick prints when price closes a full box past the last brick's edge. Reversals need **two** boxes, not one — that two-box rule is what filters the noise. `source: 'highlow'` lets a bar's extremes print bricks instead of its close. |
|
|
2329
|
+
| **Line Break** | A block prints when the close clears the extreme of the last `lines` blocks (default 3). No box size at all — the reversal distance is whatever recent blocks span, so it widens automatically in volatile stretches. |
|
|
2330
|
+
| **Kagi** | **Direction** flips on a retrace of the reversal amount. **Thickness** flips on a break of the prior shoulder or waist. These are independent: a line can reverse repeatedly without ever changing thickness. |
|
|
2331
|
+
| **Point & Figure** | Columns of X's and O's on a box grid, built from each bar's **high and low** — high first in an X column, low first in an O column, so a bar that both extended and reversed is read in the order it happened. A new column needs `reversal` boxes (default 3). |
|
|
2332
|
+
|
|
2333
|
+
### Using the transforms off-chart
|
|
2334
|
+
|
|
2335
|
+
They are exported as pure functions, so a backtest or a server-side render gets
|
|
2336
|
+
byte-identical elements:
|
|
2337
|
+
|
|
2338
|
+
```ts
|
|
2339
|
+
import { toRenko, toKagi, atrValue } from 'acttrader-charts';
|
|
2340
|
+
|
|
2341
|
+
const { bars, meta } = toRenko(ohlcv, { boxSize: { kind: 'fixed', size: 5 } });
|
|
2342
|
+
```
|
|
2343
|
+
|
|
2344
|
+
Each returns `{ bars, meta }`. `meta[i]` carries what cannot be read off the
|
|
2345
|
+
synthetic bar: Kagi's `thick`, P&F's `boxSize`, and `sourceBars` / `startTime`
|
|
2346
|
+
for every type.
|
|
2347
|
+
|
|
2348
|
+
### Native wrapper parity
|
|
2349
|
+
|
|
2350
|
+
The five types are new values of the same `series` string, so `setSeries('renko')`
|
|
2351
|
+
works on [charts-android](../charts-android) and [charts-ios](../charts-ios)
|
|
2352
|
+
unchanged. Parameters travel as a JSON object:
|
|
2353
|
+
|
|
2354
|
+
| JS | Android | iOS |
|
|
2355
|
+
| --- | --- | --- |
|
|
2356
|
+
| `seriesOptions` at init | `Init(seriesOptionsJson = "…")` | `seriesOptionsJson:` init argument |
|
|
2357
|
+
| `setSeriesOptions(o)` | `setSeriesOptions(json)` | `setSeriesOptions(_:)` |
|
|
2358
|
+
|
|
2359
|
+
---
|
|
2360
|
+
|
|
2361
|
+
## Top-Toolbar Features
|
|
2362
|
+
|
|
2363
|
+
Four opt-in features that bring the header in line with TradingView's: **indicator
|
|
2364
|
+
templates**, **saved chart layouts**, **Quick Search**, and **chart-settings
|
|
2365
|
+
templates with "Apply to all charts"**. Compare and Snapshot already shipped — see
|
|
2366
|
+
[Multi-Pane Layouts](#multi-pane-layouts) and the Compare section.
|
|
2367
|
+
|
|
2368
|
+
Two rules apply to all of them:
|
|
2369
|
+
|
|
2370
|
+
- **Nothing moves.** Every gate defaults to `false`, and with them off the chart's
|
|
2371
|
+
DOM is unchanged. When enabled, each feature extends a flyout, popover or dialog
|
|
2372
|
+
that already exists — no feature adds a header button (Quick Search can, but only
|
|
2373
|
+
if you ask for one).
|
|
2374
|
+
- **The library persists nothing.** Saving emits an event carrying the complete
|
|
2375
|
+
object; your app stores it and seeds it back. This is the same contract
|
|
2376
|
+
`stateChange` follows, and it is what lets Android and iOS reuse the feature
|
|
2377
|
+
without reimplementing storage twice.
|
|
2378
|
+
|
|
2379
|
+
### Indicator templates
|
|
2380
|
+
|
|
2381
|
+
Named, reusable indicator sets, listed in a **Templates** block at the foot of the
|
|
2382
|
+
indicators flyout.
|
|
2383
|
+
|
|
2384
|
+
```ts
|
|
2385
|
+
const chart = new ChartEngine({
|
|
2386
|
+
container,
|
|
2387
|
+
enableIndicatorTemplates: true,
|
|
2388
|
+
indicatorTemplates: loadFromStorage(), // what you saved last session
|
|
2389
|
+
});
|
|
2390
|
+
|
|
2391
|
+
chart.on('indicatorTemplateSaved', ({ template }) => persist(template));
|
|
2392
|
+
chart.on('indicatorTemplateDeleted', ({ id }) => forget(id));
|
|
2393
|
+
```
|
|
2394
|
+
|
|
2395
|
+
| API | Does |
|
|
2396
|
+
| --- | --- |
|
|
2397
|
+
| `captureIndicatorTemplate(name)` | Saves the active indicators; emits `indicatorTemplateSaved`. Returns the template or `null`. |
|
|
2398
|
+
| `applyIndicatorTemplate(idOrName)` | Replaces the active indicators with the template's. Returns `false` if nothing matched. |
|
|
2399
|
+
| `deleteIndicatorTemplate(idOrName)` | Removes it; emits `indicatorTemplateDeleted`. |
|
|
2400
|
+
| `setIndicatorTemplates(list)` | Replaces the list the flyout shows. |
|
|
2401
|
+
| `getIndicatorTemplates()` | Reads it back (copies). |
|
|
2402
|
+
|
|
2403
|
+
Saving twice under one name yields two templates — ids are de-duplicated
|
|
2404
|
+
(`my-set`, `my-set-2`), which is what users expect from "Save as".
|
|
2405
|
+
|
|
2406
|
+
Rendered by the default `TopBar` and by `AdvancedToolbar`. The compact per-pane
|
|
2407
|
+
strip and the mobile header have no full indicators flyout, so they skip it.
|
|
2408
|
+
|
|
2409
|
+
### Saved chart layouts
|
|
2410
|
+
|
|
2411
|
+
A **saved layout** is a grid preset *plus* every pane's full `ChartState` — symbol,
|
|
2412
|
+
timeframe, series, indicators, drawings, viewport, compares. That is the difference
|
|
2413
|
+
from the preset grid already in the layout popover, which only picks a *shape*.
|
|
2414
|
+
|
|
2415
|
+
Requires `enableMultipleLayouts`, since the section renders inside that popover.
|
|
2416
|
+
|
|
2417
|
+
```ts
|
|
2418
|
+
const chart = new ChartEngine({
|
|
2419
|
+
container,
|
|
2420
|
+
enableMultipleLayouts: true,
|
|
2421
|
+
enableSavedLayouts: true,
|
|
2422
|
+
savedLayouts: loadFromStorage(),
|
|
2423
|
+
});
|
|
2424
|
+
|
|
2425
|
+
chart.on('layoutSaved', ({ layout }) => persist(layout));
|
|
2426
|
+
chart.on('layoutApplied', ({ layout }) => mountPanes(layout)); // multi-pane hosts
|
|
2427
|
+
```
|
|
2428
|
+
|
|
2429
|
+
| API | Does |
|
|
2430
|
+
| --- | --- |
|
|
2431
|
+
| `captureSavedLayout(name, paneId?)` | Saves the preset + this chart's state. Single-engine: one pane. |
|
|
2432
|
+
| `applySavedLayout(idOrName, paneId?)` | Applies the preset (emits `layoutChange`) then this pane's state. |
|
|
2433
|
+
| `deleteSavedLayout(idOrName)` | Removes it; emits `layoutDeleted`. |
|
|
2434
|
+
| `setSavedLayouts(list)` / `getSavedLayouts()` | Replace / read the list. |
|
|
2435
|
+
|
|
2436
|
+
For a real multi-pane grid use `ChartGroup`, which sees every pane:
|
|
2437
|
+
|
|
2438
|
+
```ts
|
|
2439
|
+
const layout = group.captureLayout('My Desk', chart.getLayoutPreset());
|
|
2440
|
+
persist(layout);
|
|
2441
|
+
for (const [, engine] of group.entries()) engine.setSavedLayouts(allLayouts);
|
|
2442
|
+
|
|
2443
|
+
// restoring: mount the grid for layout.presetId yourself, then
|
|
2444
|
+
const { applied, missing } = group.applyLayout(layout);
|
|
2445
|
+
```
|
|
2446
|
+
|
|
2447
|
+
`applyLayout` skips panes that aren't registered yet and returns them in `missing`,
|
|
2448
|
+
so a host that mounts lazily can create them and call again. Registered panes that
|
|
2449
|
+
the layout doesn't mention are left alone rather than cleared.
|
|
2450
|
+
|
|
2451
|
+
### Quick Search
|
|
2452
|
+
|
|
2453
|
+
A command palette over everything the chart can do: series types, timeframes,
|
|
2454
|
+
durations, indicators, drawing tools, saved templates and layouts, and the header
|
|
2455
|
+
actions.
|
|
2456
|
+
|
|
2457
|
+
```ts
|
|
2458
|
+
const chart = new ChartEngine({ container, enableQuickSearch: true });
|
|
2459
|
+
```
|
|
2460
|
+
|
|
2461
|
+
Opened with **Ctrl/⌘+K**, with **`/`**, or by `chart.openQuickSearch()`. It is
|
|
2462
|
+
keyboard-first and **adds no header button** — pass
|
|
2463
|
+
`quickSearch: { showButton: true }` if you want one. A bare `/` is ignored while
|
|
2464
|
+
the user is typing in any input, textarea, select, or contenteditable.
|
|
2465
|
+
|
|
2466
|
+
Add your own commands beside the built-ins:
|
|
2467
|
+
|
|
2468
|
+
```ts
|
|
2469
|
+
chart.registerCommand({
|
|
2470
|
+
id: 'myapp.openTicket',
|
|
2471
|
+
label: 'Open order ticket',
|
|
2472
|
+
group: 'My App',
|
|
2473
|
+
keywords: ['buy', 'sell', 'trade'],
|
|
2474
|
+
run: () => openTicket(),
|
|
2475
|
+
});
|
|
2476
|
+
|
|
2477
|
+
chart.on('quickSearchCommand', ({ id }) => track(id));
|
|
2478
|
+
```
|
|
2479
|
+
|
|
2480
|
+
Namespace your ids so a future built-in can't collide. `matchCommands`,
|
|
2481
|
+
`scoreCommand` and `groupCommands` are exported if you want the same ranking in
|
|
2482
|
+
your own UI: exact label beats prefix beats word-start beats substring, with
|
|
2483
|
+
keyword and group hits last, and ties keep their original order so the list never
|
|
2484
|
+
reshuffles unpredictably as the user types.
|
|
2485
|
+
|
|
2486
|
+
### Chart-settings templates + Apply to all charts
|
|
2487
|
+
|
|
2488
|
+
Named snapshots of everything the Chart Settings dialog edits, plus a switch to
|
|
2489
|
+
push the current settings to every other chart. Both render in the dialog's
|
|
2490
|
+
footer — no new button anywhere.
|
|
2491
|
+
|
|
2492
|
+
```ts
|
|
2493
|
+
const chart = new ChartEngine({
|
|
2494
|
+
container,
|
|
2495
|
+
enableSettingsTemplates: true,
|
|
2496
|
+
settingsTemplates: loadFromStorage(),
|
|
2497
|
+
});
|
|
2498
|
+
|
|
2499
|
+
chart.on('settingsTemplateSaved', ({ template }) => persist(template));
|
|
2500
|
+
|
|
2501
|
+
chart.on('chartSettingsApplied', ({ settings, applyToAll }) => {
|
|
2502
|
+
// This chart already applied them. Only the fan-out is yours:
|
|
2503
|
+
if (applyToAll) group.applySettingsToAll(settings, thisPaneId);
|
|
2504
|
+
});
|
|
2505
|
+
```
|
|
2506
|
+
|
|
2507
|
+
| API | Does |
|
|
2508
|
+
| --- | --- |
|
|
2509
|
+
| `getChartSettings()` / `applyChartSettings(s)` | Read / apply a settings snapshot. Every route — dialog, template, apply-to-all, bridge — goes through `applyChartSettings`. |
|
|
2510
|
+
| `captureSettingsTemplate(name)` | Saves the current settings; emits `settingsTemplateSaved`. |
|
|
2511
|
+
| `applySettingsTemplate(idOrName)` | Applies a saved one. |
|
|
2512
|
+
| `deleteSettingsTemplate(idOrName)` | Removes it. |
|
|
2513
|
+
| `setSettingsTemplates(list)` / `getSettingsTemplates()` | Replace / read the list. |
|
|
2514
|
+
| `ChartGroup.applySettingsToAll(settings, fromPaneId?)` | Applies to every other pane. Not gated on a `sync` toggle — it is an explicit one-shot action, not continuous mirroring. |
|
|
2515
|
+
|
|
2516
|
+
### Native wrapper parity
|
|
2517
|
+
|
|
2518
|
+
All four features, plus snapshot capture, are exposed by
|
|
2519
|
+
[charts-android](../charts-android) and [charts-ios](../charts-ios). Templates and
|
|
2520
|
+
layouts cross the bridge as opaque JSON strings: the app stores what the chart
|
|
2521
|
+
handed it and sends the same string back, so neither Kotlin nor Swift has to mirror
|
|
2522
|
+
a `ChartState` that only the chart interprets.
|
|
2523
|
+
|
|
2524
|
+
| JS | Android | iOS |
|
|
2525
|
+
| --- | --- | --- |
|
|
2526
|
+
| `enableIndicatorTemplates` | `Init(enableIndicatorTemplates = true)` | `HeaderFeatures(enableIndicatorTemplates: true)` |
|
|
2527
|
+
| `captureIndicatorTemplate(name)` | `captureIndicatorTemplate(name)` | `captureIndicatorTemplate(_:)` |
|
|
2528
|
+
| `enableSavedLayouts` | `Init(enableSavedLayouts = true)` | `HeaderFeatures(enableSavedLayouts: true)` |
|
|
2529
|
+
| `enableQuickSearch` / `openQuickSearch()` | `openQuickSearch()` | `openQuickSearch()` |
|
|
2530
|
+
| `enableSettingsTemplates` | `Init(enableSettingsTemplates = true)` | `HeaderFeatures(enableSettingsTemplates: true)` |
|
|
2531
|
+
| `chartSettingsApplied` event | `BridgeEvent.ChartSettingsApplied` | `.chartSettingsApplied` |
|
|
2532
|
+
| `chart.toDataUrl()` | `requestSnapshot()` → `BridgeEvent.Snapshot` | `requestSnapshot()` → `.snapshot` |
|
|
2533
|
+
|
|
2534
|
+
On mobile there is no Ctrl/⌘+K, so Quick Search is opened with the
|
|
2535
|
+
`openQuickSearch` command from your own toolbar.
|
|
2536
|
+
|
|
2537
|
+
---
|
|
2538
|
+
|
|
2539
|
+
## Chart Settings
|
|
2540
|
+
|
|
2541
|
+
Six settings TradingView has and ActCharts did not, behind
|
|
2542
|
+
`features.enableChartSettings`. The gate adds three tabs — **Status Line**,
|
|
2543
|
+
**Scales**, **Canvas** — to the Chart Settings dialog and a bar-colouring choice
|
|
2544
|
+
to Appearance. Every one of them is also a `ChartConfig` option and a
|
|
2545
|
+
`ChartEngine` method, so a host can drive them from its own chrome and leave the
|
|
2546
|
+
dialog as it was.
|
|
2547
|
+
|
|
2548
|
+
```ts
|
|
2549
|
+
const chart = new ChartEngine({
|
|
2550
|
+
container,
|
|
2551
|
+
features: { enableChartSettings: true },
|
|
2552
|
+
statusLine: { barChange: true },
|
|
2553
|
+
scales: { highLowLabels: true, pricePrecision: 4, timezone: 'Asia/Tokyo' },
|
|
2554
|
+
canvas: { gridVertical: false, watermarkVisible: true },
|
|
2555
|
+
barColorSource: 'previousClose',
|
|
2556
|
+
});
|
|
2557
|
+
```
|
|
2558
|
+
|
|
2559
|
+
### Status line
|
|
2560
|
+
|
|
2561
|
+
What the legend above the chart shows.
|
|
2562
|
+
|
|
2563
|
+
| Field | Default | Shows |
|
|
2564
|
+
| --- | --- | --- |
|
|
2565
|
+
| `symbol` | `true` | The instrument name and its stream dot |
|
|
2566
|
+
| `ohlc` | `true` | O / H / L / C of the hovered bar |
|
|
2567
|
+
| `barChange` | **`false`** | Absolute and percent change, e.g. `+1.68 (+0.96%)` |
|
|
2568
|
+
| `volume` | `true` | V, when the feed carries it |
|
|
2569
|
+
|
|
2570
|
+
`barChange` is the one default of `false`: it is a new readout, and turning it on
|
|
2571
|
+
by itself would change a legend hosts have laid out around. **Change is measured
|
|
2572
|
+
against the previous bar's close**, which is what "the change" means on every
|
|
2573
|
+
quote screen — against this bar's open it would only restate the candle's colour.
|
|
2574
|
+
|
|
2575
|
+
### Scales and lines
|
|
2576
|
+
|
|
2577
|
+
```ts
|
|
2578
|
+
chart.setScalesSettings({ lastPriceLabel: false, highLowLabels: true });
|
|
2579
|
+
```
|
|
2580
|
+
|
|
2581
|
+
| Field | Default | Effect |
|
|
2582
|
+
| --- | --- | --- |
|
|
2583
|
+
| `lastPriceLabel` | `true` | The live price tag and its dashed line |
|
|
2584
|
+
| `bidLabel` / `askLabel` | follows config | The bid / ask tags |
|
|
2585
|
+
| `highLowLabels` | `false` | Tags at the extremes of the **visible** range |
|
|
2586
|
+
| `timeAxisCountdown` | follows `showCandleCountdown` | Countdown on the time axis |
|
|
2587
|
+
| `pricePrecision` | `null` | Decimal places; null infers from the feed |
|
|
2588
|
+
| `timezone` | `'UTC'` | IANA name for axis, crosshair and tooltips |
|
|
2589
|
+
|
|
2590
|
+
Bid and ask fall through to the `showBidLine` / `showAskLine` config they
|
|
2591
|
+
duplicate, so the dialog and the existing runtime setters stay **one switch**
|
|
2592
|
+
rather than two that can disagree.
|
|
2593
|
+
|
|
2594
|
+
High/low are measured over what is on screen, not the whole dataset: a tag for a
|
|
2595
|
+
high six months out of view marks a line the user cannot see and cannot scroll
|
|
2596
|
+
to without losing it.
|
|
2597
|
+
|
|
2598
|
+
### Price precision
|
|
2599
|
+
|
|
2600
|
+
```ts
|
|
2601
|
+
chart.setPricePrecision(4); // pin
|
|
2602
|
+
chart.setPricePrecision(null); // back to inferring from the feed
|
|
2603
|
+
```
|
|
2604
|
+
|
|
2605
|
+
One accessor feeds all eleven places the chart writes a price — axis, legend,
|
|
2606
|
+
tooltips, crosshair, drawings, trade levels — so an override cannot apply to
|
|
2607
|
+
some and not others. A price axis reading `1.2345` beside a tooltip reading
|
|
2608
|
+
`1.23` is worse than either choice on its own.
|
|
2609
|
+
|
|
2610
|
+
**It deliberately does not move pip size.** A pip is a property of the contract;
|
|
2611
|
+
asking the axis for fewer decimals is a display choice, and the Ruler must keep
|
|
2612
|
+
saying what a move is actually worth. Pip size still comes from `InstrumentSpec`
|
|
2613
|
+
and, failing that, from the precision *inferred* from the data.
|
|
2614
|
+
|
|
2615
|
+
### Timezone
|
|
2616
|
+
|
|
2617
|
+
`setTimezone(tz)` already existed; it is now in the dialog, carried in
|
|
2618
|
+
`ChartSettingsSnapshot`, and emits `timezoneChange`. `'local'` resolves to the
|
|
2619
|
+
device zone immediately, so `getTimezone()` always returns a real IANA name.
|
|
2620
|
+
|
|
2621
|
+
### Canvas
|
|
2622
|
+
|
|
2623
|
+
```ts
|
|
2624
|
+
chart.setCanvasOptions({ gridVertical: false, watermarkVisible: true, watermarkSize: 128 });
|
|
2625
|
+
```
|
|
2626
|
+
|
|
2627
|
+
| Field | Default |
|
|
2628
|
+
| --- | --- |
|
|
2629
|
+
| `gridHorizontal` / `gridVertical` | `true` |
|
|
2630
|
+
| `watermarkVisible` | `false` |
|
|
2631
|
+
| `watermarkText` | `''` — empty uses the current symbol |
|
|
2632
|
+
| `watermarkSize` / `watermarkOpacity` | `72` / `0.06` |
|
|
2633
|
+
| `crosshairStyle` | `'dashed'` |
|
|
2634
|
+
| `crosshairWidth` | `1` |
|
|
2635
|
+
|
|
2636
|
+
Colours stay in `setCanvasColors`, which was already plumbed per theme;
|
|
2637
|
+
`gridVertical` and `watermark` are new entries in `CanvasColorSettings` and fall
|
|
2638
|
+
back to `grid` and `axisText`.
|
|
2639
|
+
|
|
2640
|
+
**The watermark draws above the grid and below everything else.** Painted after
|
|
2641
|
+
the series it would tint the candles, and the point of it is to sit behind them.
|
|
2642
|
+
Crosshair dash lengths scale with the width, or a 4px dash on a 4px line reads as
|
|
2643
|
+
a solid bar.
|
|
2644
|
+
|
|
2645
|
+
### Colour bars based on previous close
|
|
2646
|
+
|
|
2647
|
+
```ts
|
|
2648
|
+
chart.setBarColorSource('previousClose');
|
|
2649
|
+
```
|
|
2650
|
+
|
|
2651
|
+
Whether a bar is "up" against its own open (the default) or against the previous
|
|
2652
|
+
bar's close. The two disagree constantly — a gap-up bar that sells off all
|
|
2653
|
+
session is up on one rule and down on the other — which is why it is a setting
|
|
2654
|
+
and not a fix.
|
|
2655
|
+
|
|
2656
|
+
Applies to candles, hollow candles, bars, HLC bars, columns **and the volume
|
|
2657
|
+
pane together**: they are one reading of the same market, and a volume pane
|
|
2658
|
+
disagreeing with the candles above it is a bug, not a setting. Heikin Ashi,
|
|
2659
|
+
Renko, Kagi and Point & Figure are unaffected — direction is intrinsic to what
|
|
2660
|
+
those transforms compute.
|
|
2661
|
+
|
|
2662
|
+
Eight series each carried their own `close >= open`; they now share
|
|
2663
|
+
`computeUpFlags()`, which the engine calls once per frame. It takes the bar
|
|
2664
|
+
*before* the visible slice, because the renderers only ever see what is on
|
|
2665
|
+
screen — without it the leftmost bar would have nothing to compare against and
|
|
2666
|
+
would flip colour as the user panned it into view. At the very start of the data,
|
|
2667
|
+
where no earlier bar exists, that one bar falls back to open-vs-close.
|
|
2668
|
+
|
|
2669
|
+
### Persistence
|
|
2670
|
+
|
|
2671
|
+
All six ride in `ChartSettingsSnapshot`, so they are covered by settings
|
|
2672
|
+
templates and "Apply to all charts" for free. **Absent is meaningful**: a
|
|
2673
|
+
template saved before these fields existed applies as "change nothing", not as
|
|
2674
|
+
"reset everything to its default" — otherwise re-applying an old template would
|
|
2675
|
+
silently rearrange the chart.
|
|
2676
|
+
|
|
2677
|
+
|
|
2678
|
+
## Bottom Bar & Price Scale
|
|
2679
|
+
|
|
2680
|
+
Five TradingView controls, behind `features.enableScaleControls`. The gate adds
|
|
2681
|
+
a cluster to the left of the duration buttons — **Go to date**, a **timezone**
|
|
2682
|
+
selector, and **%**, **log**, **auto** — and needs `showBottomBar: true`, since
|
|
2683
|
+
the duration bar is off by default. Each is also a `ChartEngine` method, so a
|
|
2684
|
+
host can drive them from its own chrome and leave the bar as it was.
|
|
2685
|
+
|
|
2686
|
+
```
|
|
2687
|
+
┌──────────────────────────────────────────────────────────────────────┐
|
|
2688
|
+
│ 📅 │ UTC ⌄ │ % log auto 1D 5D 1M 3M 6M 1Y 5Y All │
|
|
2689
|
+
└──────────────────────────────────────────────────────────────────────┘
|
|
2690
|
+
```
|
|
2691
|
+
|
|
2692
|
+
All five are ordinary buttons styled like the duration buttons beside them, and
|
|
2693
|
+
the two that need input open a themed popover above the bar. **No native
|
|
2694
|
+
`<input type="date">` or `<select>`**: both take their colours from the
|
|
2695
|
+
operating system, so in a dark chart they rendered as pale boxes with a browser
|
|
2696
|
+
calendar glyph — the one part of the bar that could not be themed. The menus
|
|
2697
|
+
open *upward*, since the bar is the last row on screen.
|
|
2698
|
+
|
|
2699
|
+
```ts
|
|
2700
|
+
const chart = new ChartEngine({
|
|
2701
|
+
container,
|
|
2702
|
+
showBottomBar: true,
|
|
2703
|
+
features: { enableScaleControls: true },
|
|
2704
|
+
priceScaleMode: 'log',
|
|
2705
|
+
autoScale: true,
|
|
2706
|
+
});
|
|
2707
|
+
```
|
|
2708
|
+
|
|
2709
|
+
### Go to a specific date
|
|
2710
|
+
|
|
2711
|
+
```ts
|
|
2712
|
+
chart.goToDate('2024-03-01'); // ISO, a Date, or unix ms
|
|
2713
|
+
```
|
|
2714
|
+
|
|
2715
|
+
The calendar button opens a date field and a **Go**; the method behind it
|
|
2716
|
+
centres the **nearest** bar and returns its index, or `null` when there is no
|
|
2717
|
+
data. Nearest rather than exact because the date a user types is rarely a bar —
|
|
2718
|
+
it falls on a weekend, a holiday, or between two intraday bars — and refusing to
|
|
2719
|
+
move is a worse answer than landing beside it. Binary search, so it costs
|
|
2720
|
+
nothing on a long history. Emits `goToDate` with the bar it settled on.
|
|
2721
|
+
|
|
2722
|
+
### Timezone selector
|
|
2723
|
+
|
|
2724
|
+
The bottom-bar button shows the current zone's short name and opens a checked
|
|
2725
|
+
list. It writes through `setTimezone()`, the same path the Scales tab and the
|
|
2726
|
+
config option use, so all three stay in step. `'local'` resolves to
|
|
2727
|
+
the device zone immediately — `getTimezone()` always returns a real IANA name.
|
|
2728
|
+
|
|
2729
|
+
### Price scale modes
|
|
2730
|
+
|
|
2731
|
+
```ts
|
|
2732
|
+
chart.setPriceScaleMode('log'); // 'normal' | 'log' | 'percent'
|
|
2733
|
+
```
|
|
2734
|
+
|
|
2735
|
+
**One choice, not three flags.** Log and percent are different answers to the
|
|
2736
|
+
same question, and a chart in both at once has no meaning. Clicking the active
|
|
2737
|
+
button returns to `'normal'`, so the pair works as a toggle rather than a trap.
|
|
2738
|
+
|
|
2739
|
+
#### Logarithmic
|
|
2740
|
+
|
|
2741
|
+
Equal ratios get equal height: a move from 10 to 20 occupies the same space as
|
|
2742
|
+
one from 100 to 200. On a series running 1 → 1000 the pixel gaps between the
|
|
2743
|
+
decade marks go from **49.8px and 497.3px** linear to **156.4px and 156.4px**
|
|
2744
|
+
log, and an exponential series renders as a straight line.
|
|
2745
|
+
|
|
2746
|
+
The mode is carried on the **`PriceRange`**, not on the `ScaleManager`:
|
|
2747
|
+
|
|
2748
|
+
```ts
|
|
2749
|
+
interface PriceRange { min: number; max: number; log?: boolean }
|
|
2750
|
+
```
|
|
2751
|
+
|
|
2752
|
+
One manager serves the price pane and every sub-pane, and an RSI drawn on a log
|
|
2753
|
+
axis would be nonsense. Every price→pixel call already passes a range, so putting
|
|
2754
|
+
the flag there made series, drawings, indicators, the crosshair and hit-testing
|
|
2755
|
+
all log-aware **without changing a single call site**.
|
|
2756
|
+
|
|
2757
|
+
**Log needs a positive range.** `isLogRange()` falls back to linear when `min <= 0`
|
|
2758
|
+
rather than refusing to draw, so an instrument that trades through zero quietly
|
|
2759
|
+
keeps working. A manual zoom-out that drags the displayed minimum below zero is
|
|
2760
|
+
clamped instead, because falling back there would make the chart snap between two
|
|
2761
|
+
mappings in the middle of a drag.
|
|
2762
|
+
|
|
2763
|
+
**Ticks are the 1/2/5 × 10ⁿ series per decade**, thinned by *pixel* distance
|
|
2764
|
+
rather than by value — a decade occupies the same height whether it runs 1→10 or
|
|
2765
|
+
1000→10000. A range inside a single decade falls back to the linear generator,
|
|
2766
|
+
since over a span that narrow the two mappings are within a pixel of each other
|
|
2767
|
+
and linear ticks read better.
|
|
2768
|
+
|
|
2769
|
+
Label precision is computed **per tick** from its own neighbours. One precision
|
|
2770
|
+
taken from the first pair would render `500` as `500.0` and `0.2` as `0.2` in the
|
|
2771
|
+
same column.
|
|
2772
|
+
|
|
2773
|
+
#### Percent
|
|
2774
|
+
|
|
2775
|
+
Every price re-expressed as percent change from the first visible bar's close,
|
|
2776
|
+
with `+0.00%` emphasised on the axis. It reuses the transform compare mode
|
|
2777
|
+
already had, with no second series to combine against, so panning re-bases the
|
|
2778
|
+
way TradingView's percent scale does rather than pinning to the start of history.
|
|
2779
|
+
|
|
2780
|
+
### Auto scale
|
|
2781
|
+
|
|
2782
|
+
```ts
|
|
2783
|
+
chart.setAutoScale(false); // freeze the Y range
|
|
2784
|
+
```
|
|
2785
|
+
|
|
2786
|
+
Switching it off freezes whatever is on screen *now*, so the chart does not jump
|
|
2787
|
+
at the moment the user asks it to stop moving. A manual axis drag still wins —
|
|
2788
|
+
turning auto off should not also take away the ability to move the axis by hand.
|
|
2789
|
+
|
|
2790
|
+
This is separate from the implicit manual mode a price-axis drag already
|
|
2791
|
+
produced: that one is entered by dragging and left by resetting, while this is a
|
|
2792
|
+
switch the user holds across pans and timeframe changes.
|
|
2793
|
+
|
|
2794
|
+
|
|
2795
|
+
## Side Panels
|
|
2796
|
+
|
|
2797
|
+
A right-hand docked panel with two tabs, behind `features.enableSidePanels`.
|
|
2798
|
+
|
|
2799
|
+
```
|
|
2800
|
+
┌──────────────────────────┐
|
|
2801
|
+
│ Data Window │ Objects │✕ │
|
|
2802
|
+
├──────────────────────────┤
|
|
2803
|
+
│ Date 12 Aug 2026│
|
|
2804
|
+
│ Open 149.73│
|
|
2805
|
+
│ Close 148.56│
|
|
2806
|
+
│ Change -1.17 (-0.78%) │
|
|
2807
|
+
│ MA(20) 150.56│
|
|
2808
|
+
│ MACD(12, 26, 9) │
|
|
2809
|
+
│ MACD 1.22│
|
|
2810
|
+
│ Signal 1.84│
|
|
2811
|
+
│ Histogram -0.62│
|
|
2812
|
+
└──────────────────────────┘
|
|
2813
|
+
```
|
|
2814
|
+
|
|
2815
|
+
```ts
|
|
2816
|
+
const chart = new ChartEngine({
|
|
2817
|
+
container,
|
|
2818
|
+
features: { enableSidePanels: true },
|
|
2819
|
+
});
|
|
2820
|
+
|
|
2821
|
+
chart.setSidePanelTab('objects');
|
|
2822
|
+
chart.setSidePanelVisible(false); // the ✕ does this too
|
|
2823
|
+
```
|
|
2824
|
+
|
|
2825
|
+
The panel is **docked, not floating**: both tabs are read while looking at the
|
|
2826
|
+
chart, and a floating window would cover the candles the numbers describe.
|
|
2827
|
+
|
|
2828
|
+
**Closing it collapses it to an icon rail, it does not hide it.**
|
|
2829
|
+
|
|
2830
|
+
```
|
|
2831
|
+
expanded (232px) collapsed (30px)
|
|
2832
|
+
┌──────────────────┐ ┌──┐
|
|
2833
|
+
│ Data │ Objects │✕│ │ ▦ │ ← Data Window
|
|
2834
|
+
├──────────────────┤ │ ◈ │ ← Objects
|
|
2835
|
+
│ … │ │ │
|
|
2836
|
+
└──────────────────┘ └──┘
|
|
2837
|
+
```
|
|
2838
|
+
|
|
2839
|
+
A panel that vanished completely would leave nothing to click to get it back,
|
|
2840
|
+
stranding the feature behind a command palette. The rail keeps 30px and gives
|
|
2841
|
+
the chart the other 202px; the `ResizeObserver` already watching `canvasWrap`
|
|
2842
|
+
resizes the canvases for free. Each rail icon opens straight onto *its* tab
|
|
2843
|
+
rather than reopening whatever was last showing, and the last-opened one stays
|
|
2844
|
+
marked so reopening is a single click on the icon already highlighted.
|
|
2845
|
+
|
|
2846
|
+
`setSidePanelVisible(false)` is the same operation as the ✕ — expanded versus
|
|
2847
|
+
rail. `features.enableSidePanels` is what removes the panel entirely.
|
|
2848
|
+
|
|
2849
|
+
### Data Window
|
|
2850
|
+
|
|
2851
|
+
The bar under the cursor — or the last bar when the cursor is off the plot —
|
|
2852
|
+
followed by one block per visible indicator, refreshed from the render pass so
|
|
2853
|
+
it coalesces with the animation frame instead of firing on every pointer event.
|
|
2854
|
+
|
|
2855
|
+
Values come from the engine's existing per-instance result cache, which is a
|
|
2856
|
+
full-length array indexed by bar, so nothing is recomputed to fill the panel.
|
|
2857
|
+
Only indicators that are actually being recomputed are listed: a hidden or
|
|
2858
|
+
timeframe-locked instance holds a stale cache and showing it would present old
|
|
2859
|
+
numbers as current.
|
|
2860
|
+
|
|
2861
|
+
**Indicator fields are named by what they are.** `IndicatorResult` has five
|
|
2862
|
+
fixed slots — `value`, `upper`, `lower`, `signal`, `histogram` — and indicators
|
|
2863
|
+
do not agree on what they mean. MACD puts its signal line in `upper` and its
|
|
2864
|
+
histogram in `lower`, where Bollinger puts bands in both, so labelling the slots
|
|
2865
|
+
generically would print `Upper 1.84` for a MACD signal. A small table names the
|
|
2866
|
+
ones that differ; everything else falls back.
|
|
2867
|
+
|
|
2868
|
+
A single-line indicator renders as one `MA(20): 150.56` row rather than a
|
|
2869
|
+
heading with one orphan beneath it. One still warming up shows a dash, because
|
|
2870
|
+
omitting the block would read as the indicator having been removed.
|
|
2871
|
+
|
|
2872
|
+
Rows use tabular figures so the value column does not jitter as digits change
|
|
2873
|
+
under a moving crosshair, and the panel **reconciles rather than rebuilds** —
|
|
2874
|
+
it keys on the row labels and, when they are unchanged, writes only the text.
|
|
2875
|
+
|
|
2876
|
+
### Object Tree
|
|
2877
|
+
|
|
2878
|
+
Everything on the chart, grouped, with per-row show/hide, lock and remove.
|
|
2879
|
+
Clicking a drawing row selects it; clicking an indicator row opens its settings.
|
|
2880
|
+
Empty groups are omitted rather than shown as a zero.
|
|
2881
|
+
|
|
2882
|
+
Drawing names come from `labels.drawingToolbar.tools` — the toolbar's own label
|
|
2883
|
+
map, so the tree is localised by the same override a host already supplies. A
|
|
2884
|
+
text tool shows its first line beside the type name, clipped, since a Table or
|
|
2885
|
+
Note carries several and the rest would push every other row off the panel.
|
|
2886
|
+
|
|
2887
|
+
Indicators get **no lock control**: there is nothing to lock. The panel reads an
|
|
2888
|
+
absent `locked` as exactly that rather than needing a flag.
|
|
2889
|
+
|
|
2890
|
+
### New per-object primitives
|
|
2891
|
+
|
|
2892
|
+
The manager only had bulk operations, so these are new:
|
|
2893
|
+
|
|
2894
|
+
```ts
|
|
2895
|
+
chart.setDrawingVisible(id, false);
|
|
2896
|
+
chart.setDrawingLocked(id, true);
|
|
2897
|
+
chart.deleteDrawing(id); // not "select it, then delete"
|
|
2898
|
+
chart.selectDrawing(id); // null clears
|
|
2899
|
+
chart.toggleIndicatorVisibility(instanceId);
|
|
2900
|
+
```
|
|
2901
|
+
|
|
2902
|
+
`deleteDrawing` is separate from `deleteSelected()` on purpose: selecting fires
|
|
2903
|
+
`onSelectionChange`, which opens the style popover on a drawing that is about to
|
|
2904
|
+
disappear. Hiding or locking the selected drawing deselects it, the way the bulk
|
|
2905
|
+
operations already did — a selection box floating over nothing, with a popover
|
|
2906
|
+
attached, is worse than losing the selection. All three take an undo snapshot.
|
|
2907
|
+
|
|
2908
|
+
### Reopening
|
|
2909
|
+
|
|
2910
|
+
Click either rail icon. Three Quick Search commands do the same from the
|
|
2911
|
+
keyboard: **Open Data Window**, **Open Object Tree**, **Toggle side panel**.
|
|
2912
|
+
|
|
2913
|
+
### Rendering the data yourself
|
|
2914
|
+
|
|
2915
|
+
`buildDataWindow()` and `buildObjectTree()` are exported as pure functions, and
|
|
2916
|
+
`SidePanel` takes their output. A host can render the same rows in its own
|
|
2917
|
+
chrome, or feed the panel from somewhere other than the chart.
|
|
2918
|
+
|
|
2919
|
+
|
|
2920
|
+
## Custom Indicator
|
|
2921
|
+
|
|
2922
|
+
Implement `IIndicator` and pass it to `addIndicator()`:
|
|
2923
|
+
|
|
2924
|
+
```ts
|
|
2925
|
+
import type { IIndicator, OHLCVBar, IndicatorResult } from 'acttrader-charts';
|
|
2926
|
+
|
|
2927
|
+
class MyIndicator implements IIndicator {
|
|
2928
|
+
name = 'MyInd';
|
|
2929
|
+
color = '#e91e63';
|
|
2930
|
+
pane = 'sub' as const; // 'main' = overlay, 'sub' = dedicated pane
|
|
2931
|
+
paneHeight = 80;
|
|
2932
|
+
|
|
2933
|
+
compute(data: OHLCVBar[]): IndicatorResult[] {
|
|
2934
|
+
return data.map((bar, i) => ({ index: i, value: bar.close }));
|
|
2935
|
+
}
|
|
2936
|
+
|
|
2937
|
+
render(ctx, results, scale, viewport, chartHeight) {
|
|
2938
|
+
// draw with ctx (Canvas 2D)
|
|
2939
|
+
}
|
|
2940
|
+
}
|
|
2941
|
+
|
|
2942
|
+
chart.addIndicator(new MyIndicator());
|
|
2943
|
+
```
|
|
2944
|
+
|
|
2945
|
+
---
|
|
2946
|
+
|
|
2947
|
+
## Build & Dev
|
|
2948
|
+
|
|
2949
|
+
```bash
|
|
2950
|
+
npm run dev # Vite dev server with demo chart
|
|
2951
|
+
npm run build # ESM + CJS via tsup → dist/
|
|
2952
|
+
npm run test # Vitest unit tests
|
|
2953
|
+
npm run typecheck # tsc --noEmit
|
|
2954
|
+
npm run lint # ESLint
|
|
2955
|
+
```
|
|
2956
|
+
|
|
2957
|
+
---
|
|
2958
|
+
|
|
2959
|
+
## License
|
|
2960
|
+
|
|
2961
|
+
MIT
|
|
2962
|
+
|
|
2963
|
+
## Bar Replay
|
|
2964
|
+
|
|
2965
|
+
Replay history bar by bar, as TradingView does. `enableReplay: true` adds a
|
|
2966
|
+
**Replay** button to the header (simple and advanced layouts); it opens a
|
|
2967
|
+
control strip under the chart:
|
|
2968
|
+
|
|
2969
|
+
```
|
|
2970
|
+
⇤ Select bar ▾ │ ▷ ▷| 1x 1D │ ▷▷| ✕
|
|
2971
|
+
```
|
|
2972
|
+
|
|
2973
|
+
- **Select bar** — a cut line with a scissors badge follows the pointer; click
|
|
2974
|
+
a bar and everything from it onward is hidden. The ▾ menu also offers
|
|
2975
|
+
**Select date…**, **First available date** and **Random bar**.
|
|
2976
|
+
- **▷ / ▷|** — play at the chosen speed (`0.1x` – `10x` bars per second) or
|
|
2977
|
+
step one bar forward. Keyboard: `Shift+→` step, `Shift+↓` play/pause,
|
|
2978
|
+
`Esc` leaves select mode.
|
|
2979
|
+
- **▷▷|** — jump to real time: every hidden bar comes back, including live
|
|
2980
|
+
bars built while the replay ran. **✕** closes the strip.
|
|
2981
|
+
|
|
2982
|
+
Live ticks keep updating the hidden series during a replay, so nothing is
|
|
2983
|
+
lost; a `loadData()` during a replay (timeframe or symbol change) keeps the
|
|
2984
|
+
replay date. Default `false`; without it nothing changes.
|
|
2985
|
+
|
|
2986
|
+
```ts
|
|
2987
|
+
const chart = new ChartEngine({ container, enableReplay: true });
|
|
2988
|
+
|
|
2989
|
+
// Drive it from code (works without the header button too):
|
|
2990
|
+
chart.openReplay(); // show the strip, arm "Select bar"
|
|
2991
|
+
chart.startReplay('2026-06-01'); // hide bars after this date (number | Date | string)
|
|
2992
|
+
chart.setReplaySpeed(3); // bars per second
|
|
2993
|
+
chart.playReplay(); chart.pauseReplay(); chart.replayStepForward();
|
|
2994
|
+
chart.exitReplay(); // back to real time, strip stays open
|
|
2995
|
+
chart.closeReplay(); // back to real time and close the strip
|
|
2996
|
+
chart.isReplayActive();
|
|
2997
|
+
|
|
2998
|
+
chart.on('replayStart', ({ time }) => { /* bars after `time` are hidden */ });
|
|
2999
|
+
chart.on('replayStep', ({ time }) => { /* one more bar revealed */ });
|
|
3000
|
+
chart.on('replayEnd', ({ time }) => { /* last hidden bar revealed */ });
|
|
3001
|
+
chart.on('replayExit', () => { /* live chart is back */ });
|
|
3002
|
+
```
|
|
3003
|
+
|
|
3004
|
+
On Android and iOS the same controls are bridge commands — `openReplay`,
|
|
3005
|
+
`closeReplay`, `startReplay { time }`, `playReplay`, `pauseReplay`,
|
|
3006
|
+
`replayStepForward`, `setReplaySpeed { barsPerSecond }`, `exitReplay` — with
|
|
3007
|
+
`enableReplay` on `init`; the four events above arrive through the bridge and the
|
|
3008
|
+
mobile header gets its own Replay button. See the `charts-android` and
|
|
3009
|
+
`charts-ios` READMEs for the Kotlin / Swift calls.
|
|
3010
|
+
|
|
3011
|
+
## Two-finger measure (mobile)
|
|
3012
|
+
|
|
3013
|
+
Hold two fingers on the chart and it shows what the TradingView app shows: a
|
|
3014
|
+
pill over the range with the **close and date under each finger** and, between
|
|
3015
|
+
them, the **change in price and percent**, coloured by direction; a vertical
|
|
3016
|
+
line and a dot on the close mark each finger and the range is tinted. Moving
|
|
3017
|
+
the fingers moves the measurement; lifting either finger ends it. Pinch still
|
|
3018
|
+
zooms — the measure only starts once both fingers have rested for ~0.3 s.
|
|
3019
|
+
|
|
3020
|
+
```ts
|
|
3021
|
+
new ChartEngine({ container, enableTwoFingerMeasure: true });
|
|
3022
|
+
|
|
3023
|
+
chart.on('twoFingerMeasure', ({ phase, startTime, endTime, startClose, endClose, change, changePercent, bars }) => {
|
|
3024
|
+
// phase: 'start' | 'update' | 'end'
|
|
3025
|
+
});
|
|
3026
|
+
```
|
|
3027
|
+
|
|
3028
|
+
Touch-only, so desktop is unaffected. Default `false`. On Android / iOS set
|
|
3029
|
+
`enableTwoFingerMeasure` on `init`; the event arrives through the bridge.
|