MCPcopy Index your code
hub / github.com/Mathieu2301/TradingView-API / step

Function step

examples/ReplayMode.js:49–78  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

47let interval = NaN;
48
49async function step() {
50 const period = { ...chart.periods[0] };
51
52 const times = Object.keys(periods);
53 const intrval = times[times.length - 1] - times[times.length - 2];
54 if (Number.isNaN(interval) && times.length >= 2) interval = intrval;
55
56 if (!Number.isNaN(interval) && interval !== intrval) {
57 throw new Error(`Wrong interval: ${intrval} (should be ${interval})`);
58 }
59
60 indicators.forEach(([n, i]) => {
61 const plots = { ...i.periods[0] };
62 delete plots.$time;
63 period[n] = { plots };
64
65 Object.keys(i.graphic).forEach((g) => {
66 if (!i.graphic[g].length) return;
67 if (!period[n].graphics) period[n].graphics = {};
68 period[n].graphics[g] = i.graphic[g];
69 });
70 });
71
72 periods[period.time] = period;
73
74 console.log('Next ->', period.time, times.length);
75
76 await chart.replayStep(1);
77 step();
78}
79
80chart.onReplayEnd(async () => {
81 await client.end();

Callers 1

addIndicatorFunction · 0.70

Calls 1

replayStepMethod · 0.80

Tested by

no test coverage detected