@mathieuc/tradingview 3.3.2 → 3.3.3
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/package.json +1 -1
- package/src/chart/study.js +68 -51
package/package.json
CHANGED
package/src/chart/study.js
CHANGED
|
@@ -32,6 +32,27 @@ function getInputs(options) {
|
|
|
32
32
|
return options.options;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
const parseTrades = (trades) => trades.reverse().map((t) => ({
|
|
36
|
+
entry: {
|
|
37
|
+
name: t.e.c,
|
|
38
|
+
type: (t.e.tp[0] === 's' ? 'short' : 'long'),
|
|
39
|
+
value: t.e.p,
|
|
40
|
+
time: t.e.tm,
|
|
41
|
+
},
|
|
42
|
+
exit: {
|
|
43
|
+
name: t.x.c,
|
|
44
|
+
value: t.x.p,
|
|
45
|
+
time: t.x.tm,
|
|
46
|
+
},
|
|
47
|
+
quantity: t.q,
|
|
48
|
+
profit: t.tp,
|
|
49
|
+
cumulative: t.cp,
|
|
50
|
+
runup: t.rn,
|
|
51
|
+
drawdown: t.dd,
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
// const historyParser = (history) => history.reverse().map((h) => ({
|
|
55
|
+
|
|
35
56
|
/**
|
|
36
57
|
* @typedef {Object} TradeReport Trade report
|
|
37
58
|
|
|
@@ -86,9 +107,19 @@ function getInputs(options) {
|
|
|
86
107
|
* @prop {number} totalTrades Total trades
|
|
87
108
|
*/
|
|
88
109
|
|
|
110
|
+
/**
|
|
111
|
+
* @typedef {Object} FromTo
|
|
112
|
+
* @prop {number} from From timestamp
|
|
113
|
+
* @prop {number} to To timestamp
|
|
114
|
+
*/
|
|
115
|
+
|
|
89
116
|
/**
|
|
90
117
|
* @typedef {Object} StrategyReport
|
|
91
118
|
* @prop {'EUR' | 'USD' | 'JPY' | '' | 'CHF'} [currency] Selected currency
|
|
119
|
+
* @prop {Object} [settings] Backtester settings
|
|
120
|
+
* @prop {Object} [settings.dateRange] Backtester date range
|
|
121
|
+
* @prop {FromTo} [settings.dateRange.backtest] Date range for backtest
|
|
122
|
+
* @prop {FromTo} [settings.dateRange.trade] Date range for trade
|
|
92
123
|
* @prop {TradeReport[]} trades Trade list starting by the last
|
|
93
124
|
* @prop {Object} history History Chart value
|
|
94
125
|
* @prop {number[]} [history.buyHold] Buy hold values
|
|
@@ -275,60 +306,45 @@ module.exports = (chartSession) => class ChartStudy {
|
|
|
275
306
|
changes.push('graphic');
|
|
276
307
|
}
|
|
277
308
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
309
|
+
const updateStrategyReport = (report) => {
|
|
310
|
+
if (report.currency) {
|
|
311
|
+
this.#strategyReport.currency = report.currency;
|
|
312
|
+
changes.push('report.currency');
|
|
313
|
+
}
|
|
282
314
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
315
|
+
if (report.settings) {
|
|
316
|
+
this.#strategyReport.settings = report.settings;
|
|
317
|
+
changes.push('report.settings');
|
|
318
|
+
}
|
|
287
319
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
320
|
+
if (report.performance) {
|
|
321
|
+
this.#strategyReport.performance = report.performance;
|
|
322
|
+
changes.push('report.perf');
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
if (report.trades) {
|
|
326
|
+
this.#strategyReport.trades = parseTrades(report.trades);
|
|
327
|
+
changes.push('report.trades');
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (report.equity) {
|
|
331
|
+
this.#strategyReport.history = {
|
|
332
|
+
buyHold: report.buyHold,
|
|
333
|
+
buyHoldPercent: report.buyHoldPercent,
|
|
334
|
+
drawDown: report.drawDown,
|
|
335
|
+
drawDownPercent: report.drawDownPercent,
|
|
336
|
+
equity: report.equity,
|
|
337
|
+
equityPercent: report.equityPercent,
|
|
338
|
+
};
|
|
339
|
+
changes.push('report.history');
|
|
340
|
+
}
|
|
341
|
+
};
|
|
292
342
|
|
|
293
343
|
if (parsed.dataCompressed) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
this.#strategyReport = {
|
|
297
|
-
currency: parsedC.report.currency,
|
|
298
|
-
|
|
299
|
-
trades: parsedC.report.trades.reverse().map((t) => ({
|
|
300
|
-
entry: {
|
|
301
|
-
name: t.e.c,
|
|
302
|
-
type: (t.e.tp[0] === 's' ? 'short' : 'long'),
|
|
303
|
-
value: t.e.p,
|
|
304
|
-
time: t.e.tm,
|
|
305
|
-
},
|
|
306
|
-
exit: {
|
|
307
|
-
name: t.x.c,
|
|
308
|
-
value: t.x.p,
|
|
309
|
-
time: t.x.tm,
|
|
310
|
-
},
|
|
311
|
-
quantity: t.q,
|
|
312
|
-
profit: t.tp,
|
|
313
|
-
cumulative: t.cp,
|
|
314
|
-
runup: t.rn,
|
|
315
|
-
drawdown: t.dd,
|
|
316
|
-
})),
|
|
317
|
-
|
|
318
|
-
history: {
|
|
319
|
-
buyHold: parsedC.report.buyHold,
|
|
320
|
-
buyHoldPercent: parsedC.report.buyHoldPercent,
|
|
321
|
-
drawDown: parsedC.report.drawDown,
|
|
322
|
-
drawDownPercent: parsedC.report.drawDownPercent,
|
|
323
|
-
equity: parsedC.report.equity,
|
|
324
|
-
equityPercent: parsedC.report.equityPercent,
|
|
325
|
-
},
|
|
326
|
-
|
|
327
|
-
performance: parsedC.report.performance,
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
changes.push('fullReport');
|
|
344
|
+
updateStrategyReport((await parseCompressed(parsed.dataCompressed)).report);
|
|
331
345
|
}
|
|
346
|
+
|
|
347
|
+
if (parsed.data && parsed.data.report) updateStrategyReport(parsed.data.report);
|
|
332
348
|
}
|
|
333
349
|
|
|
334
350
|
if (data.ns.indexes && typeof data.ns.indexes === 'object') {
|
|
@@ -383,8 +399,9 @@ module.exports = (chartSession) => class ChartStudy {
|
|
|
383
399
|
}
|
|
384
400
|
|
|
385
401
|
/**
|
|
386
|
-
* @typedef {
|
|
387
|
-
*
|
|
402
|
+
* @typedef {'plots' | 'report.currency'
|
|
403
|
+
* | 'report.settings' | 'report.perf'
|
|
404
|
+
* | 'report.trades' | 'report.history'
|
|
388
405
|
* } UpdateChangeType
|
|
389
406
|
*/
|
|
390
407
|
|