@lacspace/patterns 0.0.0-stage → 1.0.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.
@@ -0,0 +1,415 @@
1
+ /** Shared bar type and the few series helpers the detectors need (Wilder ATR, volume profile). */
2
+ interface Bar {
3
+ /** Unix seconds (bar open). */
4
+ time: number;
5
+ open: number;
6
+ high: number;
7
+ low: number;
8
+ close: number;
9
+ volume: number;
10
+ }
11
+ type Series = (number | null)[];
12
+ /** A horizontal box / line on the price pane. */
13
+ interface StudyZone {
14
+ /** First bar index. */
15
+ from: number;
16
+ /** Last bar index; null = runs to the right edge. */
17
+ to: number | null;
18
+ top: number;
19
+ bottom: number;
20
+ color: string;
21
+ label?: string;
22
+ /** Dashed outline / line instead of solid. */
23
+ dashed?: boolean;
24
+ }
25
+ /** Wilder's moving average (RMA), seeded with the SMA of the first `n` values. */
26
+ declare function rma(values: Series, n: number): Series;
27
+ declare function trueRange(bars: Bar[]): Series;
28
+ /** Average true range (Wilder). */
29
+ declare function atr(bars: Bar[], n?: number): Series;
30
+ /** Volume by price: `rows` buckets, each with up and down volume, plus POC and the 70% value area. */
31
+ declare function volumeProfile(bars: Bar[], rows?: number): {
32
+ buckets: {
33
+ lo: number;
34
+ hi: number;
35
+ up: number;
36
+ down: number;
37
+ }[];
38
+ poc: number;
39
+ vaLow: number;
40
+ vaHigh: number;
41
+ max: number;
42
+ } | null;
43
+
44
+ /**
45
+ * Pattern recognition on recorded bars: harmonic patterns (Gartley, Bat,
46
+ * Butterfly, Crab, Cypher, AB=CD), an Elliott-wave impulse count, classic chart
47
+ * patterns (double tops/bottoms, head & shoulders, triangles, wedges,
48
+ * channels) and per-session market / volume profiles.
49
+ *
50
+ * Everything is found from ATR-sized swings, so the same settings work on a
51
+ * 5-minute chart and a weekly one. These are rule-based detections of
52
+ * geometry already on the chart — descriptive, never a forecast. Wave counts
53
+ * in particular are subjective; this shows one count that obeys the rules.
54
+ */
55
+
56
+ /** A polyline on the price pane. `i` is a bar index (may run past the last bar for projections). */
57
+ interface StudyPath {
58
+ pts: {
59
+ i: number;
60
+ p: number;
61
+ label?: string;
62
+ }[];
63
+ color: string;
64
+ width?: number;
65
+ dashed?: boolean;
66
+ /** Fill the closed polygon with this colour at low opacity. */
67
+ fill?: boolean;
68
+ /** Name drawn beside the last point (or `labelAt`). */
69
+ label?: string;
70
+ labelAt?: number;
71
+ }
72
+ /** A histogram drawn inside one session (TPO letters or volume). */
73
+ interface StudyProfile {
74
+ from: number;
75
+ to: number;
76
+ rows: {
77
+ lo: number;
78
+ hi: number;
79
+ v: number;
80
+ up?: number;
81
+ letters?: string;
82
+ }[];
83
+ poc: number;
84
+ vaLow: number;
85
+ vaHigh: number;
86
+ /** Initial balance (first hour) for TPO profiles. */
87
+ ib?: {
88
+ lo: number;
89
+ hi: number;
90
+ };
91
+ kind: "tpo" | "vol";
92
+ color: string;
93
+ }
94
+ interface Pivot {
95
+ i: number;
96
+ p: number;
97
+ hi: boolean;
98
+ }
99
+ /**
100
+ * Alternating swing highs and lows: a swing is confirmed once price moves
101
+ * `k` × ATR(14) away from it. The last, still-forming extreme is returned as
102
+ * `tail` (not yet confirmed).
103
+ */
104
+ declare function swings(bars: Bar[], k?: number): {
105
+ piv: Pivot[];
106
+ tail: Pivot | null;
107
+ atr: number[];
108
+ };
109
+ interface HarmonicHit {
110
+ name: string;
111
+ bull: boolean;
112
+ pts: Pivot[];
113
+ /** D not yet confirmed as a swing. */
114
+ forming: boolean;
115
+ }
116
+ /**
117
+ * Harmonic XABCD patterns on the swings. Completed ones (D already reached)
118
+ * are drawn as two triangles; a pattern still waiting for D shows its
119
+ * potential reversal zone (where D would complete) as a dashed box.
120
+ */
121
+ declare function harmonics(bars: Bar[], k?: number, tolPct?: number, show?: number, up?: string, down?: string): {
122
+ paths: StudyPath[];
123
+ zones: StudyZone[];
124
+ hits: HarmonicHit[];
125
+ };
126
+ /**
127
+ * The most recent five-wave impulse whose swings obey the three hard rules:
128
+ * wave 2 never retraces past the start of wave 1, wave 3 is never the shortest
129
+ * of 1/3/5, and wave 4 never enters wave 1's territory. Swings after wave 5
130
+ * are labelled a-b-c. If the latest four swings form waves 1–4, the wave 5
131
+ * target zone (wave 1 equality to 0.618 × waves 0→3) is shown instead.
132
+ */
133
+ declare function elliott(bars: Bar[], k?: number, up?: string, down?: string, neutral?: string): {
134
+ paths: StudyPath[];
135
+ zones: StudyZone[];
136
+ };
137
+ /**
138
+ * Double tops/bottoms, head & shoulders (and inverse), and the latest
139
+ * converging / parallel structure (triangles, wedges, channels, ranges).
140
+ * `look` limits patterns to the last N bars. Tolerances scale with ATR.
141
+ */
142
+ declare function chartPatterns(bars: Bar[], k?: number, look?: number, up?: string, down?: string, neutral?: string, show?: number): {
143
+ paths: StudyPath[];
144
+ zones: StudyZone[];
145
+ found: string[];
146
+ };
147
+ /**
148
+ * Market profile (TPO): each 30-minute period of a session gets a letter
149
+ * (A = 11:00, B = 11:30 …) and every price row it traded through gets that
150
+ * letter. Shows the point of control, the 70% value area and the initial
151
+ * balance (first hour). Hourly bars use one letter per hour.
152
+ */
153
+ declare function tpoProfiles(bars: Bar[], rowsWanted?: number, sessionsShown?: number, color?: string): StudyProfile[];
154
+ /** A volume profile for each of the last N sessions, drawn inside that session. */
155
+ declare function sessionVolumeProfiles(bars: Bar[], rows?: number, sessionsShown?: number, color?: string): StudyProfile[];
156
+
157
+ /**
158
+ * Time-independent chart types built from closes: Kagi and Point & Figure.
159
+ * Like Renko and line break, each returns ordinary bars (so the price scale,
160
+ * crosshair and studies keep working) plus the extra shape the chart's
161
+ * overlay needs to draw them properly. Pure arithmetic on recorded bars.
162
+ */
163
+
164
+ interface KagiLine {
165
+ /** Thick (yang) at the start of this line. */
166
+ yang: boolean;
167
+ /** Price where the line changes thickness (passing the last shoulder / waist), if it does. */
168
+ flipAt: number | null;
169
+ }
170
+ /**
171
+ * Kagi: a line keeps going in one direction until price reverses by `rev`;
172
+ * then it steps across and turns. It turns thick (yang) when it rises above the
173
+ * previous shoulder (top) and thin (yin) when it falls below the previous
174
+ * waist (bottom). Each line becomes one bar: open = where it starts, close =
175
+ * where it ends.
176
+ */
177
+ declare function kagi(bars: Bar[], rev: number): {
178
+ bars: Bar[];
179
+ lines: KagiLine[];
180
+ };
181
+ interface PnfColumn {
182
+ /** true = a column of X (rising), false = O (falling). */
183
+ up: boolean;
184
+ /** Lowest and highest box, as multiples of the box size. */
185
+ lo: number;
186
+ hi: number;
187
+ }
188
+ /**
189
+ * Point & Figure (close method): X columns while price rises a box at a time,
190
+ * O columns while it falls; a new column only after a reversal of `rev` boxes.
191
+ * Box k sits at price k × box.
192
+ */
193
+ declare function pointFigure(bars: Bar[], box: number, rev?: number): {
194
+ bars: Bar[];
195
+ cols: PnfColumn[];
196
+ };
197
+
198
+ /**
199
+ * @lacspace/patterns — rule-based chart-pattern detection on OHLCV bars.
200
+ *
201
+ * ATR-sized swings (zigzag), harmonic XABCD patterns (Gartley, Bat, Alt Bat, Butterfly,
202
+ * Crab, Deep Crab, Cypher, AB=CD) with potential-reversal zones, an Elliott impulse count
203
+ * that obeys the three hard rules, classic chart patterns (double tops/bottoms, head &
204
+ * shoulders, triangles, wedges, channels, ranges), per-session TPO market profiles and
205
+ * volume profiles, plus Kagi and Point & Figure transforms.
206
+ *
207
+ * Descriptive geometry of what is already on the chart — never a forecast or advice.
208
+ * Results are drawing-ready (`paths`, `zones`, `profiles`) and also returned as data
209
+ * (`hits`, `found`). Contributed by the ShareRocketPro team; zero-dependency.
210
+ */
211
+
212
+ /** describe() for agents/conductors. */
213
+ declare function describe(): {
214
+ name: string;
215
+ version: string;
216
+ summary: string;
217
+ commands: ({
218
+ name: string;
219
+ input: {
220
+ type: string;
221
+ properties: {
222
+ bars: {
223
+ type: string;
224
+ description: string;
225
+ };
226
+ k: {
227
+ type: string;
228
+ default: number;
229
+ };
230
+ tolPct?: undefined;
231
+ show?: undefined;
232
+ look?: undefined;
233
+ rowsWanted?: undefined;
234
+ sessionsShown?: undefined;
235
+ rows?: undefined;
236
+ rev?: undefined;
237
+ box?: undefined;
238
+ };
239
+ required: string[];
240
+ };
241
+ output: string;
242
+ } | {
243
+ name: string;
244
+ input: {
245
+ type: string;
246
+ properties: {
247
+ bars: {
248
+ type: string;
249
+ description: string;
250
+ };
251
+ k: {
252
+ type: string;
253
+ default: number;
254
+ };
255
+ tolPct: {
256
+ type: string;
257
+ default: number;
258
+ };
259
+ show: {
260
+ type: string;
261
+ default: number;
262
+ };
263
+ look?: undefined;
264
+ rowsWanted?: undefined;
265
+ sessionsShown?: undefined;
266
+ rows?: undefined;
267
+ rev?: undefined;
268
+ box?: undefined;
269
+ };
270
+ required: string[];
271
+ };
272
+ output: string;
273
+ } | {
274
+ name: string;
275
+ input: {
276
+ type: string;
277
+ properties: {
278
+ bars: {
279
+ type: string;
280
+ description: string;
281
+ };
282
+ k: {
283
+ type: string;
284
+ default: number;
285
+ };
286
+ look: {
287
+ type: string;
288
+ default: number;
289
+ };
290
+ show: {
291
+ type: string;
292
+ default: number;
293
+ };
294
+ tolPct?: undefined;
295
+ rowsWanted?: undefined;
296
+ sessionsShown?: undefined;
297
+ rows?: undefined;
298
+ rev?: undefined;
299
+ box?: undefined;
300
+ };
301
+ required: string[];
302
+ };
303
+ output: string;
304
+ } | {
305
+ name: string;
306
+ input: {
307
+ type: string;
308
+ properties: {
309
+ bars: {
310
+ type: string;
311
+ description: string;
312
+ };
313
+ rowsWanted: {
314
+ type: string;
315
+ default: number;
316
+ };
317
+ sessionsShown: {
318
+ type: string;
319
+ default: number;
320
+ };
321
+ k?: undefined;
322
+ tolPct?: undefined;
323
+ show?: undefined;
324
+ look?: undefined;
325
+ rows?: undefined;
326
+ rev?: undefined;
327
+ box?: undefined;
328
+ };
329
+ required: string[];
330
+ };
331
+ output: string;
332
+ } | {
333
+ name: string;
334
+ input: {
335
+ type: string;
336
+ properties: {
337
+ bars: {
338
+ type: string;
339
+ description: string;
340
+ };
341
+ rows: {
342
+ type: string;
343
+ default: number;
344
+ };
345
+ sessionsShown: {
346
+ type: string;
347
+ default: number;
348
+ };
349
+ k?: undefined;
350
+ tolPct?: undefined;
351
+ show?: undefined;
352
+ look?: undefined;
353
+ rowsWanted?: undefined;
354
+ rev?: undefined;
355
+ box?: undefined;
356
+ };
357
+ required: string[];
358
+ };
359
+ output: string;
360
+ } | {
361
+ name: string;
362
+ input: {
363
+ type: string;
364
+ properties: {
365
+ bars: {
366
+ type: string;
367
+ description: string;
368
+ };
369
+ rev: {
370
+ type: string;
371
+ default?: undefined;
372
+ };
373
+ k?: undefined;
374
+ tolPct?: undefined;
375
+ show?: undefined;
376
+ look?: undefined;
377
+ rowsWanted?: undefined;
378
+ sessionsShown?: undefined;
379
+ rows?: undefined;
380
+ box?: undefined;
381
+ };
382
+ required: string[];
383
+ };
384
+ output: string;
385
+ } | {
386
+ name: string;
387
+ input: {
388
+ type: string;
389
+ properties: {
390
+ bars: {
391
+ type: string;
392
+ description: string;
393
+ };
394
+ box: {
395
+ type: string;
396
+ };
397
+ rev: {
398
+ type: string;
399
+ default: number;
400
+ };
401
+ k?: undefined;
402
+ tolPct?: undefined;
403
+ show?: undefined;
404
+ look?: undefined;
405
+ rowsWanted?: undefined;
406
+ sessionsShown?: undefined;
407
+ rows?: undefined;
408
+ };
409
+ required: string[];
410
+ };
411
+ output: string;
412
+ })[];
413
+ };
414
+
415
+ export { type Bar, type HarmonicHit, type KagiLine, type Pivot, type PnfColumn, type Series, type StudyPath, type StudyProfile, type StudyZone, atr, chartPatterns, describe, elliott, harmonics, kagi, pointFigure, rma, sessionVolumeProfiles, swings, tpoProfiles, trueRange, volumeProfile };