lightweight-charts-indicators 0.9.0 → 0.10.0

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.
Files changed (59) hide show
  1. package/README.md +32 -1
  2. package/dist/anchor-period.d.ts +40 -0
  3. package/dist/anchor-period.d.ts.map +1 -0
  4. package/dist/index.cjs +19513 -19433
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.mjs +10875 -10794
  8. package/dist/lower-tf-volume.d.ts +46 -0
  9. package/dist/lower-tf-volume.d.ts.map +1 -0
  10. package/dist/render/renderer.d.ts +23 -0
  11. package/dist/render/renderer.d.ts.map +1 -1
  12. package/dist/render.mjs +131 -36
  13. package/dist/standard/awesome-oscillator.d.ts +2 -7
  14. package/dist/standard/awesome-oscillator.d.ts.map +1 -1
  15. package/dist/standard/chande-mo.d.ts +3 -1
  16. package/dist/standard/chande-mo.d.ts.map +1 -1
  17. package/dist/standard/choppiness.d.ts +2 -0
  18. package/dist/standard/choppiness.d.ts.map +1 -1
  19. package/dist/standard/cumulative-volume-delta.d.ts +21 -6
  20. package/dist/standard/cumulative-volume-delta.d.ts.map +1 -1
  21. package/dist/standard/dema.d.ts +0 -1
  22. package/dist/standard/dema.d.ts.map +1 -1
  23. package/dist/standard/historical-volatility.d.ts +2 -5
  24. package/dist/standard/historical-volatility.d.ts.map +1 -1
  25. package/dist/standard/klinger.d.ts +3 -9
  26. package/dist/standard/klinger.d.ts.map +1 -1
  27. package/dist/standard/lsma.d.ts +1 -1
  28. package/dist/standard/lsma.d.ts.map +1 -1
  29. package/dist/standard/macd.d.ts +16 -3
  30. package/dist/standard/macd.d.ts.map +1 -1
  31. package/dist/standard/mcginley-dynamic.d.ts +1 -2
  32. package/dist/standard/mcginley-dynamic.d.ts.map +1 -1
  33. package/dist/standard/net-volume.d.ts +15 -5
  34. package/dist/standard/net-volume.d.ts.map +1 -1
  35. package/dist/standard/price-oscillator.d.ts +17 -10
  36. package/dist/standard/price-oscillator.d.ts.map +1 -1
  37. package/dist/standard/relative-volume-at-time.d.ts +12 -3
  38. package/dist/standard/relative-volume-at-time.d.ts.map +1 -1
  39. package/dist/standard/smma.d.ts +3 -1
  40. package/dist/standard/smma.d.ts.map +1 -1
  41. package/dist/standard/stoch-rsi.d.ts +3 -1
  42. package/dist/standard/stoch-rsi.d.ts.map +1 -1
  43. package/dist/standard/tema.d.ts +1 -3
  44. package/dist/standard/tema.d.ts.map +1 -1
  45. package/dist/standard/twap.d.ts +7 -1
  46. package/dist/standard/twap.d.ts.map +1 -1
  47. package/dist/standard/ulcer-index.d.ts +5 -3
  48. package/dist/standard/ulcer-index.d.ts.map +1 -1
  49. package/dist/standard/up-down-volume.d.ts +16 -5
  50. package/dist/standard/up-down-volume.d.ts.map +1 -1
  51. package/dist/standard/volume-delta.d.ts +15 -4
  52. package/dist/standard/volume-delta.d.ts.map +1 -1
  53. package/dist/standard/vwap.d.ts +36 -10
  54. package/dist/standard/vwap.d.ts.map +1 -1
  55. package/dist/standard/williams-alligator.d.ts +4 -4
  56. package/dist/standard/williams-alligator.d.ts.map +1 -1
  57. package/dist/standard/zigzag.d.ts +15 -3
  58. package/dist/standard/zigzag.d.ts.map +1 -1
  59. package/package.json +3 -3
package/README.md CHANGED
@@ -69,6 +69,9 @@ before, and the indicator pane keeps its height across a redraw.
69
69
  - **Render options**: `inputs` (plots whose visibility follows an input), `plots` (per-plot `visible`, `color`,
70
70
  `lineWidth`, `style`, `palette`), `lastValueVisible`, `titleVisible`, `priceLineVisible`, `precision`, and
71
71
  `autoscale: false` to leave the indicator out of the price-pane autoscale.
72
+ - **Live updates**: `reuseSeries: true` keeps the series of the previous render (same indicator, bars changed at
73
+ the end). Series of the same type, pane and creation order are kept; when only their newest points changed
74
+ (or a bar was added) those points are updated instead of the whole data being set again.
72
75
 
73
76
  The demo page (`example/`) uses the same renderer.
74
77
 
@@ -201,7 +204,7 @@ chart.timeScale().subscribeVisibleLogicalRangeChange(range => {
201
204
 
202
205
  | Indicator | Export | Description |
203
206
  |-----------|--------|-------------|
204
- | MACD | `MACD` | Relationship between two EMAs |
207
+ | MACD | `MACD` | Relationship between two moving averages (EMA or SMA) |
205
208
  | Momentum | `Momentum` | Rate of change of price |
206
209
  | Rate of Change | `ROC` | Percentage change over a period |
207
210
  | Balance of Power | `BOP` | Strength of buyers vs sellers |
@@ -372,6 +375,34 @@ const result = sma?.calculate(bars, sma.defaultInputs);
372
375
  const oscillators = indicatorRegistry.filter(i => i.category === 'Oscillators');
373
376
  ```
374
377
 
378
+ ### Settings dialog
379
+
380
+ Each registry entry gives its inputs in `inputConfig`, in the order, with the titles, limits and layout of the
381
+ original indicator. A settings dialog can be built from these fields:
382
+
383
+ | Field | Meaning |
384
+ |---|---|
385
+ | `title`, `type`, `defval`, `options`, `min`, `max`, `step` | Label, control and limits (an empty title has no label) |
386
+ | `group` | Section header: consecutive inputs with the same group are shown under it |
387
+ | `inline` | Inputs with the same `inline` id are shown on one row |
388
+ | `tooltip` | Info text of the input |
389
+ | `display` | Where the value is shown outside the dialog (`'all'`, `'none'`, ...) |
390
+ | `active` | The input is greyed out unless the condition on other inputs holds |
391
+
392
+ ```typescript
393
+ import { isInputActive } from 'oakscriptjs';
394
+ import { indicatorRegistry } from 'lightweight-charts-indicators';
395
+
396
+ const { inputConfig } = indicatorRegistry.find(i => i.id === 'ma-ribbon')!;
397
+ const inputs = { showMa2: false };
398
+
399
+ for (const input of inputConfig) {
400
+ const enabled = isInputActive(input, inputs, inputConfig); // ma2Type, ma2Source, ma2Length, ma2Color: false
401
+ }
402
+ ```
403
+
404
+ An inactive input still gives its value to `calculate`.
405
+
375
406
  ## Building
376
407
 
377
408
  ```bash
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Timeframe periods of the bars, for ports with a timeframe input (PineScript `time(tf)`, `timeframe.change(tf)`),
3
+ * and the chart timeframe of the bars (lower-timeframe volume ports).
4
+ *
5
+ * The original computes periods from the exchange time zone and the trading sessions of the symbol, which the bars
6
+ * do not carry. The port uses the UTC calendar and takes the session start of a trading day from the bars:
7
+ * - symbols with bars on Saturdays or Sundays trade every day: each UTC day is a trading day starting at 00:00 UTC
8
+ * - other symbols: the trading days are the UTC days that have bars, and a trading day starts at its first bar
9
+ * Then, as in the original:
10
+ * - "" (the chart timeframe): every bar is its own period
11
+ * - seconds / minutes: periods of the timeframe length aligned on the session start of the trading day
12
+ * - "D": the trading day; "nD": n trading days counted from the first trading day of the year (when the bars start
13
+ * after it, the count starts at the first bar)
14
+ * - "W": the week from Monday; "nW": n weeks counted from the first Monday of the year
15
+ * - "M": the month; "nM": n months counted from January
16
+ * - `time(tf)` of D / W / M periods: the session start of the first trading day of the period (the first bar of
17
+ * the period on symbols that do not trade every day)
18
+ * Exact on UTC 24x7 symbols and on symbols whose trading day is inside the UTC day with bars from the session start
19
+ * (e.g. US stocks); not on sessions that cross 00:00 UTC (futures, forex). Before the first bar the port has no
20
+ * trading days: the first period of the bars (the first year for "nD" on symbols that do not trade every day) can
21
+ * differ.
22
+ */
23
+ /**
24
+ * PineScript `time(tf)` of each bar: the start of the `tf` period that contains the bar, in the unit of the bar
25
+ * times (seconds as lightweight-charts, or ms). A bar opens a new period (`timeframe.change(tf)`) when its value
26
+ * differs from the previous bar's. `tf` = "" (the chart timeframe) gives the bar times.
27
+ * @throws RangeError for a string that is not a timeframe, or a tick timeframe
28
+ */
29
+ export declare function periodStarts(bars: ReadonlyArray<{
30
+ time: number;
31
+ }>, tf: string): number[];
32
+ /**
33
+ * Chart timeframe of the bars ("1", "60", "1D", "1W", "1M", ...), from the most frequent gap between two bars
34
+ * (`barInterval`): one day on daily bars even with weekends and holidays, 28 to 31 days on monthly bars.
35
+ * Empty string with fewer than 2 bars.
36
+ */
37
+ export declare function chartTimeframe(bars: ReadonlyArray<{
38
+ time: number;
39
+ }>): string;
40
+ //# sourceMappingURL=anchor-period.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anchor-period.d.ts","sourceRoot":"","sources":["../src/anchor-period.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AA2BH;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE,CA+CxF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,aAAa,CAAC;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,MAAM,CAQ5E"}