acttrader-charts 1.2.0-beta.1 → 1.2.0-beta.2

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 CHANGED
@@ -84,6 +84,35 @@ chart.removeIndicator('SMA');
84
84
 
85
85
  Indicator pills appear inline above the chart (up to 2 visible; beyond that collapses into a dropdown).
86
86
 
87
+ #### Multiple instances of the same study
88
+
89
+ Parameterized studies support **multiple simultaneous instances** — e.g. EMA-20, EMA-50 and
90
+ EMA-200, or RSI-14 alongside RSI-7. Each instance gets an auto-cycled color so they're visually
91
+ distinct, and oscillators (RSI, MACD, …) each render in their own stacked sub-pane.
92
+
93
+ ```ts
94
+ chart.addIndicatorByName('EMA'); // EMA-20 (default)
95
+ chart.addIndicatorByName('EMA'); // a 2nd EMA, different color
96
+ // or build instances directly with different params:
97
+ chart.addIndicator(new EMA(50, '#22c55e'));
98
+ chart.addIndicator(new EMA(200, '#ef4444'));
99
+ ```
100
+
101
+ Selecting an already-active study in the Studies dropdown **adds another instance**. Remove a
102
+ specific instance via its pill **×** or the settings dialog's Remove button.
103
+
104
+ Each instance has a unique `instanceId` (e.g. `"EMA#3"`). Listen for it via the `indicatorAdded`
105
+ event and pass it to `removeIndicator` to target one instance:
106
+
107
+ ```ts
108
+ chart.on('indicatorAdded', ({ instanceId, shortName, params }) => { /* track it */ });
109
+ chart.removeIndicator('EMA#3'); // remove that one instance
110
+ chart.removeIndicator('EMA'); // (back-compat) remove ALL EMA instances
111
+ ```
112
+
113
+ A handful of studies remain **single-instance** (re-selecting toggles them off): `VOL`, `OBV`,
114
+ `A/D`, `AO`, `VWAP`, `Ichimoku`, `PSAR`, `Pivot`, and Heikin-Ashi.
115
+
87
116
  ### Drawing Tools
88
117
 
89
118
  ```ts
@@ -603,10 +632,16 @@ chart.setVolume(show: boolean): this
603
632
  ### Indicators
604
633
 
605
634
  ```ts
606
- chart.addIndicator(indicator: IIndicator): this
607
- chart.removeIndicator(name: string): this
635
+ chart.addIndicator(indicator: IIndicator, initialParams?: IndicatorParams): this
636
+ chart.addIndicatorByName(shortName: string, params?: IndicatorParams): void
637
+ chart.removeIndicator(idOrShortName: string): this
608
638
  ```
609
639
 
640
+ - `addIndicator` / `addIndicatorByName` — add a study. Multi-instance studies add a new instance
641
+ per call (auto-cycled color); single-instance studies toggle. `params` overrides period/color/source.
642
+ - `removeIndicator` — pass an `instanceId` (e.g. `"EMA#3"`, from the `indicatorAdded` event) to remove
643
+ that one instance, or a `shortName` (e.g. `"EMA"`) to remove **all** instances of that type.
644
+
610
645
  ### Drawing Tools
611
646
 
612
647
  ```ts
@@ -834,6 +869,8 @@ chart.on('seriesChange', ({ series }) => {});
834
869
  chart.on('streamStatus', ({ status }) => {}); // 'connected' | 'reconnecting' | 'disconnected'
835
870
  chart.on('dataLoaded', ({ timeframe, interval, start, end }) => {});
836
871
  chart.on('newBar', ({ completedBar, openingBar, intervalMs }) => {});
872
+ chart.on('indicatorAdded', ({ instanceId, shortName, params }) => {}); // a study instance was added — keep instanceId to remove it later
873
+ chart.on('indicatorRemoved', ({ instanceId, shortName }) => {});
837
874
  chart.on('stateChange', ({ symbol, state }) => {
838
875
  // Fires after every user-driven config change (timeframe, series, theme,
839
876
  // indicators, drawings, volume). `state` is a full serializable snapshot.
@@ -1228,6 +1228,13 @@ interface IWebSocketAdapter {
1228
1228
  }
1229
1229
  type IndicatorParams = Record<string, number | string>;
1230
1230
  interface ActiveIndicatorState {
1231
+ /**
1232
+ * Unique per-instance identifier (e.g. "EMA#3"). Distinguishes multiple
1233
+ * active instances of the same indicator type. All per-instance state and
1234
+ * UI (results cache, sub-pane overlays, scale factors, pills) is keyed by
1235
+ * this, not by `shortName` — so e.g. EMA-20, EMA-50 and EMA-200 can coexist.
1236
+ */
1237
+ instanceId: string;
1231
1238
  indicator: IIndicator;
1232
1239
  shortName: string;
1233
1240
  currentParams: IndicatorParams;
@@ -1250,6 +1257,12 @@ interface IndicatorStateEntry {
1250
1257
  shortName: string;
1251
1258
  params: IndicatorParams;
1252
1259
  visible?: boolean;
1260
+ /**
1261
+ * Per-instance id captured at serialization time. Optional for backward
1262
+ * compatibility — configs saved before multi-instance support omit it, and
1263
+ * `setState` mints a fresh id when it's absent.
1264
+ */
1265
+ instanceId?: string;
1253
1266
  }
1254
1267
  /** Color overrides for the chart canvas elements (background, grid, candles, etc.). */
1255
1268
  interface CanvasColorSettings {
@@ -1558,6 +1571,22 @@ type ChartEventMap = {
1558
1571
  symbol: string;
1559
1572
  message: string;
1560
1573
  };
1574
+ /**
1575
+ * Emitted after an indicator instance is added. `instanceId` uniquely
1576
+ * identifies the instance (e.g. "EMA#3") so callers can later remove that
1577
+ * specific instance via `removeIndicator(instanceId)` — important now that
1578
+ * multiple instances of the same `shortName` can coexist.
1579
+ */
1580
+ indicatorAdded: {
1581
+ instanceId: string;
1582
+ shortName: string;
1583
+ params: IndicatorParams;
1584
+ };
1585
+ /** Emitted after an indicator instance is removed (pill ×, settings dialog, or `removeIndicator`). */
1586
+ indicatorRemoved: {
1587
+ instanceId: string;
1588
+ shortName: string;
1589
+ };
1561
1590
  };
1562
1591
  /** Distinguishes level types: historical trade, open position, or pending order. */
1563
1592
  type TradeLevelType = 'trade' | 'position' | 'pending';
@@ -1749,4 +1778,4 @@ declare class MACD implements IIndicator {
1749
1778
  render(ctx: CanvasRenderingContext2D, results: IndicatorResult[], scale: ScaleManager, viewport: Viewport, paneHeight: number, rangeOverride?: PriceRange): void;
1750
1779
  }
1751
1780
 
1752
- export { type Duration as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_DRAWING_TOOLBAR_CONFIG as E, DEFAULT_INDICATOR_OVERLAY_CONFIG as F, DEFAULT_LABELS as G, DEFAULT_LAYOUT_SYNC as H, type IIndicator as I, DEFAULT_PRICE_AXIS_CONFIG as J, DEFAULT_TIME_AXIS_CONFIG as K, type LayoutSyncState as L, DEFAULT_TOP_BAR_CONFIG as M, DEFAULT_TRADE_BUTTON_CONFIG as N, type OHLCVBar as O, type PriceRange as P, DEFAULT_UI_CONFIG as Q, type DataLoaderParams as R, type SeriesType as S, type Timeframe as T, type DeepPartial$1 as U, type Viewport as V, type DeepPartialChartTheme as W, type DialogLabels as X, type DrawingToolbarColors as Y, type DrawingToolbarLabels as Z, type DrawingToolbarUiConfig as _, type ChartEventMap as a, EMA as a0, type IndicatorOverlayColors as a1, type IndicatorOverlayUiConfig as a2, type IndicatorParams as a3, type IndicatorResult as a4, type IndicatorStateEntry as a5, LAYOUT_PRESETS as a6, LIGHT_THEME as a7, type LayoutPreset as a8, MACD as a9, getAllPresets as aA, getCustomPresets as aB, getPreset as aC, registerCustomPreset as aD, resolveCssVarsInTheme as aE, resolveLabels as aF, resolveUiConfig as aG, unregisterCustomPreset as aH, type PriceSource as aI, type OhlcLabels as aa, type OrderSubmit as ab, PRESETS_BY_COUNT as ac, PRESET_COUNTS as ad, PRESET_LABEL as ae, type Padding as af, type PendingOrderLevel as ag, type PositionLevel as ah, type PositionRenderStyle as ai, type PriceAxisUiConfig as aj, RSI as ak, SMA as al, type Theme as am, type ThemeOverrides as an, type TimeAxisUiConfig as ao, type TopBarColors as ap, type TopBarLabels as aq, type TopBarUiConfig as ar, type TradeButtonUiConfig as as, type TradeDisplayFilter as at, type TradeLabels as au, type TradeLevel as av, type TradeLevelColors as aw, type TradePanelColors as ax, type UiConfig as ay, deepMergeTheme as az, type ChartState as b, type IDrawing as c, type IWebSocketAdapter as d, type TradeLevelType as e, type ChartTheme as f, type AnyLevel as g, type DrawingPoint as h, ScaleManager as i, type DrawingHandle as j, type SerializedDrawing as k, type Tick as l, type StreamStatus as m, type ActiveIndicatorState as n, type BottomBarColors as o, type BottomBarLabels as p, type BottomBarUiConfig as q, type CanvasColorSettings as r, type ChartLabels as s, type ChartMiscLabels as t, type ChartThemeUi as u, type CrosshairPosition as v, type CrosshairUiConfig as w, DARK_THEME as x, DEFAULT_BOTTOM_BAR_CONFIG as y, DEFAULT_CROSSHAIR_CONFIG as z };
1781
+ export { type DrawingToolbarUiConfig as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_CROSSHAIR_CONFIG as E, DEFAULT_DRAWING_TOOLBAR_CONFIG as F, DEFAULT_INDICATOR_OVERLAY_CONFIG as G, DEFAULT_LABELS as H, type IIndicator as I, DEFAULT_LAYOUT_SYNC as J, DEFAULT_PRICE_AXIS_CONFIG as K, type LayoutSyncState as L, DEFAULT_TIME_AXIS_CONFIG as M, DEFAULT_TOP_BAR_CONFIG as N, type OHLCVBar as O, type PriceRange as P, DEFAULT_TRADE_BUTTON_CONFIG as Q, DEFAULT_UI_CONFIG as R, type SeriesType as S, type Timeframe as T, type DataLoaderParams as U, type Viewport as V, type DeepPartial$1 as W, type DeepPartialChartTheme as X, type DialogLabels as Y, type DrawingToolbarColors as Z, type DrawingToolbarLabels as _, type IndicatorParams as a, type Duration as a0, EMA as a1, type IndicatorOverlayColors as a2, type IndicatorOverlayUiConfig as a3, type IndicatorResult as a4, type IndicatorStateEntry as a5, LAYOUT_PRESETS as a6, LIGHT_THEME as a7, type LayoutPreset as a8, MACD as a9, getAllPresets as aA, getCustomPresets as aB, getPreset as aC, registerCustomPreset as aD, resolveCssVarsInTheme as aE, resolveLabels as aF, resolveUiConfig as aG, unregisterCustomPreset as aH, type PriceSource as aI, type OhlcLabels as aa, type OrderSubmit as ab, PRESETS_BY_COUNT as ac, PRESET_COUNTS as ad, PRESET_LABEL as ae, type Padding as af, type PendingOrderLevel as ag, type PositionLevel as ah, type PositionRenderStyle as ai, type PriceAxisUiConfig as aj, RSI as ak, SMA as al, type Theme as am, type ThemeOverrides as an, type TimeAxisUiConfig as ao, type TopBarColors as ap, type TopBarLabels as aq, type TopBarUiConfig as ar, type TradeButtonUiConfig as as, type TradeDisplayFilter as at, type TradeLabels as au, type TradeLevel as av, type TradeLevelColors as aw, type TradePanelColors as ax, type UiConfig as ay, deepMergeTheme as az, type ChartEventMap as b, type ChartState as c, type IDrawing as d, type IWebSocketAdapter as e, type TradeLevelType as f, type ChartTheme as g, type AnyLevel as h, type DrawingPoint as i, ScaleManager as j, type DrawingHandle as k, type SerializedDrawing as l, type Tick as m, type StreamStatus as n, type ActiveIndicatorState as o, type BottomBarColors as p, type BottomBarLabels as q, type BottomBarUiConfig as r, type CanvasColorSettings as s, type ChartLabels as t, type ChartMiscLabels as u, type ChartThemeUi as v, type CrosshairPosition as w, type CrosshairUiConfig as x, DARK_THEME as y, DEFAULT_BOTTOM_BAR_CONFIG as z };
@@ -1228,6 +1228,13 @@ interface IWebSocketAdapter {
1228
1228
  }
1229
1229
  type IndicatorParams = Record<string, number | string>;
1230
1230
  interface ActiveIndicatorState {
1231
+ /**
1232
+ * Unique per-instance identifier (e.g. "EMA#3"). Distinguishes multiple
1233
+ * active instances of the same indicator type. All per-instance state and
1234
+ * UI (results cache, sub-pane overlays, scale factors, pills) is keyed by
1235
+ * this, not by `shortName` — so e.g. EMA-20, EMA-50 and EMA-200 can coexist.
1236
+ */
1237
+ instanceId: string;
1231
1238
  indicator: IIndicator;
1232
1239
  shortName: string;
1233
1240
  currentParams: IndicatorParams;
@@ -1250,6 +1257,12 @@ interface IndicatorStateEntry {
1250
1257
  shortName: string;
1251
1258
  params: IndicatorParams;
1252
1259
  visible?: boolean;
1260
+ /**
1261
+ * Per-instance id captured at serialization time. Optional for backward
1262
+ * compatibility — configs saved before multi-instance support omit it, and
1263
+ * `setState` mints a fresh id when it's absent.
1264
+ */
1265
+ instanceId?: string;
1253
1266
  }
1254
1267
  /** Color overrides for the chart canvas elements (background, grid, candles, etc.). */
1255
1268
  interface CanvasColorSettings {
@@ -1558,6 +1571,22 @@ type ChartEventMap = {
1558
1571
  symbol: string;
1559
1572
  message: string;
1560
1573
  };
1574
+ /**
1575
+ * Emitted after an indicator instance is added. `instanceId` uniquely
1576
+ * identifies the instance (e.g. "EMA#3") so callers can later remove that
1577
+ * specific instance via `removeIndicator(instanceId)` — important now that
1578
+ * multiple instances of the same `shortName` can coexist.
1579
+ */
1580
+ indicatorAdded: {
1581
+ instanceId: string;
1582
+ shortName: string;
1583
+ params: IndicatorParams;
1584
+ };
1585
+ /** Emitted after an indicator instance is removed (pill ×, settings dialog, or `removeIndicator`). */
1586
+ indicatorRemoved: {
1587
+ instanceId: string;
1588
+ shortName: string;
1589
+ };
1561
1590
  };
1562
1591
  /** Distinguishes level types: historical trade, open position, or pending order. */
1563
1592
  type TradeLevelType = 'trade' | 'position' | 'pending';
@@ -1749,4 +1778,4 @@ declare class MACD implements IIndicator {
1749
1778
  render(ctx: CanvasRenderingContext2D, results: IndicatorResult[], scale: ScaleManager, viewport: Viewport, paneHeight: number, rangeOverride?: PriceRange): void;
1750
1779
  }
1751
1780
 
1752
- export { type Duration as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_DRAWING_TOOLBAR_CONFIG as E, DEFAULT_INDICATOR_OVERLAY_CONFIG as F, DEFAULT_LABELS as G, DEFAULT_LAYOUT_SYNC as H, type IIndicator as I, DEFAULT_PRICE_AXIS_CONFIG as J, DEFAULT_TIME_AXIS_CONFIG as K, type LayoutSyncState as L, DEFAULT_TOP_BAR_CONFIG as M, DEFAULT_TRADE_BUTTON_CONFIG as N, type OHLCVBar as O, type PriceRange as P, DEFAULT_UI_CONFIG as Q, type DataLoaderParams as R, type SeriesType as S, type Timeframe as T, type DeepPartial$1 as U, type Viewport as V, type DeepPartialChartTheme as W, type DialogLabels as X, type DrawingToolbarColors as Y, type DrawingToolbarLabels as Z, type DrawingToolbarUiConfig as _, type ChartEventMap as a, EMA as a0, type IndicatorOverlayColors as a1, type IndicatorOverlayUiConfig as a2, type IndicatorParams as a3, type IndicatorResult as a4, type IndicatorStateEntry as a5, LAYOUT_PRESETS as a6, LIGHT_THEME as a7, type LayoutPreset as a8, MACD as a9, getAllPresets as aA, getCustomPresets as aB, getPreset as aC, registerCustomPreset as aD, resolveCssVarsInTheme as aE, resolveLabels as aF, resolveUiConfig as aG, unregisterCustomPreset as aH, type PriceSource as aI, type OhlcLabels as aa, type OrderSubmit as ab, PRESETS_BY_COUNT as ac, PRESET_COUNTS as ad, PRESET_LABEL as ae, type Padding as af, type PendingOrderLevel as ag, type PositionLevel as ah, type PositionRenderStyle as ai, type PriceAxisUiConfig as aj, RSI as ak, SMA as al, type Theme as am, type ThemeOverrides as an, type TimeAxisUiConfig as ao, type TopBarColors as ap, type TopBarLabels as aq, type TopBarUiConfig as ar, type TradeButtonUiConfig as as, type TradeDisplayFilter as at, type TradeLabels as au, type TradeLevel as av, type TradeLevelColors as aw, type TradePanelColors as ax, type UiConfig as ay, deepMergeTheme as az, type ChartState as b, type IDrawing as c, type IWebSocketAdapter as d, type TradeLevelType as e, type ChartTheme as f, type AnyLevel as g, type DrawingPoint as h, ScaleManager as i, type DrawingHandle as j, type SerializedDrawing as k, type Tick as l, type StreamStatus as m, type ActiveIndicatorState as n, type BottomBarColors as o, type BottomBarLabels as p, type BottomBarUiConfig as q, type CanvasColorSettings as r, type ChartLabels as s, type ChartMiscLabels as t, type ChartThemeUi as u, type CrosshairPosition as v, type CrosshairUiConfig as w, DARK_THEME as x, DEFAULT_BOTTOM_BAR_CONFIG as y, DEFAULT_CROSSHAIR_CONFIG as z };
1781
+ export { type DrawingToolbarUiConfig as $, type AnyDrawingStyle as A, BollingerBands as B, type ChartConfig as C, type DrawingToolType as D, DEFAULT_CROSSHAIR_CONFIG as E, DEFAULT_DRAWING_TOOLBAR_CONFIG as F, DEFAULT_INDICATOR_OVERLAY_CONFIG as G, DEFAULT_LABELS as H, type IIndicator as I, DEFAULT_LAYOUT_SYNC as J, DEFAULT_PRICE_AXIS_CONFIG as K, type LayoutSyncState as L, DEFAULT_TIME_AXIS_CONFIG as M, DEFAULT_TOP_BAR_CONFIG as N, type OHLCVBar as O, type PriceRange as P, DEFAULT_TRADE_BUTTON_CONFIG as Q, DEFAULT_UI_CONFIG as R, type SeriesType as S, type Timeframe as T, type DataLoaderParams as U, type Viewport as V, type DeepPartial$1 as W, type DeepPartialChartTheme as X, type DialogLabels as Y, type DrawingToolbarColors as Z, type DrawingToolbarLabels as _, type IndicatorParams as a, type Duration as a0, EMA as a1, type IndicatorOverlayColors as a2, type IndicatorOverlayUiConfig as a3, type IndicatorResult as a4, type IndicatorStateEntry as a5, LAYOUT_PRESETS as a6, LIGHT_THEME as a7, type LayoutPreset as a8, MACD as a9, getAllPresets as aA, getCustomPresets as aB, getPreset as aC, registerCustomPreset as aD, resolveCssVarsInTheme as aE, resolveLabels as aF, resolveUiConfig as aG, unregisterCustomPreset as aH, type PriceSource as aI, type OhlcLabels as aa, type OrderSubmit as ab, PRESETS_BY_COUNT as ac, PRESET_COUNTS as ad, PRESET_LABEL as ae, type Padding as af, type PendingOrderLevel as ag, type PositionLevel as ah, type PositionRenderStyle as ai, type PriceAxisUiConfig as aj, RSI as ak, SMA as al, type Theme as am, type ThemeOverrides as an, type TimeAxisUiConfig as ao, type TopBarColors as ap, type TopBarLabels as aq, type TopBarUiConfig as ar, type TradeButtonUiConfig as as, type TradeDisplayFilter as at, type TradeLabels as au, type TradeLevel as av, type TradeLevelColors as aw, type TradePanelColors as ax, type UiConfig as ay, deepMergeTheme as az, type ChartEventMap as b, type ChartState as c, type IDrawing as d, type IWebSocketAdapter as e, type TradeLevelType as f, type ChartTheme as g, type AnyLevel as h, type DrawingPoint as i, ScaleManager as j, type DrawingHandle as k, type SerializedDrawing as l, type Tick as m, type StreamStatus as n, type ActiveIndicatorState as o, type BottomBarColors as p, type BottomBarLabels as q, type BottomBarUiConfig as r, type CanvasColorSettings as s, type ChartLabels as t, type ChartMiscLabels as u, type ChartThemeUi as v, type CrosshairPosition as w, type CrosshairUiConfig as x, DARK_THEME as y, DEFAULT_BOTTOM_BAR_CONFIG as z };