-
-
Notifications
You must be signed in to change notification settings - Fork 680
Expand file tree
/
Copy path11. DeepBacktest.js
More file actions
53 lines (43 loc) · 1.42 KB
/
11. DeepBacktest.js
File metadata and controls
53 lines (43 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const TradingView = require('../main');
const wait = (ms) => new Promise((cb) => { setTimeout(cb, ms); });
module.exports = async (log, success, warn, err, cb) => {
if (!process.env.SESSION || !process.env.SIGNATURE) {
warn('No sessionid/signature was provided');
cb();
return;
}
log('Creating logged history client');
const client = new TradingView.Client({
// requires a Premium plan
token: process.env.SESSION,
signature: process.env.SIGNATURE,
// needs a new server type
server: 'history-data',
});
client.onError((...error) => {
err('Client error', error);
});
const history = new client.Session.History();
history.onError((...error) => {
err('History error', error);
history.delete();
client.end();
cb();
});
await wait(1000);
log('Loading built-in strategy....');
const indicator = await TradingView.getIndicator('STD;MACD%1Strategy');
const from = Math.floor(new Date(2010, 1, 1) / 1000);
const to = Math.floor(Date.now() / 1000);
log('Running deep backtest....');
history.requestHistoryData('AMEX:SPY', indicator, { timeframe: '5', from, to });
history.onHistoryLoaded(async () => {
success('Deep backtest traded from', new Date(history.strategyReport.settings.dateRange.trade.from));
log('Closing client...');
history.delete();
await client.end();
success('Client closed');
cb();
});
log('Strategy loaded !');
};