trendkit 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Darshan Sachaniya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,122 @@
1
+ # trendkit
2
+
3
+ Drawing tools for [Lightweight Charts](https://github.com/tradingview/lightweight-charts) —
4
+ trendlines, rays, Fibonacci retracements, zones and a measure tool, built on
5
+ the v5 plugin API.
6
+
7
+ > **Status: pre-release.** Five drawing tools and three indicators work and
8
+ > are verified in a browser. Not yet published to npm — the React entry
9
+ > point and the documentation pass are still to come.
10
+
11
+ ## Why
12
+
13
+ Lightweight Charts is excellent and free, but it draws data — not the things a
14
+ discretionary trader puts *on* the data. Since v5 it exposes a plugin API
15
+ (`attachPrimitive`, `hitTest`, two-way coordinate conversion) that makes the
16
+ missing layer buildable. trendkit is that layer.
17
+
18
+ ## Install
19
+
20
+ ```bash
21
+ npm install trendkit lightweight-charts
22
+ ```
23
+
24
+ `lightweight-charts` is a peer dependency — trendkit never bundles its own
25
+ copy, because two chart runtimes in one page means two sets of `instanceof`
26
+ checks that disagree.
27
+
28
+ ## Use
29
+
30
+ ```ts
31
+ import { createChart, CandlestickSeries } from "lightweight-charts";
32
+ import { createTrendkit, Trendline } from "trendkit";
33
+
34
+ const chart = createChart(container);
35
+ const series = chart.addSeries(CandlestickSeries);
36
+ series.setData(candles);
37
+
38
+ const kit = createTrendkit({ chart, series, tools: [Trendline] });
39
+
40
+ kit.store.add({
41
+ id: crypto.randomUUID(),
42
+ tool: "trendline",
43
+ points: [
44
+ { time: candles[20].time, logical: 20, price: 102.65 },
45
+ { time: candles[120].time, logical: 120, price: 112.80 },
46
+ ],
47
+ });
48
+ ```
49
+
50
+ Only the tools you pass are bundled — the package is `sideEffects: false`, so
51
+ anything you leave out is tree-shaken away.
52
+
53
+ ### Indicators
54
+
55
+ Independent of the drawing tools — use either alone.
56
+
57
+ ```ts
58
+ import { addIndicator } from "trendkit";
59
+
60
+ const rsi = addIndicator(chart, { type: "rsi", period: 14 }, candles);
61
+ addIndicator(chart, { type: "macd" }, candles); // 12/26/9
62
+ addIndicator(chart, { type: "bollinger" }, candles); // 20, 2σ
63
+
64
+ rsi.setData(moreCandles); // recompute
65
+ rsi.remove(); // takes its pane with it
66
+ ```
67
+
68
+ RSI and MACD get their own panes; Bollinger overlays the price pane, because
69
+ it is the only one of the three measured in price units.
70
+
71
+ The maths follows the conventions the rest of the industry uses, which is
72
+ mostly a matter of getting three things right: RSI uses **Wilder's**
73
+ smoothing (k = 1/n), not an EMA; MACD's EMAs are **seeded with an SMA**, and
74
+ its signal line skips the leading nulls rather than treating them as zeros;
75
+ Bollinger uses **population** standard deviation, not sample. Each of those
76
+ is a way to produce numbers that look plausible and disagree with every other
77
+ platform.
78
+
79
+ The raw functions are exported too, if you only want the numbers:
80
+
81
+ ```ts
82
+ import { rsi, macd, bollinger, ema, sma, wilder, stdev } from "trendkit";
83
+ ```
84
+
85
+ ### Persistence
86
+
87
+ `toJSON()` and `fromJSON()` are the whole story. Where the result is stored is
88
+ your decision, not the library's:
89
+
90
+ ```ts
91
+ kit.store.subscribe(() => localStorage.setItem("drawings", JSON.stringify(kit.toJSON())));
92
+ ```
93
+
94
+ ## Two things it gets right
95
+
96
+ **Drawings are anchored in `(time, price)`, never pixels.** A trendline
97
+ through two candles stays through those candles when you pan, zoom or resize.
98
+ Points dragged past the last bar — where there is no `Time` to convert — fall
99
+ back to the logical bar index, so projections into empty space keep working.
100
+
101
+ **Rendering happens in bitmap space, not CSS pixels.** On a Retina screen a
102
+ 1px line drawn in CSS pixels lands across two device pixels and renders as a
103
+ grey smear. trendkit snaps to the device grid: measured on a DPR 2 display, a
104
+ 2px line is 4 fully opaque device rows with 2 antialiased edges.
105
+
106
+ ## Development
107
+
108
+ ```bash
109
+ npm install
110
+ npm run dev # the example at localhost:5174
111
+ npm test
112
+ npm run verify # typecheck + lint + test + build
113
+ ```
114
+
115
+ > `vitest` is pinned to v3. npm 10.9.2 crashes with
116
+ > `Cannot read properties of null (reading 'edgesOut')` while resolving
117
+ > vitest 4's peer graph — an npm bug, not a vitest one. Revisit when npm 11
118
+ > is common.
119
+
120
+ ## Licence
121
+
122
+ MIT