-
-
Notifications
You must be signed in to change notification settings - Fork 977
Expand file tree
/
Copy pathbuiltin-indicator.js
More file actions
22 lines (19 loc) · 932 Bytes
/
Copy pathbuiltin-indicator.js
File metadata and controls
22 lines (19 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Built-in studies such as the fixed-range volume profile.
// Run: npm run build && node examples/builtin-indicator.js
import { BuiltInIndicator, TradingViewClient } from '@mathieuc/tradingview';
const profile = new BuiltInIndicator('VbPFixed@tv-basicstudies-241!');
profile.setOption('first_bar_time', Date.now() - 10 ** 8);
const client = new TradingViewClient();
const chart = client.createChart();
chart.setMarket('BINANCE:BTCEUR', { timeframe: '60', count: 1 });
const study = chart.createStudy(profile);
study.on('update', async () => {
const rows = study.graphics.horizHists
.filter((h) => h.lastBarTime === 0) // Profile that ends on the latest bar
.sort((a, b) => b.priceHigh - a.priceHigh);
if (!rows.length) return;
for (const h of rows) {
console.log(`~ ${Math.round((h.priceHigh + h.priceLow) / 2)} € : ${'_'.repeat(h.rate[0] / 3)}${'_'.repeat(h.rate[1] / 3)}`);
}
await client.close();
});