react-klinecharts-ui 0.1.0 → 0.2.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/README.md +284 -24
- package/dist/chunk-47JXSAIT.cjs +2467 -0
- package/dist/chunk-47JXSAIT.cjs.map +1 -0
- package/dist/chunk-B3NZ66YA.js +2424 -0
- package/dist/chunk-B3NZ66YA.js.map +1 -0
- package/dist/extensions.cjs +8 -4
- package/dist/extensions.d.cts +5 -1
- package/dist/extensions.d.ts +5 -1
- package/dist/extensions.js +1 -1
- package/dist/index.cjs +1058 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +253 -3
- package/dist/index.d.ts +253 -3
- package/dist/index.js +949 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-PUULIBFN.js +0 -911
- package/dist/chunk-PUULIBFN.js.map +0 -1
- package/dist/chunk-SLTXNLKN.cjs +0 -932
- package/dist/chunk-SLTXNLKN.cjs.map +0 -1
|
@@ -0,0 +1,2467 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactKlinecharts = require('react-klinecharts');
|
|
4
|
+
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
// src/overlays/index.ts
|
|
12
|
+
var overlays_exports = {};
|
|
13
|
+
__export(overlays_exports, {
|
|
14
|
+
abcd: () => abcd_default,
|
|
15
|
+
anyWaves: () => anyWaves_default,
|
|
16
|
+
arrow: () => arrow_default,
|
|
17
|
+
brush: () => brush_default,
|
|
18
|
+
circle: () => circle_default,
|
|
19
|
+
eightWaves: () => eightWaves_default,
|
|
20
|
+
elliottWave: () => elliottWave_default,
|
|
21
|
+
fibRetracement: () => fibRetracement_default,
|
|
22
|
+
fibonacciCircle: () => fibonacciCircle_default,
|
|
23
|
+
fibonacciExtension: () => fibonacciExtension_default,
|
|
24
|
+
fibonacciSegment: () => fibonacciSegment_default,
|
|
25
|
+
fibonacciSpeedResistanceFan: () => fibonacciSpeedResistanceFan_default,
|
|
26
|
+
fibonacciSpiral: () => fibonacciSpiral_default,
|
|
27
|
+
fiveWaves: () => fiveWaves_default,
|
|
28
|
+
gannBox: () => gannBox_default,
|
|
29
|
+
gannFan: () => gannFan_default,
|
|
30
|
+
longPosition: () => longPosition_default,
|
|
31
|
+
measure: () => measure_default,
|
|
32
|
+
parallelChannel: () => parallelChannel_default,
|
|
33
|
+
parallelogram: () => parallelogram_default,
|
|
34
|
+
ray: () => ray_default,
|
|
35
|
+
rect: () => rect_default,
|
|
36
|
+
shortPosition: () => shortPosition_default,
|
|
37
|
+
threeWaves: () => threeWaves_default,
|
|
38
|
+
triangle: () => triangle_default,
|
|
39
|
+
xabcd: () => xabcd_default
|
|
40
|
+
});
|
|
41
|
+
function getRotateCoordinate(coordinate, targetCoordinate, angle) {
|
|
42
|
+
const x = (coordinate.x - targetCoordinate.x) * Math.cos(angle) - (coordinate.y - targetCoordinate.y) * Math.sin(angle) + targetCoordinate.x;
|
|
43
|
+
const y = (coordinate.x - targetCoordinate.x) * Math.sin(angle) + (coordinate.y - targetCoordinate.y) * Math.cos(angle) + targetCoordinate.y;
|
|
44
|
+
return { x, y };
|
|
45
|
+
}
|
|
46
|
+
function getRayLine(coordinates, bounding) {
|
|
47
|
+
if (coordinates.length > 1) {
|
|
48
|
+
let coordinate;
|
|
49
|
+
if (coordinates[0].x === coordinates[1].x && coordinates[0].y !== coordinates[1].y) {
|
|
50
|
+
if (coordinates[0].y < coordinates[1].y) {
|
|
51
|
+
coordinate = { x: coordinates[0].x, y: bounding.height };
|
|
52
|
+
} else {
|
|
53
|
+
coordinate = { x: coordinates[0].x, y: 0 };
|
|
54
|
+
}
|
|
55
|
+
} else if (coordinates[0].x > coordinates[1].x) {
|
|
56
|
+
coordinate = {
|
|
57
|
+
x: 0,
|
|
58
|
+
y: reactKlinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
|
|
59
|
+
x: 0,
|
|
60
|
+
y: coordinates[0].y
|
|
61
|
+
})
|
|
62
|
+
};
|
|
63
|
+
} else {
|
|
64
|
+
coordinate = {
|
|
65
|
+
x: bounding.width,
|
|
66
|
+
y: reactKlinecharts.utils.getLinearYFromCoordinates(coordinates[0], coordinates[1], {
|
|
67
|
+
x: bounding.width,
|
|
68
|
+
y: coordinates[0].y
|
|
69
|
+
})
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
return { coordinates: [coordinates[0], coordinate] };
|
|
73
|
+
}
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
function getDistance(coordinate1, coordinate2) {
|
|
77
|
+
const xDis = Math.abs(coordinate1.x - coordinate2.x);
|
|
78
|
+
const yDis = Math.abs(coordinate1.y - coordinate2.y);
|
|
79
|
+
return Math.sqrt(xDis * xDis + yDis * yDis);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// src/overlays/arrow.ts
|
|
83
|
+
var arrow = {
|
|
84
|
+
name: "arrow",
|
|
85
|
+
totalStep: 3,
|
|
86
|
+
needDefaultPointFigure: true,
|
|
87
|
+
needDefaultXAxisFigure: true,
|
|
88
|
+
needDefaultYAxisFigure: true,
|
|
89
|
+
createPointFigures: ({ coordinates }) => {
|
|
90
|
+
if (coordinates.length > 1) {
|
|
91
|
+
const flag = coordinates[1].x > coordinates[0].x ? 0 : 1;
|
|
92
|
+
const kb = reactKlinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
|
|
93
|
+
let offsetAngle;
|
|
94
|
+
if (kb) {
|
|
95
|
+
offsetAngle = Math.atan(kb[0]) + Math.PI * flag;
|
|
96
|
+
} else {
|
|
97
|
+
if (coordinates[1].y > coordinates[0].y) {
|
|
98
|
+
offsetAngle = Math.PI / 2;
|
|
99
|
+
} else {
|
|
100
|
+
offsetAngle = Math.PI / 2 * 3;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const rotateCoordinate1 = getRotateCoordinate(
|
|
104
|
+
{ x: coordinates[1].x - 8, y: coordinates[1].y + 4 },
|
|
105
|
+
coordinates[1],
|
|
106
|
+
offsetAngle
|
|
107
|
+
);
|
|
108
|
+
const rotateCoordinate2 = getRotateCoordinate(
|
|
109
|
+
{ x: coordinates[1].x - 8, y: coordinates[1].y - 4 },
|
|
110
|
+
coordinates[1],
|
|
111
|
+
offsetAngle
|
|
112
|
+
);
|
|
113
|
+
return [
|
|
114
|
+
{ type: "line", attrs: { coordinates } },
|
|
115
|
+
{
|
|
116
|
+
type: "line",
|
|
117
|
+
ignoreEvent: true,
|
|
118
|
+
attrs: {
|
|
119
|
+
coordinates: [rotateCoordinate1, coordinates[1], rotateCoordinate2]
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
return [];
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
var arrow_default = arrow;
|
|
128
|
+
|
|
129
|
+
// src/overlays/circle.ts
|
|
130
|
+
var circle = {
|
|
131
|
+
name: "circle",
|
|
132
|
+
totalStep: 3,
|
|
133
|
+
needDefaultPointFigure: true,
|
|
134
|
+
needDefaultXAxisFigure: true,
|
|
135
|
+
needDefaultYAxisFigure: true,
|
|
136
|
+
styles: { circle: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
137
|
+
createPointFigures: ({ coordinates }) => {
|
|
138
|
+
if (coordinates.length > 1) {
|
|
139
|
+
const radius = getDistance(coordinates[0], coordinates[1]);
|
|
140
|
+
return {
|
|
141
|
+
type: "circle",
|
|
142
|
+
attrs: { ...coordinates[0], r: radius },
|
|
143
|
+
styles: { style: "stroke_fill" }
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
var circle_default = circle;
|
|
150
|
+
|
|
151
|
+
// src/overlays/rect.ts
|
|
152
|
+
var rect = {
|
|
153
|
+
name: "rect",
|
|
154
|
+
totalStep: 3,
|
|
155
|
+
needDefaultPointFigure: true,
|
|
156
|
+
needDefaultXAxisFigure: true,
|
|
157
|
+
needDefaultYAxisFigure: true,
|
|
158
|
+
styles: { polygon: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
159
|
+
createPointFigures: ({ coordinates }) => {
|
|
160
|
+
if (coordinates.length > 1) {
|
|
161
|
+
return [
|
|
162
|
+
{
|
|
163
|
+
type: "polygon",
|
|
164
|
+
attrs: {
|
|
165
|
+
coordinates: [
|
|
166
|
+
coordinates[0],
|
|
167
|
+
{ x: coordinates[1].x, y: coordinates[0].y },
|
|
168
|
+
coordinates[1],
|
|
169
|
+
{ x: coordinates[0].x, y: coordinates[1].y }
|
|
170
|
+
]
|
|
171
|
+
},
|
|
172
|
+
styles: { style: "stroke_fill" }
|
|
173
|
+
}
|
|
174
|
+
];
|
|
175
|
+
}
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
var rect_default = rect;
|
|
180
|
+
|
|
181
|
+
// src/overlays/triangle.ts
|
|
182
|
+
var triangle = {
|
|
183
|
+
name: "triangle",
|
|
184
|
+
totalStep: 4,
|
|
185
|
+
needDefaultPointFigure: true,
|
|
186
|
+
needDefaultXAxisFigure: true,
|
|
187
|
+
needDefaultYAxisFigure: true,
|
|
188
|
+
styles: { polygon: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
189
|
+
createPointFigures: ({ coordinates }) => {
|
|
190
|
+
return [
|
|
191
|
+
{
|
|
192
|
+
type: "polygon",
|
|
193
|
+
attrs: { coordinates },
|
|
194
|
+
styles: { style: "stroke_fill" }
|
|
195
|
+
}
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
var triangle_default = triangle;
|
|
200
|
+
|
|
201
|
+
// src/overlays/parallelogram.ts
|
|
202
|
+
var parallelogram = {
|
|
203
|
+
name: "parallelogram",
|
|
204
|
+
totalStep: 4,
|
|
205
|
+
needDefaultPointFigure: true,
|
|
206
|
+
needDefaultXAxisFigure: true,
|
|
207
|
+
needDefaultYAxisFigure: true,
|
|
208
|
+
styles: { polygon: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
209
|
+
createPointFigures: ({ coordinates }) => {
|
|
210
|
+
if (coordinates.length === 2) {
|
|
211
|
+
return [{ type: "line", ignoreEvent: true, attrs: { coordinates } }];
|
|
212
|
+
}
|
|
213
|
+
if (coordinates.length === 3) {
|
|
214
|
+
const coordinate = {
|
|
215
|
+
x: coordinates[0].x + (coordinates[2].x - coordinates[1].x),
|
|
216
|
+
y: coordinates[2].y - coordinates[1].y + coordinates[0].y
|
|
217
|
+
};
|
|
218
|
+
return [
|
|
219
|
+
{
|
|
220
|
+
type: "polygon",
|
|
221
|
+
attrs: {
|
|
222
|
+
coordinates: [
|
|
223
|
+
coordinates[0],
|
|
224
|
+
coordinates[1],
|
|
225
|
+
coordinates[2],
|
|
226
|
+
coordinate
|
|
227
|
+
]
|
|
228
|
+
},
|
|
229
|
+
styles: { style: "stroke_fill" }
|
|
230
|
+
}
|
|
231
|
+
];
|
|
232
|
+
}
|
|
233
|
+
return [];
|
|
234
|
+
},
|
|
235
|
+
performEventPressedMove: ({ points, performPointIndex, performPoint }) => {
|
|
236
|
+
if (performPointIndex < 2) {
|
|
237
|
+
if (points[0]) points[0].price = performPoint.price;
|
|
238
|
+
if (points[1]) points[1].price = performPoint.price;
|
|
239
|
+
}
|
|
240
|
+
},
|
|
241
|
+
performEventMoveForDrawing: ({ currentStep, points, performPoint }) => {
|
|
242
|
+
if (currentStep === 2) {
|
|
243
|
+
if (points[0]) points[0].price = performPoint.price;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
var parallelogram_default = parallelogram;
|
|
248
|
+
|
|
249
|
+
// src/overlays/fibonacciCircle.ts
|
|
250
|
+
var fibonacciCircle = {
|
|
251
|
+
name: "fibonacciCircle",
|
|
252
|
+
totalStep: 3,
|
|
253
|
+
needDefaultPointFigure: true,
|
|
254
|
+
needDefaultXAxisFigure: true,
|
|
255
|
+
needDefaultYAxisFigure: true,
|
|
256
|
+
createPointFigures: ({ coordinates }) => {
|
|
257
|
+
if (coordinates.length > 1) {
|
|
258
|
+
const xDis = Math.abs(coordinates[0].x - coordinates[1].x);
|
|
259
|
+
const yDis = Math.abs(coordinates[0].y - coordinates[1].y);
|
|
260
|
+
const radius = Math.sqrt(xDis * xDis + yDis * yDis);
|
|
261
|
+
const percents = [0.236, 0.382, 0.5, 0.618, 0.786, 1];
|
|
262
|
+
const circles = [];
|
|
263
|
+
const texts = [];
|
|
264
|
+
percents.forEach((percent) => {
|
|
265
|
+
const r = radius * percent;
|
|
266
|
+
circles.push({ ...coordinates[0], r });
|
|
267
|
+
texts.push({
|
|
268
|
+
x: coordinates[0].x,
|
|
269
|
+
y: coordinates[0].y + r + 6,
|
|
270
|
+
text: `${(percent * 100).toFixed(1)}%`
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
return [
|
|
274
|
+
{ type: "circle", attrs: circles, styles: { style: "stroke" } },
|
|
275
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
276
|
+
];
|
|
277
|
+
}
|
|
278
|
+
return [];
|
|
279
|
+
}
|
|
280
|
+
};
|
|
281
|
+
var fibonacciCircle_default = fibonacciCircle;
|
|
282
|
+
|
|
283
|
+
// src/overlays/fibonacciSegment.ts
|
|
284
|
+
var fibonacciSegment = {
|
|
285
|
+
name: "fibonacciSegment",
|
|
286
|
+
totalStep: 3,
|
|
287
|
+
needDefaultPointFigure: true,
|
|
288
|
+
needDefaultXAxisFigure: true,
|
|
289
|
+
needDefaultYAxisFigure: true,
|
|
290
|
+
createPointFigures: ({ coordinates, overlay, chart }) => {
|
|
291
|
+
const precision = chart.getSymbol()?.pricePrecision ?? 2;
|
|
292
|
+
const lines = [];
|
|
293
|
+
const texts = [];
|
|
294
|
+
if (coordinates.length > 1) {
|
|
295
|
+
const textX = coordinates[1].x > coordinates[0].x ? coordinates[0].x : coordinates[1].x;
|
|
296
|
+
const percents = [1, 0.786, 0.618, 0.5, 0.382, 0.236, 0];
|
|
297
|
+
const yDif = coordinates[0].y - coordinates[1].y;
|
|
298
|
+
const points = overlay.points;
|
|
299
|
+
const valueDif = points[0].value - points[1].value;
|
|
300
|
+
percents.forEach((percent) => {
|
|
301
|
+
const y = coordinates[1].y + yDif * percent;
|
|
302
|
+
const price = (points[1].value + valueDif * percent).toFixed(precision);
|
|
303
|
+
lines.push({
|
|
304
|
+
coordinates: [
|
|
305
|
+
{ x: coordinates[0].x, y },
|
|
306
|
+
{ x: coordinates[1].x, y }
|
|
307
|
+
]
|
|
308
|
+
});
|
|
309
|
+
texts.push({
|
|
310
|
+
x: textX,
|
|
311
|
+
y,
|
|
312
|
+
text: `${price} (${(percent * 100).toFixed(1)}%)`,
|
|
313
|
+
baseline: "bottom"
|
|
314
|
+
});
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return [
|
|
318
|
+
{ type: "line", attrs: lines },
|
|
319
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
320
|
+
];
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
var fibonacciSegment_default = fibonacciSegment;
|
|
324
|
+
var fibonacciSpiral = {
|
|
325
|
+
name: "fibonacciSpiral",
|
|
326
|
+
totalStep: 3,
|
|
327
|
+
needDefaultPointFigure: true,
|
|
328
|
+
needDefaultXAxisFigure: true,
|
|
329
|
+
needDefaultYAxisFigure: true,
|
|
330
|
+
createPointFigures: ({ coordinates, bounding }) => {
|
|
331
|
+
if (coordinates.length > 1) {
|
|
332
|
+
const startRadius = getDistance(coordinates[0], coordinates[1]) / Math.sqrt(24);
|
|
333
|
+
const flag = coordinates[1].x > coordinates[0].x ? 0 : 1;
|
|
334
|
+
const kb = reactKlinecharts.utils.getLinearSlopeIntercept(coordinates[0], coordinates[1]);
|
|
335
|
+
let offsetAngle;
|
|
336
|
+
if (kb) {
|
|
337
|
+
offsetAngle = Math.atan(kb[0]) + Math.PI * flag;
|
|
338
|
+
} else {
|
|
339
|
+
if (coordinates[1].y > coordinates[0].y) {
|
|
340
|
+
offsetAngle = Math.PI / 2;
|
|
341
|
+
} else {
|
|
342
|
+
offsetAngle = Math.PI / 2 * 3;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
const rotateCoordinate1 = getRotateCoordinate(
|
|
346
|
+
{ x: coordinates[0].x - startRadius, y: coordinates[0].y },
|
|
347
|
+
coordinates[0],
|
|
348
|
+
offsetAngle
|
|
349
|
+
);
|
|
350
|
+
const rotateCoordinate2 = getRotateCoordinate(
|
|
351
|
+
{
|
|
352
|
+
x: coordinates[0].x - startRadius,
|
|
353
|
+
y: coordinates[0].y - startRadius
|
|
354
|
+
},
|
|
355
|
+
coordinates[0],
|
|
356
|
+
offsetAngle
|
|
357
|
+
);
|
|
358
|
+
const arcs = [
|
|
359
|
+
{
|
|
360
|
+
...rotateCoordinate1,
|
|
361
|
+
r: startRadius,
|
|
362
|
+
startAngle: offsetAngle,
|
|
363
|
+
endAngle: offsetAngle + Math.PI / 2
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
...rotateCoordinate2,
|
|
367
|
+
r: startRadius * 2,
|
|
368
|
+
startAngle: offsetAngle + Math.PI / 2,
|
|
369
|
+
endAngle: offsetAngle + Math.PI
|
|
370
|
+
}
|
|
371
|
+
];
|
|
372
|
+
let x = coordinates[0].x - startRadius;
|
|
373
|
+
let y = coordinates[0].y - startRadius;
|
|
374
|
+
for (let i = 2; i < 9; i++) {
|
|
375
|
+
const r = arcs[i - 2].r + arcs[i - 1].r;
|
|
376
|
+
let startAngle = 0;
|
|
377
|
+
switch (i % 4) {
|
|
378
|
+
case 0:
|
|
379
|
+
startAngle = offsetAngle;
|
|
380
|
+
x -= arcs[i - 2].r;
|
|
381
|
+
break;
|
|
382
|
+
case 1:
|
|
383
|
+
startAngle = offsetAngle + Math.PI / 2;
|
|
384
|
+
y -= arcs[i - 2].r;
|
|
385
|
+
break;
|
|
386
|
+
case 2:
|
|
387
|
+
startAngle = offsetAngle + Math.PI;
|
|
388
|
+
x += arcs[i - 2].r;
|
|
389
|
+
break;
|
|
390
|
+
case 3:
|
|
391
|
+
startAngle = offsetAngle + Math.PI / 2 * 3;
|
|
392
|
+
y += arcs[i - 2].r;
|
|
393
|
+
break;
|
|
394
|
+
}
|
|
395
|
+
const endAngle = startAngle + Math.PI / 2;
|
|
396
|
+
const rotateCoordinate = getRotateCoordinate(
|
|
397
|
+
{ x, y },
|
|
398
|
+
coordinates[0],
|
|
399
|
+
offsetAngle
|
|
400
|
+
);
|
|
401
|
+
arcs.push({ ...rotateCoordinate, r, startAngle, endAngle });
|
|
402
|
+
}
|
|
403
|
+
return [
|
|
404
|
+
{ type: "arc", attrs: arcs },
|
|
405
|
+
{ type: "line", attrs: getRayLine(coordinates, bounding) }
|
|
406
|
+
];
|
|
407
|
+
}
|
|
408
|
+
return [];
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
var fibonacciSpiral_default = fibonacciSpiral;
|
|
412
|
+
|
|
413
|
+
// src/overlays/fibonacciSpeedResistanceFan.ts
|
|
414
|
+
var fibonacciSpeedResistanceFan = {
|
|
415
|
+
name: "fibonacciSpeedResistanceFan",
|
|
416
|
+
totalStep: 3,
|
|
417
|
+
needDefaultPointFigure: true,
|
|
418
|
+
needDefaultXAxisFigure: true,
|
|
419
|
+
needDefaultYAxisFigure: true,
|
|
420
|
+
createPointFigures: ({ coordinates, bounding }) => {
|
|
421
|
+
const lines1 = [];
|
|
422
|
+
let lines2 = [];
|
|
423
|
+
const texts = [];
|
|
424
|
+
if (coordinates.length > 1) {
|
|
425
|
+
const xOffset = coordinates[1].x > coordinates[0].x ? -38 : 4;
|
|
426
|
+
const yOffset = coordinates[1].y > coordinates[0].y ? -2 : 20;
|
|
427
|
+
const xDistance = coordinates[1].x - coordinates[0].x;
|
|
428
|
+
const yDistance = coordinates[1].y - coordinates[0].y;
|
|
429
|
+
const percents = [1, 0.75, 0.618, 0.5, 0.382, 0.25, 0];
|
|
430
|
+
percents.forEach((percent) => {
|
|
431
|
+
const x = coordinates[1].x - xDistance * percent;
|
|
432
|
+
const y = coordinates[1].y - yDistance * percent;
|
|
433
|
+
lines1.push({
|
|
434
|
+
coordinates: [
|
|
435
|
+
{ x, y: coordinates[0].y },
|
|
436
|
+
{ x, y: coordinates[1].y }
|
|
437
|
+
]
|
|
438
|
+
});
|
|
439
|
+
lines1.push({
|
|
440
|
+
coordinates: [
|
|
441
|
+
{ x: coordinates[0].x, y },
|
|
442
|
+
{ x: coordinates[1].x, y }
|
|
443
|
+
]
|
|
444
|
+
});
|
|
445
|
+
lines2 = lines2.concat(
|
|
446
|
+
getRayLine(
|
|
447
|
+
[coordinates[0], { x, y: coordinates[1].y }],
|
|
448
|
+
bounding
|
|
449
|
+
)
|
|
450
|
+
);
|
|
451
|
+
lines2 = lines2.concat(
|
|
452
|
+
getRayLine(
|
|
453
|
+
[coordinates[0], { x: coordinates[1].x, y }],
|
|
454
|
+
bounding
|
|
455
|
+
)
|
|
456
|
+
);
|
|
457
|
+
texts.unshift({
|
|
458
|
+
x: coordinates[0].x + xOffset,
|
|
459
|
+
y: y + 10,
|
|
460
|
+
text: `${percent.toFixed(3)}`
|
|
461
|
+
});
|
|
462
|
+
texts.unshift({
|
|
463
|
+
x: x - 18,
|
|
464
|
+
y: coordinates[0].y + yOffset,
|
|
465
|
+
text: `${percent.toFixed(3)}`
|
|
466
|
+
});
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
return [
|
|
470
|
+
{ type: "line", attrs: lines1 },
|
|
471
|
+
{ type: "line", attrs: lines2 },
|
|
472
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
473
|
+
];
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
var fibonacciSpeedResistanceFan_default = fibonacciSpeedResistanceFan;
|
|
477
|
+
|
|
478
|
+
// src/overlays/fibonacciExtension.ts
|
|
479
|
+
var fibonacciExtension = {
|
|
480
|
+
name: "fibonacciExtension",
|
|
481
|
+
totalStep: 4,
|
|
482
|
+
needDefaultPointFigure: true,
|
|
483
|
+
needDefaultXAxisFigure: true,
|
|
484
|
+
needDefaultYAxisFigure: true,
|
|
485
|
+
createPointFigures: ({ coordinates, overlay, chart }) => {
|
|
486
|
+
const precision = chart.getSymbol()?.pricePrecision ?? 2;
|
|
487
|
+
const fbLines = [];
|
|
488
|
+
const texts = [];
|
|
489
|
+
if (coordinates.length > 2) {
|
|
490
|
+
const points = overlay.points;
|
|
491
|
+
const valueDif = points[1].value - points[0].value;
|
|
492
|
+
const yDif = coordinates[1].y - coordinates[0].y;
|
|
493
|
+
const percents = [0, 0.236, 0.382, 0.5, 0.618, 0.786, 1];
|
|
494
|
+
const textX = coordinates[2].x > coordinates[1].x ? coordinates[1].x : coordinates[2].x;
|
|
495
|
+
percents.forEach((percent) => {
|
|
496
|
+
const y = coordinates[2].y + yDif * percent;
|
|
497
|
+
const price = (points[2].value + valueDif * percent).toFixed(precision);
|
|
498
|
+
fbLines.push({
|
|
499
|
+
coordinates: [
|
|
500
|
+
{ x: coordinates[1].x, y },
|
|
501
|
+
{ x: coordinates[2].x, y }
|
|
502
|
+
]
|
|
503
|
+
});
|
|
504
|
+
texts.push({
|
|
505
|
+
x: textX,
|
|
506
|
+
y,
|
|
507
|
+
text: `${price} (${(percent * 100).toFixed(1)}%)`,
|
|
508
|
+
baseline: "bottom"
|
|
509
|
+
});
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
return [
|
|
513
|
+
{
|
|
514
|
+
type: "line",
|
|
515
|
+
attrs: { coordinates },
|
|
516
|
+
styles: { style: "dashed" }
|
|
517
|
+
},
|
|
518
|
+
{ type: "line", attrs: fbLines },
|
|
519
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
520
|
+
];
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
var fibonacciExtension_default = fibonacciExtension;
|
|
524
|
+
|
|
525
|
+
// src/overlays/fibRetracement.ts
|
|
526
|
+
var fibRetracement = {
|
|
527
|
+
name: "fibRetracement",
|
|
528
|
+
totalStep: 3,
|
|
529
|
+
needDefaultPointFigure: true,
|
|
530
|
+
needDefaultXAxisFigure: true,
|
|
531
|
+
needDefaultYAxisFigure: true,
|
|
532
|
+
createPointFigures: ({ coordinates, bounding }) => {
|
|
533
|
+
if (coordinates.length > 1) {
|
|
534
|
+
const lines = [];
|
|
535
|
+
const texts = [];
|
|
536
|
+
const x1 = coordinates[0].x;
|
|
537
|
+
const x2 = bounding.width;
|
|
538
|
+
const y1 = coordinates[0].y;
|
|
539
|
+
const y2 = coordinates[1].y;
|
|
540
|
+
const diff = y2 - y1;
|
|
541
|
+
const levels = [
|
|
542
|
+
{ level: 0, text: "0 (0.00%)" },
|
|
543
|
+
{ level: 0.236, text: "0.236 (23.6%)" },
|
|
544
|
+
{ level: 0.382, text: "0.382 (38.2%)" },
|
|
545
|
+
{ level: 0.5, text: "0.5 (50.0%)" },
|
|
546
|
+
{ level: 0.618, text: "0.618 (61.8%)" },
|
|
547
|
+
{ level: 0.786, text: "0.786 (78.6%)" },
|
|
548
|
+
{ level: 1, text: "1 (100.0%)" }
|
|
549
|
+
];
|
|
550
|
+
levels.forEach((l) => {
|
|
551
|
+
const y = y1 + diff * l.level;
|
|
552
|
+
lines.push({ coordinates: [{ x: x1, y }, { x: x2, y }] });
|
|
553
|
+
texts.push({
|
|
554
|
+
x: x1,
|
|
555
|
+
y,
|
|
556
|
+
text: l.text,
|
|
557
|
+
align: "left",
|
|
558
|
+
baseline: "bottom"
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
return [
|
|
562
|
+
{ type: "line", attrs: lines },
|
|
563
|
+
{ type: "text", attrs: texts }
|
|
564
|
+
];
|
|
565
|
+
}
|
|
566
|
+
return [];
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
var fibRetracement_default = fibRetracement;
|
|
570
|
+
|
|
571
|
+
// src/overlays/gannBox.ts
|
|
572
|
+
var gannBox = {
|
|
573
|
+
name: "gannBox",
|
|
574
|
+
totalStep: 3,
|
|
575
|
+
needDefaultPointFigure: true,
|
|
576
|
+
needDefaultXAxisFigure: true,
|
|
577
|
+
needDefaultYAxisFigure: true,
|
|
578
|
+
styles: { polygon: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
579
|
+
createPointFigures: ({ coordinates }) => {
|
|
580
|
+
if (coordinates.length > 1) {
|
|
581
|
+
const quarterYDis = (coordinates[1].y - coordinates[0].y) / 4;
|
|
582
|
+
const xDis = coordinates[1].x - coordinates[0].x;
|
|
583
|
+
const dashedLines = [
|
|
584
|
+
{
|
|
585
|
+
coordinates: [
|
|
586
|
+
coordinates[0],
|
|
587
|
+
{ x: coordinates[1].x, y: coordinates[1].y - quarterYDis }
|
|
588
|
+
]
|
|
589
|
+
},
|
|
590
|
+
{
|
|
591
|
+
coordinates: [
|
|
592
|
+
coordinates[0],
|
|
593
|
+
{ x: coordinates[1].x, y: coordinates[1].y - quarterYDis * 2 }
|
|
594
|
+
]
|
|
595
|
+
},
|
|
596
|
+
{
|
|
597
|
+
coordinates: [
|
|
598
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
599
|
+
{ x: coordinates[1].x, y: coordinates[0].y + quarterYDis }
|
|
600
|
+
]
|
|
601
|
+
},
|
|
602
|
+
{
|
|
603
|
+
coordinates: [
|
|
604
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
605
|
+
{ x: coordinates[1].x, y: coordinates[0].y + quarterYDis * 2 }
|
|
606
|
+
]
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
coordinates: [
|
|
610
|
+
{ ...coordinates[0] },
|
|
611
|
+
{ x: coordinates[0].x + xDis * 0.236, y: coordinates[1].y }
|
|
612
|
+
]
|
|
613
|
+
},
|
|
614
|
+
{
|
|
615
|
+
coordinates: [
|
|
616
|
+
{ ...coordinates[0] },
|
|
617
|
+
{ x: coordinates[0].x + xDis * 0.5, y: coordinates[1].y }
|
|
618
|
+
]
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
coordinates: [
|
|
622
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
623
|
+
{ x: coordinates[0].x + xDis * 0.236, y: coordinates[0].y }
|
|
624
|
+
]
|
|
625
|
+
},
|
|
626
|
+
{
|
|
627
|
+
coordinates: [
|
|
628
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
629
|
+
{ x: coordinates[0].x + xDis * 0.5, y: coordinates[0].y }
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
];
|
|
633
|
+
const solidLines = [
|
|
634
|
+
{ coordinates: [coordinates[0], coordinates[1]] },
|
|
635
|
+
{
|
|
636
|
+
coordinates: [
|
|
637
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
638
|
+
{ x: coordinates[1].x, y: coordinates[0].y }
|
|
639
|
+
]
|
|
640
|
+
}
|
|
641
|
+
];
|
|
642
|
+
return [
|
|
643
|
+
{
|
|
644
|
+
type: "line",
|
|
645
|
+
attrs: [
|
|
646
|
+
{
|
|
647
|
+
coordinates: [
|
|
648
|
+
coordinates[0],
|
|
649
|
+
{ x: coordinates[1].x, y: coordinates[0].y }
|
|
650
|
+
]
|
|
651
|
+
},
|
|
652
|
+
{
|
|
653
|
+
coordinates: [
|
|
654
|
+
{ x: coordinates[1].x, y: coordinates[0].y },
|
|
655
|
+
coordinates[1]
|
|
656
|
+
]
|
|
657
|
+
},
|
|
658
|
+
{
|
|
659
|
+
coordinates: [
|
|
660
|
+
coordinates[1],
|
|
661
|
+
{ x: coordinates[0].x, y: coordinates[1].y }
|
|
662
|
+
]
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
coordinates: [
|
|
666
|
+
{ x: coordinates[0].x, y: coordinates[1].y },
|
|
667
|
+
coordinates[0]
|
|
668
|
+
]
|
|
669
|
+
}
|
|
670
|
+
]
|
|
671
|
+
},
|
|
672
|
+
{
|
|
673
|
+
type: "polygon",
|
|
674
|
+
ignoreEvent: true,
|
|
675
|
+
attrs: {
|
|
676
|
+
coordinates: [
|
|
677
|
+
coordinates[0],
|
|
678
|
+
{ x: coordinates[1].x, y: coordinates[0].y },
|
|
679
|
+
coordinates[1],
|
|
680
|
+
{ x: coordinates[0].x, y: coordinates[1].y }
|
|
681
|
+
]
|
|
682
|
+
},
|
|
683
|
+
styles: { style: "fill" }
|
|
684
|
+
},
|
|
685
|
+
{ type: "line", attrs: dashedLines, styles: { style: "dashed" } },
|
|
686
|
+
{ type: "line", attrs: solidLines }
|
|
687
|
+
];
|
|
688
|
+
}
|
|
689
|
+
return [];
|
|
690
|
+
}
|
|
691
|
+
};
|
|
692
|
+
var gannBox_default = gannBox;
|
|
693
|
+
|
|
694
|
+
// src/overlays/gannFan.ts
|
|
695
|
+
var gannFan = {
|
|
696
|
+
name: "gannFan",
|
|
697
|
+
totalStep: 2,
|
|
698
|
+
needDefaultPointFigure: true,
|
|
699
|
+
needDefaultXAxisFigure: true,
|
|
700
|
+
needDefaultYAxisFigure: true,
|
|
701
|
+
createPointFigures: ({ coordinates, bounding }) => {
|
|
702
|
+
if (coordinates.length > 0) {
|
|
703
|
+
const p1 = coordinates[0];
|
|
704
|
+
const p2 = coordinates[1] || p1;
|
|
705
|
+
const lines = [];
|
|
706
|
+
const dx = p2.x - p1.x;
|
|
707
|
+
const dy = p2.y - p1.y;
|
|
708
|
+
const ratios = [8, 4, 3, 2, 1, 0.5, 0.333, 0.25, 0.125];
|
|
709
|
+
ratios.forEach((ratio) => {
|
|
710
|
+
const targetX = bounding.width;
|
|
711
|
+
const targetY = p1.y + dy * (ratio * ((targetX - p1.x) / (dx || 1)));
|
|
712
|
+
lines.push({ coordinates: [p1, { x: targetX, y: targetY }] });
|
|
713
|
+
});
|
|
714
|
+
return [{ type: "line", attrs: lines }];
|
|
715
|
+
}
|
|
716
|
+
return [];
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
var gannFan_default = gannFan;
|
|
720
|
+
|
|
721
|
+
// src/overlays/threeWaves.ts
|
|
722
|
+
var threeWaves = {
|
|
723
|
+
name: "threeWaves",
|
|
724
|
+
totalStep: 5,
|
|
725
|
+
needDefaultPointFigure: true,
|
|
726
|
+
needDefaultXAxisFigure: true,
|
|
727
|
+
needDefaultYAxisFigure: true,
|
|
728
|
+
createPointFigures: ({ coordinates }) => {
|
|
729
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
730
|
+
...coordinate,
|
|
731
|
+
text: `(${i})`,
|
|
732
|
+
baseline: "bottom"
|
|
733
|
+
}));
|
|
734
|
+
return [
|
|
735
|
+
{ type: "line", attrs: { coordinates } },
|
|
736
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
737
|
+
];
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
var threeWaves_default = threeWaves;
|
|
741
|
+
|
|
742
|
+
// src/overlays/fiveWaves.ts
|
|
743
|
+
var fiveWaves = {
|
|
744
|
+
name: "fiveWaves",
|
|
745
|
+
totalStep: 7,
|
|
746
|
+
needDefaultPointFigure: true,
|
|
747
|
+
needDefaultXAxisFigure: true,
|
|
748
|
+
needDefaultYAxisFigure: true,
|
|
749
|
+
createPointFigures: ({ coordinates }) => {
|
|
750
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
751
|
+
...coordinate,
|
|
752
|
+
text: `(${i})`,
|
|
753
|
+
baseline: "bottom"
|
|
754
|
+
}));
|
|
755
|
+
return [
|
|
756
|
+
{ type: "line", attrs: { coordinates } },
|
|
757
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
758
|
+
];
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
var fiveWaves_default = fiveWaves;
|
|
762
|
+
|
|
763
|
+
// src/overlays/eightWaves.ts
|
|
764
|
+
var eightWaves = {
|
|
765
|
+
name: "eightWaves",
|
|
766
|
+
totalStep: 10,
|
|
767
|
+
needDefaultPointFigure: true,
|
|
768
|
+
needDefaultXAxisFigure: true,
|
|
769
|
+
needDefaultYAxisFigure: true,
|
|
770
|
+
createPointFigures: ({ coordinates }) => {
|
|
771
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
772
|
+
...coordinate,
|
|
773
|
+
text: `(${i})`,
|
|
774
|
+
baseline: "bottom"
|
|
775
|
+
}));
|
|
776
|
+
return [
|
|
777
|
+
{ type: "line", attrs: { coordinates } },
|
|
778
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
779
|
+
];
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
var eightWaves_default = eightWaves;
|
|
783
|
+
|
|
784
|
+
// src/overlays/anyWaves.ts
|
|
785
|
+
var anyWaves = {
|
|
786
|
+
name: "anyWaves",
|
|
787
|
+
totalStep: Number.MAX_SAFE_INTEGER,
|
|
788
|
+
needDefaultPointFigure: true,
|
|
789
|
+
needDefaultXAxisFigure: true,
|
|
790
|
+
needDefaultYAxisFigure: true,
|
|
791
|
+
createPointFigures: ({ coordinates }) => {
|
|
792
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
793
|
+
...coordinate,
|
|
794
|
+
text: `(${i})`,
|
|
795
|
+
baseline: "bottom"
|
|
796
|
+
}));
|
|
797
|
+
return [
|
|
798
|
+
{ type: "line", attrs: { coordinates } },
|
|
799
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
800
|
+
];
|
|
801
|
+
}
|
|
802
|
+
};
|
|
803
|
+
var anyWaves_default = anyWaves;
|
|
804
|
+
|
|
805
|
+
// src/overlays/elliottWave.ts
|
|
806
|
+
var elliottWave = {
|
|
807
|
+
name: "elliottWave",
|
|
808
|
+
totalStep: 6,
|
|
809
|
+
needDefaultPointFigure: true,
|
|
810
|
+
needDefaultXAxisFigure: true,
|
|
811
|
+
needDefaultYAxisFigure: true,
|
|
812
|
+
createPointFigures: ({ coordinates }) => {
|
|
813
|
+
if (coordinates.length > 1) {
|
|
814
|
+
const lines = [];
|
|
815
|
+
const texts = [];
|
|
816
|
+
for (let i = 0; i < coordinates.length - 1; i++) {
|
|
817
|
+
lines.push({
|
|
818
|
+
coordinates: [coordinates[i], coordinates[i + 1]]
|
|
819
|
+
});
|
|
820
|
+
texts.push({
|
|
821
|
+
...coordinates[i],
|
|
822
|
+
text: `(${i})`,
|
|
823
|
+
align: "center",
|
|
824
|
+
baseline: "bottom"
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
if (coordinates.length === 6) {
|
|
828
|
+
texts.push({
|
|
829
|
+
...coordinates[5],
|
|
830
|
+
text: "(5)",
|
|
831
|
+
align: "center",
|
|
832
|
+
baseline: "bottom"
|
|
833
|
+
});
|
|
834
|
+
}
|
|
835
|
+
return [
|
|
836
|
+
{ type: "line", attrs: lines },
|
|
837
|
+
{ type: "text", attrs: texts }
|
|
838
|
+
];
|
|
839
|
+
}
|
|
840
|
+
return [];
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
var elliottWave_default = elliottWave;
|
|
844
|
+
|
|
845
|
+
// src/overlays/abcd.ts
|
|
846
|
+
var abcd = {
|
|
847
|
+
name: "abcd",
|
|
848
|
+
totalStep: 5,
|
|
849
|
+
needDefaultPointFigure: true,
|
|
850
|
+
needDefaultXAxisFigure: true,
|
|
851
|
+
needDefaultYAxisFigure: true,
|
|
852
|
+
createPointFigures: ({ coordinates }) => {
|
|
853
|
+
let acLineCoordinates = [];
|
|
854
|
+
let bdLineCoordinates = [];
|
|
855
|
+
const tags = ["A", "B", "C", "D"];
|
|
856
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
857
|
+
...coordinate,
|
|
858
|
+
baseline: "bottom",
|
|
859
|
+
text: `(${tags[i]})`
|
|
860
|
+
}));
|
|
861
|
+
if (coordinates.length > 2) {
|
|
862
|
+
acLineCoordinates = [coordinates[0], coordinates[2]];
|
|
863
|
+
if (coordinates.length > 3) {
|
|
864
|
+
bdLineCoordinates = [coordinates[1], coordinates[3]];
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
return [
|
|
868
|
+
{ type: "line", attrs: { coordinates } },
|
|
869
|
+
{
|
|
870
|
+
type: "line",
|
|
871
|
+
attrs: [
|
|
872
|
+
{ coordinates: acLineCoordinates },
|
|
873
|
+
{ coordinates: bdLineCoordinates }
|
|
874
|
+
],
|
|
875
|
+
styles: { style: "dashed" }
|
|
876
|
+
},
|
|
877
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
878
|
+
];
|
|
879
|
+
}
|
|
880
|
+
};
|
|
881
|
+
var abcd_default = abcd;
|
|
882
|
+
|
|
883
|
+
// src/overlays/xabcd.ts
|
|
884
|
+
var xabcd = {
|
|
885
|
+
name: "xabcd",
|
|
886
|
+
totalStep: 6,
|
|
887
|
+
needDefaultPointFigure: true,
|
|
888
|
+
needDefaultXAxisFigure: true,
|
|
889
|
+
needDefaultYAxisFigure: true,
|
|
890
|
+
styles: { polygon: { color: "rgba(22, 119, 255, 0.15)" } },
|
|
891
|
+
createPointFigures: ({ coordinates }) => {
|
|
892
|
+
const dashedLines = [];
|
|
893
|
+
const polygons = [];
|
|
894
|
+
const tags = ["X", "A", "B", "C", "D"];
|
|
895
|
+
const texts = coordinates.map((coordinate, i) => ({
|
|
896
|
+
...coordinate,
|
|
897
|
+
baseline: "bottom",
|
|
898
|
+
text: `(${tags[i]})`
|
|
899
|
+
}));
|
|
900
|
+
if (coordinates.length > 2) {
|
|
901
|
+
dashedLines.push({ coordinates: [coordinates[0], coordinates[2]] });
|
|
902
|
+
polygons.push({
|
|
903
|
+
coordinates: [coordinates[0], coordinates[1], coordinates[2]]
|
|
904
|
+
});
|
|
905
|
+
if (coordinates.length > 3) {
|
|
906
|
+
dashedLines.push({ coordinates: [coordinates[1], coordinates[3]] });
|
|
907
|
+
if (coordinates.length > 4) {
|
|
908
|
+
dashedLines.push({ coordinates: [coordinates[2], coordinates[4]] });
|
|
909
|
+
polygons.push({
|
|
910
|
+
coordinates: [coordinates[2], coordinates[3], coordinates[4]]
|
|
911
|
+
});
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
return [
|
|
916
|
+
{ type: "line", attrs: { coordinates } },
|
|
917
|
+
{ type: "line", attrs: dashedLines, styles: { style: "dashed" } },
|
|
918
|
+
{ type: "polygon", ignoreEvent: true, attrs: polygons },
|
|
919
|
+
{ type: "text", ignoreEvent: true, attrs: texts }
|
|
920
|
+
];
|
|
921
|
+
}
|
|
922
|
+
};
|
|
923
|
+
var xabcd_default = xabcd;
|
|
924
|
+
|
|
925
|
+
// src/overlays/ray.ts
|
|
926
|
+
var ray = {
|
|
927
|
+
name: "ray",
|
|
928
|
+
totalStep: 3,
|
|
929
|
+
needDefaultPointFigure: true,
|
|
930
|
+
needDefaultXAxisFigure: true,
|
|
931
|
+
needDefaultYAxisFigure: true,
|
|
932
|
+
createPointFigures: ({ coordinates, bounding }) => {
|
|
933
|
+
if (coordinates.length > 1) {
|
|
934
|
+
let coordinate = { x: 0, y: 0 };
|
|
935
|
+
if (coordinates[0].x === coordinates[1].x && coordinates[0].y !== coordinates[1].y) {
|
|
936
|
+
if (coordinates[0].y < coordinates[1].y) {
|
|
937
|
+
coordinate = { x: coordinates[0].x, y: bounding.height };
|
|
938
|
+
} else {
|
|
939
|
+
coordinate = { x: coordinates[0].x, y: 0 };
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
const x = coordinates[0].x < coordinates[1].x ? bounding.width : 0;
|
|
943
|
+
const y = (coordinates[1].y - coordinates[0].y) / (coordinates[1].x - coordinates[0].x) * (x - coordinates[0].x) + coordinates[0].y;
|
|
944
|
+
coordinate = { x, y };
|
|
945
|
+
}
|
|
946
|
+
return [
|
|
947
|
+
{
|
|
948
|
+
type: "line",
|
|
949
|
+
attrs: { coordinates: [coordinates[0], coordinate] }
|
|
950
|
+
}
|
|
951
|
+
];
|
|
952
|
+
}
|
|
953
|
+
return [];
|
|
954
|
+
}
|
|
955
|
+
};
|
|
956
|
+
var ray_default = ray;
|
|
957
|
+
|
|
958
|
+
// src/overlays/parallelChannel.ts
|
|
959
|
+
var parallelChannel = {
|
|
960
|
+
name: "parallelChannel",
|
|
961
|
+
totalStep: 4,
|
|
962
|
+
needDefaultPointFigure: true,
|
|
963
|
+
needDefaultXAxisFigure: true,
|
|
964
|
+
needDefaultYAxisFigure: true,
|
|
965
|
+
createPointFigures: ({ coordinates }) => {
|
|
966
|
+
if (coordinates.length > 1) {
|
|
967
|
+
const p1 = coordinates[0];
|
|
968
|
+
const p2 = coordinates[1];
|
|
969
|
+
const p3 = coordinates[2] || p2;
|
|
970
|
+
const dx = p1.x - p2.x;
|
|
971
|
+
const dy = p1.y - p2.y;
|
|
972
|
+
const p4 = {
|
|
973
|
+
x: p3.x + dx,
|
|
974
|
+
y: p3.y + dy
|
|
975
|
+
};
|
|
976
|
+
return [
|
|
977
|
+
{
|
|
978
|
+
type: "line",
|
|
979
|
+
attrs: [
|
|
980
|
+
{ coordinates: [p1, p2] },
|
|
981
|
+
{ coordinates: [p3, p4] },
|
|
982
|
+
{ coordinates: [p1, p4] },
|
|
983
|
+
{ coordinates: [p2, p3] }
|
|
984
|
+
]
|
|
985
|
+
},
|
|
986
|
+
{
|
|
987
|
+
type: "polygon",
|
|
988
|
+
attrs: { coordinates: [p1, p2, p3, p4] },
|
|
989
|
+
styles: { style: "fill" }
|
|
990
|
+
}
|
|
991
|
+
];
|
|
992
|
+
}
|
|
993
|
+
return [];
|
|
994
|
+
}
|
|
995
|
+
};
|
|
996
|
+
var parallelChannel_default = parallelChannel;
|
|
997
|
+
|
|
998
|
+
// src/overlays/longPosition.ts
|
|
999
|
+
var longPosition = {
|
|
1000
|
+
name: "longPosition",
|
|
1001
|
+
totalStep: 3,
|
|
1002
|
+
needDefaultPointFigure: true,
|
|
1003
|
+
needDefaultXAxisFigure: true,
|
|
1004
|
+
needDefaultYAxisFigure: true,
|
|
1005
|
+
createPointFigures: (params) => {
|
|
1006
|
+
const { coordinates, overlay, yAxis } = params;
|
|
1007
|
+
const figures = [];
|
|
1008
|
+
if (coordinates.length > 1 && yAxis) {
|
|
1009
|
+
const startX = coordinates[0].x;
|
|
1010
|
+
const endX = coordinates[1].x;
|
|
1011
|
+
const entryY = coordinates[0].y;
|
|
1012
|
+
const targetY = coordinates[1].y;
|
|
1013
|
+
const stopY = coordinates.length > 2 ? coordinates[2].y : entryY + 40;
|
|
1014
|
+
const entryPrice = overlay.points[0].value;
|
|
1015
|
+
const targetPrice = overlay.points[1].value;
|
|
1016
|
+
const stopPrice = overlay.points[2]?.value ?? yAxis.convertFromPixel(stopY);
|
|
1017
|
+
const reward = targetPrice - entryPrice;
|
|
1018
|
+
const risk = entryPrice - stopPrice;
|
|
1019
|
+
const rr = risk > 0 ? (reward / risk).toFixed(2) : "0.00";
|
|
1020
|
+
const profitPercent = (reward / entryPrice * 100).toFixed(2);
|
|
1021
|
+
const lossPercent = (risk / entryPrice * 100).toFixed(2);
|
|
1022
|
+
figures.push({
|
|
1023
|
+
type: "rect",
|
|
1024
|
+
attrs: {
|
|
1025
|
+
x: Math.min(startX, endX),
|
|
1026
|
+
y: Math.min(entryY, targetY),
|
|
1027
|
+
width: Math.abs(startX - endX),
|
|
1028
|
+
height: Math.abs(entryY - targetY)
|
|
1029
|
+
},
|
|
1030
|
+
styles: { color: "rgba(38, 166, 154, 0.2)", style: "fill" }
|
|
1031
|
+
});
|
|
1032
|
+
figures.push({
|
|
1033
|
+
type: "rect",
|
|
1034
|
+
attrs: {
|
|
1035
|
+
x: Math.min(startX, endX),
|
|
1036
|
+
y: Math.min(entryY, stopY),
|
|
1037
|
+
width: Math.abs(startX - endX),
|
|
1038
|
+
height: Math.abs(entryY - stopY)
|
|
1039
|
+
},
|
|
1040
|
+
styles: { color: "rgba(239, 83, 80, 0.2)", style: "fill" }
|
|
1041
|
+
});
|
|
1042
|
+
figures.push({
|
|
1043
|
+
type: "line",
|
|
1044
|
+
attrs: {
|
|
1045
|
+
coordinates: [
|
|
1046
|
+
{ x: startX, y: entryY },
|
|
1047
|
+
{ x: endX, y: entryY }
|
|
1048
|
+
]
|
|
1049
|
+
},
|
|
1050
|
+
styles: { color: "#888888", size: 2 }
|
|
1051
|
+
});
|
|
1052
|
+
figures.push({
|
|
1053
|
+
type: "text",
|
|
1054
|
+
attrs: {
|
|
1055
|
+
x: endX,
|
|
1056
|
+
y: targetY,
|
|
1057
|
+
text: `Target: ${targetPrice.toFixed(2)} (${profitPercent}%)`,
|
|
1058
|
+
align: "left",
|
|
1059
|
+
baseline: "bottom"
|
|
1060
|
+
},
|
|
1061
|
+
styles: {
|
|
1062
|
+
color: "#26a69a",
|
|
1063
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1064
|
+
paddingLeft: 4,
|
|
1065
|
+
paddingRight: 4
|
|
1066
|
+
}
|
|
1067
|
+
});
|
|
1068
|
+
figures.push({
|
|
1069
|
+
type: "text",
|
|
1070
|
+
attrs: {
|
|
1071
|
+
x: endX,
|
|
1072
|
+
y: stopY,
|
|
1073
|
+
text: `Stop: ${stopPrice.toFixed(2)} (${lossPercent}%)`,
|
|
1074
|
+
align: "left",
|
|
1075
|
+
baseline: "top"
|
|
1076
|
+
},
|
|
1077
|
+
styles: {
|
|
1078
|
+
color: "#ef5350",
|
|
1079
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1080
|
+
paddingLeft: 4,
|
|
1081
|
+
paddingRight: 4
|
|
1082
|
+
}
|
|
1083
|
+
});
|
|
1084
|
+
figures.push({
|
|
1085
|
+
type: "text",
|
|
1086
|
+
attrs: {
|
|
1087
|
+
x: Math.min(startX, endX) + Math.abs(startX - endX) / 2,
|
|
1088
|
+
y: entryY,
|
|
1089
|
+
text: `R/R Ratio: ${rr}`,
|
|
1090
|
+
align: "center",
|
|
1091
|
+
baseline: "middle"
|
|
1092
|
+
},
|
|
1093
|
+
styles: {
|
|
1094
|
+
color: "#ffffff",
|
|
1095
|
+
backgroundColor: "rgba(0,0,0,0.8)",
|
|
1096
|
+
paddingLeft: 6,
|
|
1097
|
+
paddingRight: 6,
|
|
1098
|
+
borderRadius: 2
|
|
1099
|
+
}
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
return figures;
|
|
1103
|
+
}
|
|
1104
|
+
};
|
|
1105
|
+
var longPosition_default = longPosition;
|
|
1106
|
+
|
|
1107
|
+
// src/overlays/shortPosition.ts
|
|
1108
|
+
var shortPosition = {
|
|
1109
|
+
name: "shortPosition",
|
|
1110
|
+
totalStep: 3,
|
|
1111
|
+
needDefaultPointFigure: true,
|
|
1112
|
+
needDefaultXAxisFigure: true,
|
|
1113
|
+
needDefaultYAxisFigure: true,
|
|
1114
|
+
createPointFigures: (params) => {
|
|
1115
|
+
const { coordinates, overlay, yAxis } = params;
|
|
1116
|
+
const figures = [];
|
|
1117
|
+
if (coordinates.length > 1 && yAxis) {
|
|
1118
|
+
const startX = coordinates[0].x;
|
|
1119
|
+
const endX = coordinates[1].x;
|
|
1120
|
+
const entryY = coordinates[0].y;
|
|
1121
|
+
const targetY = coordinates[1].y;
|
|
1122
|
+
const stopY = coordinates.length > 2 ? coordinates[2].y : entryY - 40;
|
|
1123
|
+
const entryPrice = overlay.points[0].value;
|
|
1124
|
+
const targetPrice = overlay.points[1].value;
|
|
1125
|
+
const stopPrice = overlay.points[2]?.value ?? yAxis.convertFromPixel(stopY);
|
|
1126
|
+
const reward = entryPrice - targetPrice;
|
|
1127
|
+
const risk = stopPrice - entryPrice;
|
|
1128
|
+
const rr = risk > 0 ? (reward / risk).toFixed(2) : "0.00";
|
|
1129
|
+
const profitPercent = (reward / entryPrice * 100).toFixed(2);
|
|
1130
|
+
const lossPercent = (risk / entryPrice * 100).toFixed(2);
|
|
1131
|
+
figures.push({
|
|
1132
|
+
type: "rect",
|
|
1133
|
+
attrs: {
|
|
1134
|
+
x: Math.min(startX, endX),
|
|
1135
|
+
y: Math.min(entryY, targetY),
|
|
1136
|
+
width: Math.abs(startX - endX),
|
|
1137
|
+
height: Math.abs(entryY - targetY)
|
|
1138
|
+
},
|
|
1139
|
+
styles: { color: "rgba(38, 166, 154, 0.2)", style: "fill" }
|
|
1140
|
+
});
|
|
1141
|
+
figures.push({
|
|
1142
|
+
type: "rect",
|
|
1143
|
+
attrs: {
|
|
1144
|
+
x: Math.min(startX, endX),
|
|
1145
|
+
y: Math.min(entryY, stopY),
|
|
1146
|
+
width: Math.abs(startX - endX),
|
|
1147
|
+
height: Math.abs(entryY - stopY)
|
|
1148
|
+
},
|
|
1149
|
+
styles: { color: "rgba(239, 83, 80, 0.2)", style: "fill" }
|
|
1150
|
+
});
|
|
1151
|
+
figures.push({
|
|
1152
|
+
type: "line",
|
|
1153
|
+
attrs: {
|
|
1154
|
+
coordinates: [
|
|
1155
|
+
{ x: startX, y: entryY },
|
|
1156
|
+
{ x: endX, y: entryY }
|
|
1157
|
+
]
|
|
1158
|
+
},
|
|
1159
|
+
styles: { color: "#888888", size: 2 }
|
|
1160
|
+
});
|
|
1161
|
+
figures.push({
|
|
1162
|
+
type: "text",
|
|
1163
|
+
attrs: {
|
|
1164
|
+
x: endX,
|
|
1165
|
+
y: targetY,
|
|
1166
|
+
text: `Target: ${targetPrice.toFixed(2)} (${profitPercent}%)`,
|
|
1167
|
+
align: "left",
|
|
1168
|
+
baseline: "top"
|
|
1169
|
+
},
|
|
1170
|
+
styles: {
|
|
1171
|
+
color: "#26a69a",
|
|
1172
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1173
|
+
paddingLeft: 4,
|
|
1174
|
+
paddingRight: 4
|
|
1175
|
+
}
|
|
1176
|
+
});
|
|
1177
|
+
figures.push({
|
|
1178
|
+
type: "text",
|
|
1179
|
+
attrs: {
|
|
1180
|
+
x: endX,
|
|
1181
|
+
y: stopY,
|
|
1182
|
+
text: `Stop: ${stopPrice.toFixed(2)} (${lossPercent}%)`,
|
|
1183
|
+
align: "left",
|
|
1184
|
+
baseline: "bottom"
|
|
1185
|
+
},
|
|
1186
|
+
styles: {
|
|
1187
|
+
color: "#ef5350",
|
|
1188
|
+
backgroundColor: "rgba(0,0,0,0.6)",
|
|
1189
|
+
paddingLeft: 4,
|
|
1190
|
+
paddingRight: 4
|
|
1191
|
+
}
|
|
1192
|
+
});
|
|
1193
|
+
figures.push({
|
|
1194
|
+
type: "text",
|
|
1195
|
+
attrs: {
|
|
1196
|
+
x: Math.min(startX, endX) + Math.abs(startX - endX) / 2,
|
|
1197
|
+
y: entryY,
|
|
1198
|
+
text: `R/R Ratio: ${rr}`,
|
|
1199
|
+
align: "center",
|
|
1200
|
+
baseline: "middle"
|
|
1201
|
+
},
|
|
1202
|
+
styles: {
|
|
1203
|
+
color: "#ffffff",
|
|
1204
|
+
backgroundColor: "rgba(0,0,0,0.8)",
|
|
1205
|
+
paddingLeft: 6,
|
|
1206
|
+
paddingRight: 6,
|
|
1207
|
+
borderRadius: 2
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
return figures;
|
|
1212
|
+
}
|
|
1213
|
+
};
|
|
1214
|
+
var shortPosition_default = shortPosition;
|
|
1215
|
+
|
|
1216
|
+
// src/overlays/measure.ts
|
|
1217
|
+
function formatDuration(ms) {
|
|
1218
|
+
const seconds = Math.floor(ms / 1e3);
|
|
1219
|
+
const minutes = Math.floor(seconds / 60);
|
|
1220
|
+
const hours = Math.floor(minutes / 60);
|
|
1221
|
+
const days = Math.floor(hours / 24);
|
|
1222
|
+
if (days > 0) return `${days}d ${hours % 24}h`;
|
|
1223
|
+
if (hours > 0) return `${hours}h ${minutes % 60}m`;
|
|
1224
|
+
return `${minutes}m`;
|
|
1225
|
+
}
|
|
1226
|
+
var measure = {
|
|
1227
|
+
name: "measure",
|
|
1228
|
+
totalStep: 3,
|
|
1229
|
+
needDefaultPointFigure: true,
|
|
1230
|
+
needDefaultXAxisFigure: true,
|
|
1231
|
+
needDefaultYAxisFigure: true,
|
|
1232
|
+
createPointFigures: (params) => {
|
|
1233
|
+
const { overlay, coordinates, yAxis } = params;
|
|
1234
|
+
if (coordinates.length < 2 || !yAxis) return [];
|
|
1235
|
+
const startPoint = overlay.points[0];
|
|
1236
|
+
const endPoint = overlay.points[1];
|
|
1237
|
+
const startCoord = coordinates[0];
|
|
1238
|
+
const endCoord = coordinates[1];
|
|
1239
|
+
const diff = endPoint.value - startPoint.value;
|
|
1240
|
+
const percent = (diff / startPoint.value * 100).toFixed(2);
|
|
1241
|
+
const bars = Math.abs(
|
|
1242
|
+
(endPoint.dataIndex ?? 0) - (startPoint.dataIndex ?? 0)
|
|
1243
|
+
);
|
|
1244
|
+
const time = formatDuration(
|
|
1245
|
+
Math.abs((endPoint.timestamp ?? 0) - (startPoint.timestamp ?? 0))
|
|
1246
|
+
);
|
|
1247
|
+
const isUp = diff >= 0;
|
|
1248
|
+
const color = isUp ? "rgba(38, 166, 154, 0.2)" : "rgba(239, 83, 80, 0.2)";
|
|
1249
|
+
const strokeColor = isUp ? "#26a69a" : "#ef5350";
|
|
1250
|
+
const rectX = Math.min(startCoord.x, endCoord.x);
|
|
1251
|
+
const rectY = Math.min(startCoord.y, endCoord.y);
|
|
1252
|
+
const rectWidth = Math.abs(startCoord.x - endCoord.x);
|
|
1253
|
+
const rectHeight = Math.abs(startCoord.y - endCoord.y);
|
|
1254
|
+
const infoLines = [
|
|
1255
|
+
`${isUp ? "\u25B2" : "\u25BC"} ${diff.toFixed(2)} (${percent}%)`,
|
|
1256
|
+
`${bars} bars, ${time}`
|
|
1257
|
+
];
|
|
1258
|
+
const textX = endCoord.x;
|
|
1259
|
+
const textY = endCoord.y + (isUp ? -40 : 20);
|
|
1260
|
+
const textFigures = infoLines.map((line, i) => ({
|
|
1261
|
+
type: "text",
|
|
1262
|
+
attrs: {
|
|
1263
|
+
x: textX,
|
|
1264
|
+
y: textY + i * 16,
|
|
1265
|
+
text: line,
|
|
1266
|
+
align: "center",
|
|
1267
|
+
baseline: "middle"
|
|
1268
|
+
},
|
|
1269
|
+
styles: {
|
|
1270
|
+
color: "#fff",
|
|
1271
|
+
backgroundColor: strokeColor,
|
|
1272
|
+
paddingLeft: 4,
|
|
1273
|
+
paddingRight: 4,
|
|
1274
|
+
paddingTop: 2,
|
|
1275
|
+
paddingBottom: 2,
|
|
1276
|
+
borderRadius: 2
|
|
1277
|
+
}
|
|
1278
|
+
}));
|
|
1279
|
+
return [
|
|
1280
|
+
{
|
|
1281
|
+
type: "rect",
|
|
1282
|
+
attrs: {
|
|
1283
|
+
x: rectX,
|
|
1284
|
+
y: rectY,
|
|
1285
|
+
width: rectWidth,
|
|
1286
|
+
height: rectHeight
|
|
1287
|
+
},
|
|
1288
|
+
styles: { style: "fill", color }
|
|
1289
|
+
},
|
|
1290
|
+
{
|
|
1291
|
+
type: "line",
|
|
1292
|
+
attrs: { coordinates: [startCoord, endCoord] },
|
|
1293
|
+
styles: { color: strokeColor, style: "dash" }
|
|
1294
|
+
},
|
|
1295
|
+
...textFigures
|
|
1296
|
+
];
|
|
1297
|
+
}
|
|
1298
|
+
};
|
|
1299
|
+
var measure_default = measure;
|
|
1300
|
+
function getSqSegDist(p, p1, p2) {
|
|
1301
|
+
let x = p1.x;
|
|
1302
|
+
let y = p1.y;
|
|
1303
|
+
let dx = p2.x - x;
|
|
1304
|
+
let dy = p2.y - y;
|
|
1305
|
+
if (dx !== 0 || dy !== 0) {
|
|
1306
|
+
const t = ((p.x - x) * dx + (p.y - y) * dy) / (dx * dx + dy * dy);
|
|
1307
|
+
if (t > 1) {
|
|
1308
|
+
x = p2.x;
|
|
1309
|
+
y = p2.y;
|
|
1310
|
+
} else if (t > 0) {
|
|
1311
|
+
x += dx * t;
|
|
1312
|
+
y += dy * t;
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
dx = p.x - x;
|
|
1316
|
+
dy = p.y - y;
|
|
1317
|
+
return dx * dx + dy * dy;
|
|
1318
|
+
}
|
|
1319
|
+
function rdp(points, epsilon) {
|
|
1320
|
+
const len = points.length;
|
|
1321
|
+
if (len <= 2) return points;
|
|
1322
|
+
const sqEpsilon = epsilon * epsilon;
|
|
1323
|
+
const markers = new Uint8Array(len);
|
|
1324
|
+
markers[0] = markers[len - 1] = 1;
|
|
1325
|
+
const stack = [[0, len - 1]];
|
|
1326
|
+
while (stack.length > 0) {
|
|
1327
|
+
const [first, last] = stack.pop();
|
|
1328
|
+
let maxSqDist = 0;
|
|
1329
|
+
let index = 0;
|
|
1330
|
+
for (let i = first + 1; i < last; i++) {
|
|
1331
|
+
const sqDist = getSqSegDist(points[i], points[first], points[last]);
|
|
1332
|
+
if (sqDist > maxSqDist) {
|
|
1333
|
+
maxSqDist = sqDist;
|
|
1334
|
+
index = i;
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
if (maxSqDist > sqEpsilon) {
|
|
1338
|
+
markers[index] = 1;
|
|
1339
|
+
stack.push([first, index]);
|
|
1340
|
+
stack.push([index, last]);
|
|
1341
|
+
}
|
|
1342
|
+
}
|
|
1343
|
+
const result = [];
|
|
1344
|
+
for (let i = 0; i < len; i++) {
|
|
1345
|
+
if (markers[i]) result.push(points[i]);
|
|
1346
|
+
}
|
|
1347
|
+
return result;
|
|
1348
|
+
}
|
|
1349
|
+
reactKlinecharts.registerFigure({
|
|
1350
|
+
name: "brush_path",
|
|
1351
|
+
draw: (ctx, attrs, styles) => {
|
|
1352
|
+
const { coordinates } = attrs;
|
|
1353
|
+
if (coordinates.length < 2) return;
|
|
1354
|
+
ctx.save();
|
|
1355
|
+
ctx.setLineDash([]);
|
|
1356
|
+
ctx.strokeStyle = styles.color || "#f00";
|
|
1357
|
+
ctx.lineWidth = styles.size || 2;
|
|
1358
|
+
ctx.lineCap = "round";
|
|
1359
|
+
ctx.lineJoin = "round";
|
|
1360
|
+
ctx.beginPath();
|
|
1361
|
+
ctx.moveTo(coordinates[0].x, coordinates[0].y);
|
|
1362
|
+
if (coordinates.length === 2) {
|
|
1363
|
+
ctx.lineTo(coordinates[1].x, coordinates[1].y);
|
|
1364
|
+
} else {
|
|
1365
|
+
for (let i = 1; i < coordinates.length - 2; i++) {
|
|
1366
|
+
const xc = (coordinates[i].x + coordinates[i + 1].x) / 2;
|
|
1367
|
+
const yc = (coordinates[i].y + coordinates[i + 1].y) / 2;
|
|
1368
|
+
ctx.quadraticCurveTo(coordinates[i].x, coordinates[i].y, xc, yc);
|
|
1369
|
+
}
|
|
1370
|
+
const last = coordinates.length - 2;
|
|
1371
|
+
ctx.quadraticCurveTo(
|
|
1372
|
+
coordinates[last].x,
|
|
1373
|
+
coordinates[last].y,
|
|
1374
|
+
coordinates[last + 1].x,
|
|
1375
|
+
coordinates[last + 1].y
|
|
1376
|
+
);
|
|
1377
|
+
}
|
|
1378
|
+
ctx.stroke();
|
|
1379
|
+
ctx.restore();
|
|
1380
|
+
},
|
|
1381
|
+
checkEventOn: (coordinate, attrs, styles) => {
|
|
1382
|
+
const { coordinates } = attrs;
|
|
1383
|
+
if (!coordinates || coordinates.length < 2) return false;
|
|
1384
|
+
const radius = (styles?.size ?? 2) / 2 + 4;
|
|
1385
|
+
const sqRadius = radius * radius;
|
|
1386
|
+
for (let i = 0; i < coordinates.length - 1; i++) {
|
|
1387
|
+
const sqDist = getSqSegDist(
|
|
1388
|
+
coordinate,
|
|
1389
|
+
coordinates[i],
|
|
1390
|
+
coordinates[i + 1]
|
|
1391
|
+
);
|
|
1392
|
+
if (sqDist <= sqRadius) return true;
|
|
1393
|
+
}
|
|
1394
|
+
return false;
|
|
1395
|
+
}
|
|
1396
|
+
});
|
|
1397
|
+
var brush = {
|
|
1398
|
+
name: "brush",
|
|
1399
|
+
totalStep: 3,
|
|
1400
|
+
needDefaultPointFigure: false,
|
|
1401
|
+
needDefaultXAxisFigure: false,
|
|
1402
|
+
needDefaultYAxisFigure: false,
|
|
1403
|
+
onDrawing: (params) => {
|
|
1404
|
+
const { overlay, x, y } = params;
|
|
1405
|
+
const paneId = params.paneId;
|
|
1406
|
+
if (x === void 0 || y === void 0) return true;
|
|
1407
|
+
if (overlay.currentStep !== 2) return true;
|
|
1408
|
+
if (!overlay.extendData) {
|
|
1409
|
+
overlay.extendData = {
|
|
1410
|
+
pixels: [],
|
|
1411
|
+
points: [],
|
|
1412
|
+
isDirty: false,
|
|
1413
|
+
paneId
|
|
1414
|
+
};
|
|
1415
|
+
}
|
|
1416
|
+
const data = overlay.extendData;
|
|
1417
|
+
if (data.paneId && data.paneId !== paneId) return true;
|
|
1418
|
+
const lastPixel = data.pixels[data.pixels.length - 1];
|
|
1419
|
+
if (lastPixel) {
|
|
1420
|
+
const dx = x - lastPixel.x;
|
|
1421
|
+
const dy = y - lastPixel.y;
|
|
1422
|
+
if (dx * dx + dy * dy < 4) return true;
|
|
1423
|
+
}
|
|
1424
|
+
data.pixels.push({ x, y });
|
|
1425
|
+
return true;
|
|
1426
|
+
},
|
|
1427
|
+
onDrawEnd: (params) => {
|
|
1428
|
+
const { overlay } = params;
|
|
1429
|
+
const data = overlay.extendData;
|
|
1430
|
+
if (data) {
|
|
1431
|
+
data.isDirty = true;
|
|
1432
|
+
}
|
|
1433
|
+
return true;
|
|
1434
|
+
},
|
|
1435
|
+
createPointFigures: ({ overlay, xAxis, yAxis, defaultStyles }) => {
|
|
1436
|
+
const data = overlay.extendData;
|
|
1437
|
+
if (!data || !xAxis || !yAxis) return [];
|
|
1438
|
+
if (data.pixels.length > 0) {
|
|
1439
|
+
for (const p of data.pixels) {
|
|
1440
|
+
data.points.push({
|
|
1441
|
+
timestamp: xAxis.convertFromPixel(p.x),
|
|
1442
|
+
value: yAxis.convertFromPixel(p.y)
|
|
1443
|
+
});
|
|
1444
|
+
}
|
|
1445
|
+
data.pixels = [];
|
|
1446
|
+
}
|
|
1447
|
+
let { points } = data;
|
|
1448
|
+
if (data.isDirty && points.length > 2) {
|
|
1449
|
+
const pixelPoints = points.map((p) => ({
|
|
1450
|
+
x: xAxis.convertToPixel(p.timestamp),
|
|
1451
|
+
y: yAxis.convertToPixel(p.value)
|
|
1452
|
+
}));
|
|
1453
|
+
const simplified = rdp(pixelPoints, 1.5);
|
|
1454
|
+
data.points = simplified.map((p) => ({
|
|
1455
|
+
timestamp: xAxis.convertFromPixel(p.x),
|
|
1456
|
+
value: yAxis.convertFromPixel(p.y)
|
|
1457
|
+
}));
|
|
1458
|
+
points = data.points;
|
|
1459
|
+
data.isDirty = false;
|
|
1460
|
+
}
|
|
1461
|
+
if (points.length < 2) return [];
|
|
1462
|
+
const coordinates = points.map((p) => ({
|
|
1463
|
+
x: xAxis.convertToPixel(p.timestamp),
|
|
1464
|
+
y: yAxis.convertToPixel(p.value)
|
|
1465
|
+
}));
|
|
1466
|
+
return [
|
|
1467
|
+
{
|
|
1468
|
+
type: "brush_path",
|
|
1469
|
+
attrs: { coordinates },
|
|
1470
|
+
styles: {
|
|
1471
|
+
color: overlay.styles?.line?.color ?? defaultStyles?.line?.color ?? "#1677ff",
|
|
1472
|
+
size: overlay.styles?.line?.size ?? defaultStyles?.line?.size ?? 2
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
];
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
var brush_default = brush;
|
|
1479
|
+
|
|
1480
|
+
// src/indicators/index.ts
|
|
1481
|
+
var indicators_exports = {};
|
|
1482
|
+
__export(indicators_exports, {
|
|
1483
|
+
bollTv: () => bollTv_default,
|
|
1484
|
+
cci: () => cci_default,
|
|
1485
|
+
hma: () => hma_default,
|
|
1486
|
+
ichimoku: () => ichimoku_default,
|
|
1487
|
+
maRibbon: () => maRibbon_default,
|
|
1488
|
+
macdTv: () => macdTv_default,
|
|
1489
|
+
pivotPoints: () => pivotPoints_default,
|
|
1490
|
+
rsiTv: () => rsiTv_default,
|
|
1491
|
+
stochastic: () => stochastic_default,
|
|
1492
|
+
superTrend: () => superTrend_default,
|
|
1493
|
+
vwap: () => vwap_default
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
// src/utils/TA.ts
|
|
1497
|
+
var TA = {
|
|
1498
|
+
/**
|
|
1499
|
+
* Simple Moving Average (SMA)
|
|
1500
|
+
* Optimized with running sum.
|
|
1501
|
+
*/
|
|
1502
|
+
sma: (data, period) => {
|
|
1503
|
+
const result = [];
|
|
1504
|
+
let sum = 0;
|
|
1505
|
+
for (let i = 0; i < data.length; i++) {
|
|
1506
|
+
sum += data[i];
|
|
1507
|
+
if (i >= period) {
|
|
1508
|
+
sum -= data[i - period];
|
|
1509
|
+
}
|
|
1510
|
+
if (i >= period - 1) {
|
|
1511
|
+
result.push(sum / period);
|
|
1512
|
+
} else {
|
|
1513
|
+
result.push(null);
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
return result;
|
|
1517
|
+
},
|
|
1518
|
+
/**
|
|
1519
|
+
* Exponential Moving Average (EMA)
|
|
1520
|
+
* alpha = 2 / (period + 1)
|
|
1521
|
+
*/
|
|
1522
|
+
ema: (data, period) => {
|
|
1523
|
+
const result = [];
|
|
1524
|
+
const alpha = 2 / (period + 1);
|
|
1525
|
+
let prevEma = null;
|
|
1526
|
+
for (let i = 0; i < data.length; i++) {
|
|
1527
|
+
if (prevEma === null) {
|
|
1528
|
+
if (i === period - 1) {
|
|
1529
|
+
let sum = 0;
|
|
1530
|
+
for (let j = 0; j <= i; j++) sum += data[j];
|
|
1531
|
+
prevEma = sum / period;
|
|
1532
|
+
result.push(prevEma);
|
|
1533
|
+
} else {
|
|
1534
|
+
result.push(null);
|
|
1535
|
+
}
|
|
1536
|
+
} else {
|
|
1537
|
+
prevEma = data[i] * alpha + prevEma * (1 - alpha);
|
|
1538
|
+
result.push(prevEma);
|
|
1539
|
+
}
|
|
1540
|
+
}
|
|
1541
|
+
return result;
|
|
1542
|
+
},
|
|
1543
|
+
/**
|
|
1544
|
+
* Running Moving Average (RMA / Wilder's MA)
|
|
1545
|
+
* Used in RSI, alpha = 1 / period
|
|
1546
|
+
*/
|
|
1547
|
+
rma: (data, period) => {
|
|
1548
|
+
const result = [];
|
|
1549
|
+
const alpha = 1 / period;
|
|
1550
|
+
let prevRma = null;
|
|
1551
|
+
for (let i = 0; i < data.length; i++) {
|
|
1552
|
+
if (prevRma === null) {
|
|
1553
|
+
if (i === period - 1) {
|
|
1554
|
+
let sum = 0;
|
|
1555
|
+
for (let j = 0; j <= i; j++) sum += data[j];
|
|
1556
|
+
prevRma = sum / period;
|
|
1557
|
+
result.push(prevRma);
|
|
1558
|
+
} else {
|
|
1559
|
+
result.push(null);
|
|
1560
|
+
}
|
|
1561
|
+
} else {
|
|
1562
|
+
prevRma = data[i] * alpha + prevRma * (1 - alpha);
|
|
1563
|
+
result.push(prevRma);
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
return result;
|
|
1567
|
+
},
|
|
1568
|
+
/**
|
|
1569
|
+
* Standard Deviation
|
|
1570
|
+
*/
|
|
1571
|
+
stdev: (data, period) => {
|
|
1572
|
+
const result = [];
|
|
1573
|
+
const sma = TA.sma(data, period);
|
|
1574
|
+
for (let i = 0; i < data.length; i++) {
|
|
1575
|
+
const currentSma = sma[i];
|
|
1576
|
+
if (currentSma === null) {
|
|
1577
|
+
result.push(null);
|
|
1578
|
+
} else {
|
|
1579
|
+
let sumSq = 0;
|
|
1580
|
+
for (let j = 0; j < period; j++) {
|
|
1581
|
+
sumSq += Math.pow(data[i - j] - currentSma, 2);
|
|
1582
|
+
}
|
|
1583
|
+
result.push(Math.sqrt(sumSq / period));
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
return result;
|
|
1587
|
+
},
|
|
1588
|
+
/**
|
|
1589
|
+
* Relative Strength Index (RSI)
|
|
1590
|
+
*/
|
|
1591
|
+
rsi: (data, period) => {
|
|
1592
|
+
const changes = [0];
|
|
1593
|
+
for (let i = 1; i < data.length; i++) {
|
|
1594
|
+
changes.push(data[i] - data[i - 1]);
|
|
1595
|
+
}
|
|
1596
|
+
const ups = changes.map((c) => Math.max(c, 0));
|
|
1597
|
+
const downs = changes.map((c) => Math.max(-c, 0));
|
|
1598
|
+
const avgUps = TA.rma(ups, period);
|
|
1599
|
+
const avgDowns = TA.rma(downs, period);
|
|
1600
|
+
return avgUps.map((up, i) => {
|
|
1601
|
+
const down = avgDowns[i];
|
|
1602
|
+
if (up === null || down === null) return null;
|
|
1603
|
+
if (down === 0) return 100;
|
|
1604
|
+
const rs = up / down;
|
|
1605
|
+
return 100 - 100 / (1 + rs);
|
|
1606
|
+
});
|
|
1607
|
+
},
|
|
1608
|
+
/**
|
|
1609
|
+
* Moving Average Convergence Divergence (MACD)
|
|
1610
|
+
*/
|
|
1611
|
+
macd: (data, fastPeriod, slowPeriod, signalPeriod) => {
|
|
1612
|
+
const fastEma = TA.ema(data, fastPeriod);
|
|
1613
|
+
const slowEma = TA.ema(data, slowPeriod);
|
|
1614
|
+
const dif = fastEma.map(
|
|
1615
|
+
(f, i) => f !== null && slowEma[i] !== null ? f - slowEma[i] : null
|
|
1616
|
+
);
|
|
1617
|
+
const dea = TA.ema(
|
|
1618
|
+
dif.filter((v) => v !== null),
|
|
1619
|
+
signalPeriod
|
|
1620
|
+
);
|
|
1621
|
+
let deaIdx = 0;
|
|
1622
|
+
const fullDea = dif.map((v) => v === null ? null : dea[deaIdx++]);
|
|
1623
|
+
const macd = dif.map(
|
|
1624
|
+
(v, i) => v !== null && fullDea[i] !== null ? v - fullDea[i] : null
|
|
1625
|
+
);
|
|
1626
|
+
return { dif, dea: fullDea, macd };
|
|
1627
|
+
},
|
|
1628
|
+
/**
|
|
1629
|
+
* Bollinger Bands (BOLL)
|
|
1630
|
+
*/
|
|
1631
|
+
bollinger: (data, period, multiplier) => {
|
|
1632
|
+
const mid = TA.sma(data, period);
|
|
1633
|
+
const std = TA.stdev(data, period);
|
|
1634
|
+
const upper = mid.map(
|
|
1635
|
+
(m, i) => m !== null && std[i] !== null ? m + multiplier * std[i] : null
|
|
1636
|
+
);
|
|
1637
|
+
const lower = mid.map(
|
|
1638
|
+
(m, i) => m !== null && std[i] !== null ? m - multiplier * std[i] : null
|
|
1639
|
+
);
|
|
1640
|
+
return { mid, upper, lower };
|
|
1641
|
+
},
|
|
1642
|
+
/**
|
|
1643
|
+
* Weighted Moving Average (WMA)
|
|
1644
|
+
*/
|
|
1645
|
+
wma: (data, period) => {
|
|
1646
|
+
const result = [];
|
|
1647
|
+
let sumWeight = 0;
|
|
1648
|
+
for (let i = 1; i <= period; i++) sumWeight += i;
|
|
1649
|
+
for (let i = 0; i < data.length; i++) {
|
|
1650
|
+
if (i < period - 1) {
|
|
1651
|
+
result.push(null);
|
|
1652
|
+
} else {
|
|
1653
|
+
let sum = 0;
|
|
1654
|
+
for (let j = 0; j < period; j++) {
|
|
1655
|
+
sum += data[i - j] * (period - j);
|
|
1656
|
+
}
|
|
1657
|
+
result.push(sum / sumWeight);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
return result;
|
|
1661
|
+
},
|
|
1662
|
+
/**
|
|
1663
|
+
* True Range (TR)
|
|
1664
|
+
*/
|
|
1665
|
+
tr: (highs, lows, closes) => {
|
|
1666
|
+
const result = [];
|
|
1667
|
+
for (let i = 0; i < highs.length; i++) {
|
|
1668
|
+
if (i === 0) {
|
|
1669
|
+
result.push(highs[i] - lows[i]);
|
|
1670
|
+
} else {
|
|
1671
|
+
const tr = Math.max(
|
|
1672
|
+
highs[i] - lows[i],
|
|
1673
|
+
Math.abs(highs[i] - closes[i - 1]),
|
|
1674
|
+
Math.abs(lows[i] - closes[i - 1])
|
|
1675
|
+
);
|
|
1676
|
+
result.push(tr);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
return result;
|
|
1680
|
+
},
|
|
1681
|
+
/**
|
|
1682
|
+
* Average True Range (ATR)
|
|
1683
|
+
*/
|
|
1684
|
+
atr: (highs, lows, closes, period) => {
|
|
1685
|
+
const tr = TA.tr(highs, lows, closes);
|
|
1686
|
+
return TA.rma(tr, period);
|
|
1687
|
+
},
|
|
1688
|
+
/**
|
|
1689
|
+
* Volume Weighted Average Price (VWAP)
|
|
1690
|
+
*/
|
|
1691
|
+
vwap: (highs, lows, closes, volumes) => {
|
|
1692
|
+
let totalVolume = 0;
|
|
1693
|
+
let totalVolumePrice = 0;
|
|
1694
|
+
return highs.map((h, i) => {
|
|
1695
|
+
const price = (h + lows[i] + closes[i]) / 3;
|
|
1696
|
+
totalVolume += volumes[i];
|
|
1697
|
+
totalVolumePrice += price * volumes[i];
|
|
1698
|
+
return totalVolume === 0 ? price : totalVolumePrice / totalVolume;
|
|
1699
|
+
});
|
|
1700
|
+
},
|
|
1701
|
+
/**
|
|
1702
|
+
* Commodity Channel Index (CCI)
|
|
1703
|
+
*/
|
|
1704
|
+
cci: (highs, lows, closes, period) => {
|
|
1705
|
+
const tp = highs.map((h, i) => (h + lows[i] + closes[i]) / 3);
|
|
1706
|
+
const smaTp = TA.sma(tp, period);
|
|
1707
|
+
const result = [];
|
|
1708
|
+
for (let i = 0; i < tp.length; i++) {
|
|
1709
|
+
const currentSma = smaTp[i];
|
|
1710
|
+
if (currentSma === null) {
|
|
1711
|
+
result.push(null);
|
|
1712
|
+
} else {
|
|
1713
|
+
let meanDev = 0;
|
|
1714
|
+
for (let j = 0; j < period; j++) {
|
|
1715
|
+
meanDev += Math.abs(tp[i - j] - currentSma);
|
|
1716
|
+
}
|
|
1717
|
+
meanDev /= period;
|
|
1718
|
+
if (meanDev === 0) {
|
|
1719
|
+
result.push(0);
|
|
1720
|
+
} else {
|
|
1721
|
+
result.push((tp[i] - currentSma) / (0.015 * meanDev));
|
|
1722
|
+
}
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return result;
|
|
1726
|
+
},
|
|
1727
|
+
/**
|
|
1728
|
+
* Hull Moving Average (HMA)
|
|
1729
|
+
*/
|
|
1730
|
+
hma: (data, period) => {
|
|
1731
|
+
const halfPeriod = Math.floor(period / 2);
|
|
1732
|
+
const sqrtPeriod = Math.floor(Math.sqrt(period));
|
|
1733
|
+
const wma1 = TA.wma(data, halfPeriod);
|
|
1734
|
+
const wma2 = TA.wma(data, period);
|
|
1735
|
+
const diff = wma1.map((v, i) => {
|
|
1736
|
+
if (v !== null && wma2[i] !== null) {
|
|
1737
|
+
return 2 * v - wma2[i];
|
|
1738
|
+
}
|
|
1739
|
+
return null;
|
|
1740
|
+
});
|
|
1741
|
+
const diffValues = diff.filter((v) => v !== null);
|
|
1742
|
+
const finalHma = TA.wma(diffValues, sqrtPeriod);
|
|
1743
|
+
let finalIndex = 0;
|
|
1744
|
+
return diff.map((v) => {
|
|
1745
|
+
if (v === null) return null;
|
|
1746
|
+
return finalHma[finalIndex++] ?? null;
|
|
1747
|
+
});
|
|
1748
|
+
}
|
|
1749
|
+
};
|
|
1750
|
+
var TA_default = TA;
|
|
1751
|
+
|
|
1752
|
+
// src/indicators/bollTv.ts
|
|
1753
|
+
var bollTv = {
|
|
1754
|
+
name: "BOLL_TV",
|
|
1755
|
+
shortName: "BOLL (TV)",
|
|
1756
|
+
calcParams: [20, 2],
|
|
1757
|
+
figures: [
|
|
1758
|
+
{ key: "mid", title: "Mid: ", type: "line" },
|
|
1759
|
+
{ key: "upper", title: "Upper: ", type: "line" },
|
|
1760
|
+
{ key: "lower", title: "Lower: ", type: "line" }
|
|
1761
|
+
],
|
|
1762
|
+
calc: (dataList, indicator) => {
|
|
1763
|
+
const period = indicator.calcParams[0];
|
|
1764
|
+
const multiplier = indicator.calcParams[1];
|
|
1765
|
+
const closes = dataList.map((d) => d.close);
|
|
1766
|
+
const { mid, upper, lower } = TA_default.bollinger(closes, period, multiplier);
|
|
1767
|
+
return dataList.map((_, i) => ({
|
|
1768
|
+
mid: mid[i],
|
|
1769
|
+
upper: upper[i],
|
|
1770
|
+
lower: lower[i]
|
|
1771
|
+
}));
|
|
1772
|
+
}
|
|
1773
|
+
};
|
|
1774
|
+
var bollTv_default = bollTv;
|
|
1775
|
+
|
|
1776
|
+
// src/indicators/cci.ts
|
|
1777
|
+
var cci = {
|
|
1778
|
+
name: "CCI_TV",
|
|
1779
|
+
shortName: "CCI",
|
|
1780
|
+
calcParams: [20],
|
|
1781
|
+
figures: [{ key: "cci", title: "CCI: ", type: "line" }],
|
|
1782
|
+
calc: (dataList, indicator) => {
|
|
1783
|
+
const period = indicator.calcParams[0];
|
|
1784
|
+
const highs = dataList.map((d) => d.high);
|
|
1785
|
+
const lows = dataList.map((d) => d.low);
|
|
1786
|
+
const closes = dataList.map((d) => d.close);
|
|
1787
|
+
const cciValues = TA_default.cci(highs, lows, closes, period);
|
|
1788
|
+
return cciValues.map((v) => ({ cci: v }));
|
|
1789
|
+
}
|
|
1790
|
+
};
|
|
1791
|
+
var cci_default = cci;
|
|
1792
|
+
|
|
1793
|
+
// src/indicators/hma.ts
|
|
1794
|
+
var hma = {
|
|
1795
|
+
name: "HMA",
|
|
1796
|
+
shortName: "HMA",
|
|
1797
|
+
calcParams: [9],
|
|
1798
|
+
figures: [{ key: "hma", title: "HMA: ", type: "line" }],
|
|
1799
|
+
calc: (dataList, indicator) => {
|
|
1800
|
+
const period = indicator.calcParams[0];
|
|
1801
|
+
const halfPeriod = Math.floor(period / 2);
|
|
1802
|
+
const sqrtPeriod = Math.floor(Math.sqrt(period));
|
|
1803
|
+
const closes = dataList.map((d) => d.close);
|
|
1804
|
+
const wma1 = TA_default.wma(closes, halfPeriod);
|
|
1805
|
+
const wma2 = TA_default.wma(closes, period);
|
|
1806
|
+
const diff = wma1.map((v, i) => {
|
|
1807
|
+
if (v !== null && wma2[i] !== null) {
|
|
1808
|
+
return 2 * v - wma2[i];
|
|
1809
|
+
}
|
|
1810
|
+
return null;
|
|
1811
|
+
});
|
|
1812
|
+
const diffValues = diff.filter((v) => v !== null);
|
|
1813
|
+
const finalHma = TA_default.wma(diffValues, sqrtPeriod);
|
|
1814
|
+
let finalIndex = 0;
|
|
1815
|
+
return diff.map((v) => {
|
|
1816
|
+
if (v === null) return { hma: null };
|
|
1817
|
+
const res = finalHma[finalIndex++];
|
|
1818
|
+
return { hma: res };
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
};
|
|
1822
|
+
var hma_default = hma;
|
|
1823
|
+
|
|
1824
|
+
// src/indicators/ichimoku.ts
|
|
1825
|
+
var ichimoku = {
|
|
1826
|
+
name: "Ichimoku",
|
|
1827
|
+
shortName: "Ichimoku",
|
|
1828
|
+
calcParams: [9, 26, 52, 26],
|
|
1829
|
+
figures: [
|
|
1830
|
+
{ key: "tenkan", title: "Tenkan: ", type: "line" },
|
|
1831
|
+
{ key: "kijun", title: "Kijun: ", type: "line" },
|
|
1832
|
+
{ key: "chikou", title: "Chikou: ", type: "line" },
|
|
1833
|
+
{ key: "spanA", title: "Span A: ", type: "line" },
|
|
1834
|
+
{ key: "spanB", title: "Span B: ", type: "line" }
|
|
1835
|
+
],
|
|
1836
|
+
calc: (dataList, indicator) => {
|
|
1837
|
+
const params = indicator.calcParams;
|
|
1838
|
+
const tenkanPeriod = params[0];
|
|
1839
|
+
const kijunPeriod = params[1];
|
|
1840
|
+
const spanBPeriod = params[2];
|
|
1841
|
+
const offset = params[3];
|
|
1842
|
+
const highLowAvg = (data, start, end) => {
|
|
1843
|
+
let high = -Infinity;
|
|
1844
|
+
let low = Infinity;
|
|
1845
|
+
for (let i = start; i <= end; i++) {
|
|
1846
|
+
high = Math.max(high, data[i].high);
|
|
1847
|
+
low = Math.min(low, data[i].low);
|
|
1848
|
+
}
|
|
1849
|
+
return (high + low) / 2;
|
|
1850
|
+
};
|
|
1851
|
+
return dataList.map((_kLineData, index) => {
|
|
1852
|
+
const item = {
|
|
1853
|
+
tenkan: null,
|
|
1854
|
+
kijun: null,
|
|
1855
|
+
chikou: null,
|
|
1856
|
+
spanA: null,
|
|
1857
|
+
spanB: null
|
|
1858
|
+
};
|
|
1859
|
+
if (index >= tenkanPeriod - 1) {
|
|
1860
|
+
item.tenkan = highLowAvg(
|
|
1861
|
+
dataList,
|
|
1862
|
+
index - tenkanPeriod + 1,
|
|
1863
|
+
index
|
|
1864
|
+
);
|
|
1865
|
+
}
|
|
1866
|
+
if (index >= kijunPeriod - 1) {
|
|
1867
|
+
item.kijun = highLowAvg(dataList, index - kijunPeriod + 1, index);
|
|
1868
|
+
}
|
|
1869
|
+
if (index + offset < dataList.length) {
|
|
1870
|
+
item.chikou = dataList[index + offset].close;
|
|
1871
|
+
}
|
|
1872
|
+
const prevIndex = index - offset;
|
|
1873
|
+
if (prevIndex >= 0) {
|
|
1874
|
+
const prevTenkan = prevIndex >= tenkanPeriod - 1 ? highLowAvg(dataList, prevIndex - tenkanPeriod + 1, prevIndex) : null;
|
|
1875
|
+
const prevKijun = prevIndex >= kijunPeriod - 1 ? highLowAvg(dataList, prevIndex - kijunPeriod + 1, prevIndex) : null;
|
|
1876
|
+
if (prevTenkan !== null && prevKijun !== null) {
|
|
1877
|
+
item.spanA = (prevTenkan + prevKijun) / 2;
|
|
1878
|
+
}
|
|
1879
|
+
if (prevIndex >= spanBPeriod - 1) {
|
|
1880
|
+
item.spanB = highLowAvg(
|
|
1881
|
+
dataList,
|
|
1882
|
+
prevIndex - spanBPeriod + 1,
|
|
1883
|
+
prevIndex
|
|
1884
|
+
);
|
|
1885
|
+
}
|
|
1886
|
+
}
|
|
1887
|
+
return item;
|
|
1888
|
+
});
|
|
1889
|
+
}
|
|
1890
|
+
};
|
|
1891
|
+
var ichimoku_default = ichimoku;
|
|
1892
|
+
|
|
1893
|
+
// src/indicators/maRibbon.ts
|
|
1894
|
+
var COLORS = [
|
|
1895
|
+
"#001CFF",
|
|
1896
|
+
"#0055FF",
|
|
1897
|
+
"#008CFF",
|
|
1898
|
+
"#00C4FF",
|
|
1899
|
+
"#00FFED",
|
|
1900
|
+
"#00FF8E",
|
|
1901
|
+
"#2EFF00",
|
|
1902
|
+
"#B7FF00",
|
|
1903
|
+
"#FFE100",
|
|
1904
|
+
"#FF9100",
|
|
1905
|
+
"#FF4400",
|
|
1906
|
+
"#FF0000",
|
|
1907
|
+
"#C4003E",
|
|
1908
|
+
"#8A007B",
|
|
1909
|
+
"#4E00B8"
|
|
1910
|
+
];
|
|
1911
|
+
var maRibbon = {
|
|
1912
|
+
name: "MA_Ribbon",
|
|
1913
|
+
shortName: "Ribbon",
|
|
1914
|
+
series: "price",
|
|
1915
|
+
calcParams: [10, 20, 30, 40],
|
|
1916
|
+
figures: Array.from({ length: 15 }).map((_, i) => ({
|
|
1917
|
+
key: `ma${i}`,
|
|
1918
|
+
title: `MA${i + 1}: `,
|
|
1919
|
+
type: "line",
|
|
1920
|
+
styles: () => ({ color: COLORS[i] })
|
|
1921
|
+
})),
|
|
1922
|
+
calc: (dataList, indicator) => {
|
|
1923
|
+
const params = indicator.calcParams;
|
|
1924
|
+
const closes = dataList.map((d) => d.close);
|
|
1925
|
+
const count = Math.min(params.length, COLORS.length);
|
|
1926
|
+
const emas = [];
|
|
1927
|
+
for (let i = 0; i < count; i++) {
|
|
1928
|
+
emas.push(TA_default.ema(closes, params[i]));
|
|
1929
|
+
}
|
|
1930
|
+
return dataList.map((_, i) => {
|
|
1931
|
+
const barData = {};
|
|
1932
|
+
for (let j = 0; j < count; j++) {
|
|
1933
|
+
barData[`ma${j}`] = emas[j][i];
|
|
1934
|
+
}
|
|
1935
|
+
return barData;
|
|
1936
|
+
});
|
|
1937
|
+
}
|
|
1938
|
+
};
|
|
1939
|
+
var maRibbon_default = maRibbon;
|
|
1940
|
+
|
|
1941
|
+
// src/indicators/macdTv.ts
|
|
1942
|
+
var macdTv = {
|
|
1943
|
+
name: "MACD_TV",
|
|
1944
|
+
shortName: "MACD (TV)",
|
|
1945
|
+
calcParams: [12, 26, 9],
|
|
1946
|
+
figures: [
|
|
1947
|
+
{
|
|
1948
|
+
key: "histogram",
|
|
1949
|
+
title: "Histogram: ",
|
|
1950
|
+
type: "bar",
|
|
1951
|
+
baseValue: 0,
|
|
1952
|
+
styles: (data) => {
|
|
1953
|
+
const current = data.current?.histogram ?? 0;
|
|
1954
|
+
const pre = data.prev?.histogram ?? 0;
|
|
1955
|
+
let color = "#26A69A";
|
|
1956
|
+
if (current > 0) {
|
|
1957
|
+
color = current > pre ? "#26A69A" : "#B2DFDB";
|
|
1958
|
+
} else if (current < 0) {
|
|
1959
|
+
color = current < pre ? "#FF5252" : "#FFCDD2";
|
|
1960
|
+
} else {
|
|
1961
|
+
color = "#B2DFDB";
|
|
1962
|
+
}
|
|
1963
|
+
return { color };
|
|
1964
|
+
}
|
|
1965
|
+
},
|
|
1966
|
+
{
|
|
1967
|
+
key: "macd",
|
|
1968
|
+
title: "MACD: ",
|
|
1969
|
+
type: "line",
|
|
1970
|
+
styles: () => ({ color: "#2962FF" })
|
|
1971
|
+
},
|
|
1972
|
+
{
|
|
1973
|
+
key: "signal",
|
|
1974
|
+
title: "Signal: ",
|
|
1975
|
+
type: "line",
|
|
1976
|
+
styles: () => ({ color: "#FF6D00" })
|
|
1977
|
+
}
|
|
1978
|
+
],
|
|
1979
|
+
calc: (dataList, indicator) => {
|
|
1980
|
+
const fast = indicator.calcParams[0];
|
|
1981
|
+
const slow = indicator.calcParams[1];
|
|
1982
|
+
const signalLen = indicator.calcParams[2];
|
|
1983
|
+
const closes = dataList.map((d) => d.close);
|
|
1984
|
+
const { dif, dea, macd } = TA_default.macd(closes, fast, slow, signalLen);
|
|
1985
|
+
return dataList.map((_, i) => ({
|
|
1986
|
+
macd: dif[i],
|
|
1987
|
+
signal: dea[i],
|
|
1988
|
+
histogram: macd[i]
|
|
1989
|
+
}));
|
|
1990
|
+
}
|
|
1991
|
+
};
|
|
1992
|
+
var macdTv_default = macdTv;
|
|
1993
|
+
|
|
1994
|
+
// src/indicators/pivotPoints.ts
|
|
1995
|
+
var pivotPoints = {
|
|
1996
|
+
name: "PivotPoints",
|
|
1997
|
+
shortName: "Pivot",
|
|
1998
|
+
calcParams: [],
|
|
1999
|
+
figures: [
|
|
2000
|
+
{ key: "p", title: "P: ", type: "line" },
|
|
2001
|
+
{ key: "r1", title: "R1: ", type: "line" },
|
|
2002
|
+
{ key: "s1", title: "S1: ", type: "line" },
|
|
2003
|
+
{ key: "r2", title: "R2: ", type: "line" },
|
|
2004
|
+
{ key: "s2", title: "S2: ", type: "line" }
|
|
2005
|
+
],
|
|
2006
|
+
calc: (dataList) => {
|
|
2007
|
+
let lastP = null;
|
|
2008
|
+
let lastR1 = null;
|
|
2009
|
+
let lastS1 = null;
|
|
2010
|
+
let lastR2 = null;
|
|
2011
|
+
let lastS2 = null;
|
|
2012
|
+
let lastDate = "";
|
|
2013
|
+
let dayHigh = -Infinity;
|
|
2014
|
+
let dayLow = Infinity;
|
|
2015
|
+
let dayClose = 0;
|
|
2016
|
+
return dataList.map((kLineData) => {
|
|
2017
|
+
const date = new Date(kLineData.timestamp).toLocaleDateString();
|
|
2018
|
+
if (date !== lastDate) {
|
|
2019
|
+
if (lastDate !== "") {
|
|
2020
|
+
lastP = (dayHigh + dayLow + dayClose) / 3;
|
|
2021
|
+
lastR1 = 2 * lastP - dayLow;
|
|
2022
|
+
lastS1 = 2 * lastP - dayHigh;
|
|
2023
|
+
lastR2 = lastP + (dayHigh - dayLow);
|
|
2024
|
+
lastS2 = lastP - (dayHigh - dayLow);
|
|
2025
|
+
}
|
|
2026
|
+
dayHigh = kLineData.high;
|
|
2027
|
+
dayLow = kLineData.low;
|
|
2028
|
+
dayClose = kLineData.close;
|
|
2029
|
+
lastDate = date;
|
|
2030
|
+
} else {
|
|
2031
|
+
dayHigh = Math.max(dayHigh, kLineData.high);
|
|
2032
|
+
dayLow = Math.min(dayLow, kLineData.low);
|
|
2033
|
+
dayClose = kLineData.close;
|
|
2034
|
+
}
|
|
2035
|
+
return {
|
|
2036
|
+
p: lastP,
|
|
2037
|
+
r1: lastR1,
|
|
2038
|
+
s1: lastS1,
|
|
2039
|
+
r2: lastR2,
|
|
2040
|
+
s2: lastS2
|
|
2041
|
+
};
|
|
2042
|
+
});
|
|
2043
|
+
}
|
|
2044
|
+
};
|
|
2045
|
+
var pivotPoints_default = pivotPoints;
|
|
2046
|
+
|
|
2047
|
+
// src/indicators/rsiTv.ts
|
|
2048
|
+
var rsiTv = {
|
|
2049
|
+
name: "RSI_TV",
|
|
2050
|
+
shortName: "RSI (TV)",
|
|
2051
|
+
calcParams: [14, 14],
|
|
2052
|
+
figures: [
|
|
2053
|
+
{
|
|
2054
|
+
key: "rsi",
|
|
2055
|
+
title: "RSI: ",
|
|
2056
|
+
type: "line",
|
|
2057
|
+
styles: () => ({ color: "#7E57C2", size: 1.5 })
|
|
2058
|
+
},
|
|
2059
|
+
{
|
|
2060
|
+
key: "rsi_ma",
|
|
2061
|
+
title: "MA: ",
|
|
2062
|
+
type: "line",
|
|
2063
|
+
styles: () => ({ color: "#FFEE58", size: 1.2 })
|
|
2064
|
+
}
|
|
2065
|
+
],
|
|
2066
|
+
calc: (dataList, indicator) => {
|
|
2067
|
+
const rsiPeriod = indicator.calcParams[0];
|
|
2068
|
+
const maPeriod = indicator.calcParams[1];
|
|
2069
|
+
const closes = dataList.map((d) => d.close);
|
|
2070
|
+
const rsiValues = TA_default.rsi(closes, rsiPeriod);
|
|
2071
|
+
const nonNullRsi = rsiValues.map((v) => v ?? 0);
|
|
2072
|
+
const maValues = TA_default.sma(nonNullRsi, maPeriod);
|
|
2073
|
+
return dataList.map((_, i) => {
|
|
2074
|
+
const rsi = rsiValues[i];
|
|
2075
|
+
const rsi_ma = rsi !== null && maValues[i] !== null ? maValues[i] : null;
|
|
2076
|
+
return { rsi, rsi_ma };
|
|
2077
|
+
});
|
|
2078
|
+
},
|
|
2079
|
+
draw: ({
|
|
2080
|
+
ctx,
|
|
2081
|
+
chart,
|
|
2082
|
+
indicator,
|
|
2083
|
+
bounding,
|
|
2084
|
+
yAxis
|
|
2085
|
+
}) => {
|
|
2086
|
+
const { from, to } = chart.getVisibleRange();
|
|
2087
|
+
const barSpace = chart.getBarSpace();
|
|
2088
|
+
const resultData = indicator.result;
|
|
2089
|
+
const y70 = yAxis.convertToPixel(70);
|
|
2090
|
+
const y50 = yAxis.convertToPixel(50);
|
|
2091
|
+
const y30 = yAxis.convertToPixel(30);
|
|
2092
|
+
const left = bounding.left;
|
|
2093
|
+
const right = bounding.left + bounding.width;
|
|
2094
|
+
const getX = (i) => right - barSpace.halfBar - (to - 1 - i) * barSpace.bar;
|
|
2095
|
+
ctx.save();
|
|
2096
|
+
const fillZone = (yThreshold, above, gradFrom, gradTo) => {
|
|
2097
|
+
const compare = above ? (v) => v > 70 : (v) => v < 30;
|
|
2098
|
+
let i = from;
|
|
2099
|
+
while (i < to) {
|
|
2100
|
+
while (i < to) {
|
|
2101
|
+
const d = resultData[i];
|
|
2102
|
+
const v = d?.rsi;
|
|
2103
|
+
if (v !== null && v !== void 0 && compare(v)) break;
|
|
2104
|
+
i++;
|
|
2105
|
+
}
|
|
2106
|
+
if (i >= to) break;
|
|
2107
|
+
const pts = [];
|
|
2108
|
+
while (i < to) {
|
|
2109
|
+
const d = resultData[i];
|
|
2110
|
+
const v = d?.rsi;
|
|
2111
|
+
if (v === null || v === void 0 || !compare(v)) break;
|
|
2112
|
+
pts.push({ x: getX(i), y: yAxis.convertToPixel(v) });
|
|
2113
|
+
i++;
|
|
2114
|
+
}
|
|
2115
|
+
if (pts.length === 0) continue;
|
|
2116
|
+
ctx.beginPath();
|
|
2117
|
+
ctx.moveTo(pts[0].x, yThreshold);
|
|
2118
|
+
for (const p of pts) ctx.lineTo(p.x, p.y);
|
|
2119
|
+
ctx.lineTo(pts[pts.length - 1].x, yThreshold);
|
|
2120
|
+
ctx.closePath();
|
|
2121
|
+
const gradY1 = yThreshold;
|
|
2122
|
+
const gradY2 = above ? Math.min(...pts.map((p) => p.y)) - 5 : Math.max(...pts.map((p) => p.y)) + 5;
|
|
2123
|
+
const grad = ctx.createLinearGradient(0, gradY1, 0, gradY2);
|
|
2124
|
+
grad.addColorStop(0, gradFrom);
|
|
2125
|
+
grad.addColorStop(1, gradTo);
|
|
2126
|
+
ctx.globalAlpha = 1;
|
|
2127
|
+
ctx.fillStyle = grad;
|
|
2128
|
+
ctx.fill();
|
|
2129
|
+
}
|
|
2130
|
+
};
|
|
2131
|
+
fillZone(
|
|
2132
|
+
y70,
|
|
2133
|
+
true,
|
|
2134
|
+
"rgba(239,83,80,0.0)",
|
|
2135
|
+
"rgba(239,83,80,0.35)"
|
|
2136
|
+
);
|
|
2137
|
+
fillZone(
|
|
2138
|
+
y30,
|
|
2139
|
+
false,
|
|
2140
|
+
"rgba(38,166,154,0.0)",
|
|
2141
|
+
"rgba(38,166,154,0.35)"
|
|
2142
|
+
);
|
|
2143
|
+
const drawDash = (y, color, alpha) => {
|
|
2144
|
+
ctx.beginPath();
|
|
2145
|
+
ctx.globalAlpha = alpha;
|
|
2146
|
+
ctx.setLineDash([5, 4]);
|
|
2147
|
+
ctx.strokeStyle = color;
|
|
2148
|
+
ctx.lineWidth = 1;
|
|
2149
|
+
ctx.moveTo(left, y);
|
|
2150
|
+
ctx.lineTo(right, y);
|
|
2151
|
+
ctx.stroke();
|
|
2152
|
+
};
|
|
2153
|
+
ctx.globalAlpha = 1;
|
|
2154
|
+
drawDash(y70, "#EF5350", 0.7);
|
|
2155
|
+
drawDash(y30, "#26A69A", 0.7);
|
|
2156
|
+
drawDash(y50, "#aaaaaa", 0.3);
|
|
2157
|
+
ctx.restore();
|
|
2158
|
+
return false;
|
|
2159
|
+
}
|
|
2160
|
+
};
|
|
2161
|
+
var rsiTv_default = rsiTv;
|
|
2162
|
+
|
|
2163
|
+
// src/indicators/stochastic.ts
|
|
2164
|
+
function rollingMinMax(data, period) {
|
|
2165
|
+
const min = [];
|
|
2166
|
+
const max = [];
|
|
2167
|
+
for (let i = 0; i < data.length; i++) {
|
|
2168
|
+
if (i < period - 1) {
|
|
2169
|
+
min.push(NaN);
|
|
2170
|
+
max.push(NaN);
|
|
2171
|
+
} else {
|
|
2172
|
+
let lo = data[i];
|
|
2173
|
+
let hi = data[i];
|
|
2174
|
+
for (let j = 1; j < period; j++) {
|
|
2175
|
+
if (data[i - j] < lo) lo = data[i - j];
|
|
2176
|
+
if (data[i - j] > hi) hi = data[i - j];
|
|
2177
|
+
}
|
|
2178
|
+
min.push(lo);
|
|
2179
|
+
max.push(hi);
|
|
2180
|
+
}
|
|
2181
|
+
}
|
|
2182
|
+
return { min, max };
|
|
2183
|
+
}
|
|
2184
|
+
function smaWithNaN(data, period) {
|
|
2185
|
+
const result = [];
|
|
2186
|
+
let sum = 0;
|
|
2187
|
+
let count = 0;
|
|
2188
|
+
let windowStart = 0;
|
|
2189
|
+
for (let i = 0; i < data.length; i++) {
|
|
2190
|
+
if (!isNaN(data[i])) {
|
|
2191
|
+
sum += data[i];
|
|
2192
|
+
count++;
|
|
2193
|
+
}
|
|
2194
|
+
if (i >= period) {
|
|
2195
|
+
if (!isNaN(data[windowStart])) {
|
|
2196
|
+
sum -= data[windowStart];
|
|
2197
|
+
count--;
|
|
2198
|
+
}
|
|
2199
|
+
windowStart++;
|
|
2200
|
+
}
|
|
2201
|
+
result.push(count === period ? sum / period : NaN);
|
|
2202
|
+
}
|
|
2203
|
+
return result;
|
|
2204
|
+
}
|
|
2205
|
+
var stochastic = {
|
|
2206
|
+
name: "Stochastic",
|
|
2207
|
+
shortName: "STOCH",
|
|
2208
|
+
calcParams: [14, 3, 3],
|
|
2209
|
+
figures: [
|
|
2210
|
+
{ key: "k", title: "%K: ", type: "line" },
|
|
2211
|
+
{ key: "d", title: "%D: ", type: "line" }
|
|
2212
|
+
],
|
|
2213
|
+
calc: (dataList, indicator) => {
|
|
2214
|
+
const [period, smoothK, smoothD] = indicator.calcParams;
|
|
2215
|
+
const highs = dataList.map((d) => d.high);
|
|
2216
|
+
const lows = dataList.map((d) => d.low);
|
|
2217
|
+
const closes = dataList.map((d) => d.close);
|
|
2218
|
+
const { min: lowestLow } = rollingMinMax(lows, period);
|
|
2219
|
+
const { max: highestHigh } = rollingMinMax(highs, period);
|
|
2220
|
+
const rawK = closes.map((c, i) => {
|
|
2221
|
+
const lo = lowestLow[i];
|
|
2222
|
+
const hi = highestHigh[i];
|
|
2223
|
+
if (isNaN(lo) || isNaN(hi) || hi === lo) return null;
|
|
2224
|
+
return (c - lo) / (hi - lo) * 100;
|
|
2225
|
+
});
|
|
2226
|
+
const validK = rawK.map((v) => v ?? NaN);
|
|
2227
|
+
const kSmoothed = smaWithNaN(validK, smoothK);
|
|
2228
|
+
const dLine = smaWithNaN(kSmoothed, smoothD);
|
|
2229
|
+
return kSmoothed.map((k, i) => ({
|
|
2230
|
+
k: isNaN(k) ? null : k,
|
|
2231
|
+
d: isNaN(dLine[i]) ? null : dLine[i]
|
|
2232
|
+
}));
|
|
2233
|
+
}
|
|
2234
|
+
};
|
|
2235
|
+
var stochastic_default = stochastic;
|
|
2236
|
+
|
|
2237
|
+
// src/indicators/superTrend.ts
|
|
2238
|
+
var superTrend = {
|
|
2239
|
+
name: "SuperTrend",
|
|
2240
|
+
shortName: "SuperTrend",
|
|
2241
|
+
calcParams: [10, 3],
|
|
2242
|
+
figures: [
|
|
2243
|
+
{ key: "up", title: "Up: ", type: "line" },
|
|
2244
|
+
{ key: "down", title: "Down: ", type: "line" }
|
|
2245
|
+
],
|
|
2246
|
+
calc: (dataList, indicator) => {
|
|
2247
|
+
const period = indicator.calcParams[0];
|
|
2248
|
+
const factor = indicator.calcParams[1];
|
|
2249
|
+
const highs = dataList.map((d) => d.high);
|
|
2250
|
+
const lows = dataList.map((d) => d.low);
|
|
2251
|
+
const closes = dataList.map((d) => d.close);
|
|
2252
|
+
const atr = TA_default.atr(highs, lows, closes, period);
|
|
2253
|
+
let trend = 1;
|
|
2254
|
+
let up = 0;
|
|
2255
|
+
let down = 0;
|
|
2256
|
+
return dataList.map((kLineData, index) => {
|
|
2257
|
+
const currentAtr = atr[index];
|
|
2258
|
+
if (currentAtr === null) return { up: null, down: null };
|
|
2259
|
+
const mid = (kLineData.high + kLineData.low) / 2;
|
|
2260
|
+
const basicUpper = mid + factor * currentAtr;
|
|
2261
|
+
const basicLower = mid - factor * currentAtr;
|
|
2262
|
+
if (index === 0 || atr[index - 1] === null) {
|
|
2263
|
+
up = basicUpper;
|
|
2264
|
+
down = basicLower;
|
|
2265
|
+
} else {
|
|
2266
|
+
const prevUp = up;
|
|
2267
|
+
const prevDown = down;
|
|
2268
|
+
const prevClose = dataList[index - 1].close;
|
|
2269
|
+
up = basicUpper < prevUp || prevClose > prevUp ? basicUpper : prevUp;
|
|
2270
|
+
down = basicLower > prevDown || prevClose < prevDown ? basicLower : prevDown;
|
|
2271
|
+
}
|
|
2272
|
+
if (trend === 1 && kLineData.close < down) {
|
|
2273
|
+
trend = -1;
|
|
2274
|
+
} else if (trend === -1 && kLineData.close > up) {
|
|
2275
|
+
trend = 1;
|
|
2276
|
+
}
|
|
2277
|
+
return {
|
|
2278
|
+
up: trend === 1 ? down : null,
|
|
2279
|
+
down: trend === -1 ? up : null
|
|
2280
|
+
};
|
|
2281
|
+
});
|
|
2282
|
+
}
|
|
2283
|
+
};
|
|
2284
|
+
var superTrend_default = superTrend;
|
|
2285
|
+
|
|
2286
|
+
// src/indicators/vwap.ts
|
|
2287
|
+
var vwap = {
|
|
2288
|
+
name: "VWAP",
|
|
2289
|
+
shortName: "VWAP",
|
|
2290
|
+
calcParams: [],
|
|
2291
|
+
figures: [{ key: "vwap", title: "VWAP: ", type: "line" }],
|
|
2292
|
+
calc: (dataList) => {
|
|
2293
|
+
let cumulativeVolume = 0;
|
|
2294
|
+
let cumulativePriceVolume = 0;
|
|
2295
|
+
let lastDate = "";
|
|
2296
|
+
return dataList.map((kLineData) => {
|
|
2297
|
+
const date = new Date(kLineData.timestamp).toLocaleDateString();
|
|
2298
|
+
if (date !== lastDate) {
|
|
2299
|
+
cumulativeVolume = 0;
|
|
2300
|
+
cumulativePriceVolume = 0;
|
|
2301
|
+
lastDate = date;
|
|
2302
|
+
}
|
|
2303
|
+
const price = (kLineData.high + kLineData.low + kLineData.close) / 3;
|
|
2304
|
+
cumulativeVolume += kLineData.volume ?? 0;
|
|
2305
|
+
cumulativePriceVolume += price * (kLineData.volume ?? 0);
|
|
2306
|
+
return {
|
|
2307
|
+
vwap: cumulativePriceVolume / (cumulativeVolume || 1)
|
|
2308
|
+
};
|
|
2309
|
+
});
|
|
2310
|
+
}
|
|
2311
|
+
};
|
|
2312
|
+
var vwap_default = vwap;
|
|
2313
|
+
|
|
2314
|
+
// src/extensions/overlays/orderLine.ts
|
|
2315
|
+
var DEFAULT_FONT_FAMILY = "Helvetica Neue, Arial, sans-serif";
|
|
2316
|
+
var orderLine = {
|
|
2317
|
+
name: "orderLine",
|
|
2318
|
+
totalStep: 2,
|
|
2319
|
+
needDefaultPointFigure: false,
|
|
2320
|
+
needDefaultXAxisFigure: false,
|
|
2321
|
+
needDefaultYAxisFigure: false,
|
|
2322
|
+
createYAxisFigures: ({ chart, overlay, coordinates }) => {
|
|
2323
|
+
if (coordinates.length < 1) return [];
|
|
2324
|
+
const y = coordinates[0].y;
|
|
2325
|
+
const price = overlay.points[0]?.value;
|
|
2326
|
+
if (price == null) return [];
|
|
2327
|
+
const d = overlay.extendData ?? {};
|
|
2328
|
+
const color = d.color ?? "rgba(255, 165, 0, 0.85)";
|
|
2329
|
+
const m = d.mark;
|
|
2330
|
+
const precision = chart.getSymbol()?.pricePrecision ?? 2;
|
|
2331
|
+
return [
|
|
2332
|
+
{
|
|
2333
|
+
type: "text",
|
|
2334
|
+
attrs: {
|
|
2335
|
+
x: 0,
|
|
2336
|
+
y,
|
|
2337
|
+
text: price.toFixed(precision),
|
|
2338
|
+
align: "left",
|
|
2339
|
+
baseline: "middle"
|
|
2340
|
+
},
|
|
2341
|
+
styles: {
|
|
2342
|
+
color: m?.color ?? "#ffffff",
|
|
2343
|
+
size: m?.font?.size ?? 11,
|
|
2344
|
+
family: m?.font?.family ?? DEFAULT_FONT_FAMILY,
|
|
2345
|
+
weight: m?.font?.weight ?? "bold",
|
|
2346
|
+
paddingLeft: m?.padding?.x ?? 4,
|
|
2347
|
+
paddingRight: m?.padding?.x ?? 4,
|
|
2348
|
+
paddingTop: m?.padding?.y ?? 4,
|
|
2349
|
+
paddingBottom: m?.padding?.y ?? 4,
|
|
2350
|
+
backgroundColor: m?.bg ?? color,
|
|
2351
|
+
borderRadius: m?.borderRadius ?? 2
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
];
|
|
2355
|
+
},
|
|
2356
|
+
createPointFigures: ({ coordinates, bounding, overlay }) => {
|
|
2357
|
+
if (coordinates.length < 1) return [];
|
|
2358
|
+
const y = coordinates[0].y;
|
|
2359
|
+
const d = overlay.extendData ?? {};
|
|
2360
|
+
const color = d.color ?? "rgba(255, 165, 0, 0.85)";
|
|
2361
|
+
const ln = d.line;
|
|
2362
|
+
const figures = [
|
|
2363
|
+
{
|
|
2364
|
+
type: "line",
|
|
2365
|
+
attrs: {
|
|
2366
|
+
coordinates: [
|
|
2367
|
+
{ x: 0, y },
|
|
2368
|
+
{ x: bounding.width, y }
|
|
2369
|
+
]
|
|
2370
|
+
},
|
|
2371
|
+
styles: {
|
|
2372
|
+
style: ln?.style ?? "dashed",
|
|
2373
|
+
color,
|
|
2374
|
+
size: ln?.width ?? 1,
|
|
2375
|
+
dashedValue: ln?.dashedValue ?? [4, 2]
|
|
2376
|
+
}
|
|
2377
|
+
}
|
|
2378
|
+
];
|
|
2379
|
+
if (d.text) {
|
|
2380
|
+
const lb = d.label;
|
|
2381
|
+
figures.push({
|
|
2382
|
+
type: "text",
|
|
2383
|
+
ignoreEvent: true,
|
|
2384
|
+
attrs: {
|
|
2385
|
+
x: lb?.offset?.x ?? 8,
|
|
2386
|
+
y: y - (lb?.offset?.y ?? 3),
|
|
2387
|
+
text: d.text,
|
|
2388
|
+
align: "left",
|
|
2389
|
+
baseline: "bottom"
|
|
2390
|
+
},
|
|
2391
|
+
styles: {
|
|
2392
|
+
color: lb?.color ?? color,
|
|
2393
|
+
size: lb?.font?.size ?? 11,
|
|
2394
|
+
family: lb?.font?.family ?? DEFAULT_FONT_FAMILY,
|
|
2395
|
+
weight: lb?.font?.weight ?? "normal",
|
|
2396
|
+
paddingLeft: lb?.padding?.x ?? 0,
|
|
2397
|
+
paddingRight: lb?.padding?.x ?? 0,
|
|
2398
|
+
paddingTop: lb?.padding?.y ?? 0,
|
|
2399
|
+
paddingBottom: lb?.padding?.y ?? 0,
|
|
2400
|
+
backgroundColor: lb?.bg ?? "transparent",
|
|
2401
|
+
borderRadius: lb?.borderRadius ?? 0
|
|
2402
|
+
}
|
|
2403
|
+
});
|
|
2404
|
+
}
|
|
2405
|
+
return figures;
|
|
2406
|
+
},
|
|
2407
|
+
performEventPressedMove: ({ points, performPoint }) => {
|
|
2408
|
+
points[0].value = performPoint.value;
|
|
2409
|
+
}
|
|
2410
|
+
};
|
|
2411
|
+
var orderLine_default = orderLine;
|
|
2412
|
+
|
|
2413
|
+
// src/extensions/index.ts
|
|
2414
|
+
var overlays = Object.values(overlays_exports);
|
|
2415
|
+
var indicators = Object.values(indicators_exports);
|
|
2416
|
+
var registered = false;
|
|
2417
|
+
function registerExtensions() {
|
|
2418
|
+
if (registered) return;
|
|
2419
|
+
overlays.forEach((overlay) => reactKlinecharts.registerOverlay(overlay));
|
|
2420
|
+
indicators.forEach((indicator) => reactKlinecharts.registerIndicator(indicator));
|
|
2421
|
+
registered = true;
|
|
2422
|
+
}
|
|
2423
|
+
|
|
2424
|
+
exports.TA_default = TA_default;
|
|
2425
|
+
exports.abcd_default = abcd_default;
|
|
2426
|
+
exports.anyWaves_default = anyWaves_default;
|
|
2427
|
+
exports.arrow_default = arrow_default;
|
|
2428
|
+
exports.bollTv_default = bollTv_default;
|
|
2429
|
+
exports.brush_default = brush_default;
|
|
2430
|
+
exports.cci_default = cci_default;
|
|
2431
|
+
exports.circle_default = circle_default;
|
|
2432
|
+
exports.eightWaves_default = eightWaves_default;
|
|
2433
|
+
exports.elliottWave_default = elliottWave_default;
|
|
2434
|
+
exports.fibRetracement_default = fibRetracement_default;
|
|
2435
|
+
exports.fibonacciCircle_default = fibonacciCircle_default;
|
|
2436
|
+
exports.fibonacciExtension_default = fibonacciExtension_default;
|
|
2437
|
+
exports.fibonacciSegment_default = fibonacciSegment_default;
|
|
2438
|
+
exports.fibonacciSpeedResistanceFan_default = fibonacciSpeedResistanceFan_default;
|
|
2439
|
+
exports.fibonacciSpiral_default = fibonacciSpiral_default;
|
|
2440
|
+
exports.fiveWaves_default = fiveWaves_default;
|
|
2441
|
+
exports.gannBox_default = gannBox_default;
|
|
2442
|
+
exports.gannFan_default = gannFan_default;
|
|
2443
|
+
exports.hma_default = hma_default;
|
|
2444
|
+
exports.ichimoku_default = ichimoku_default;
|
|
2445
|
+
exports.indicators = indicators;
|
|
2446
|
+
exports.longPosition_default = longPosition_default;
|
|
2447
|
+
exports.maRibbon_default = maRibbon_default;
|
|
2448
|
+
exports.macdTv_default = macdTv_default;
|
|
2449
|
+
exports.measure_default = measure_default;
|
|
2450
|
+
exports.orderLine_default = orderLine_default;
|
|
2451
|
+
exports.overlays = overlays;
|
|
2452
|
+
exports.parallelChannel_default = parallelChannel_default;
|
|
2453
|
+
exports.parallelogram_default = parallelogram_default;
|
|
2454
|
+
exports.pivotPoints_default = pivotPoints_default;
|
|
2455
|
+
exports.ray_default = ray_default;
|
|
2456
|
+
exports.rect_default = rect_default;
|
|
2457
|
+
exports.registerExtensions = registerExtensions;
|
|
2458
|
+
exports.rsiTv_default = rsiTv_default;
|
|
2459
|
+
exports.shortPosition_default = shortPosition_default;
|
|
2460
|
+
exports.stochastic_default = stochastic_default;
|
|
2461
|
+
exports.superTrend_default = superTrend_default;
|
|
2462
|
+
exports.threeWaves_default = threeWaves_default;
|
|
2463
|
+
exports.triangle_default = triangle_default;
|
|
2464
|
+
exports.vwap_default = vwap_default;
|
|
2465
|
+
exports.xabcd_default = xabcd_default;
|
|
2466
|
+
//# sourceMappingURL=chunk-47JXSAIT.cjs.map
|
|
2467
|
+
//# sourceMappingURL=chunk-47JXSAIT.cjs.map
|