Skip to content

πŸ“ˆ Get real-time stocks from TradingView

Add CustomChartType example

Mathieu Colmon768c8e91b966
diff --git a/examples/CustomChartType.js b/examples/CustomChartType.js
new file mode 100644
index 0000000..ee292b7
--- /dev/null
+++ b/examples/CustomChartType.js
@@ -0,0 +1,121 @@
+const TradingView = require('../main');
+
+/*
+ This example creates charts of custom
+ types such as 'HeikinAshi', 'Renko',
+ 'LineBreak', 'Kagi', 'PointAndFigure',
+ and 'Range' with default settings
+*/
+
+const client = new TradingView.Client({
+ /* Token is only required if you want to use intraday
+ timeframes (if you have a paid TradingView account) */
+ // token: 'YOUR_SESSION_TOKEN',
+});
+
+const chart = new client.Session.Chart();
+
+chart.onError((...err) => {
+ console.log('Chart error:', ...err);
+});
+
+chart.onUpdate(() => {
+ if (!chart.periods[0]) return;
+ console.log('Last period', chart.periods[0]);
+});
+
+/* (0s) Heikin Ashi chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: HeikinAshi');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'HeikinAshi',
+ timeframe: 'D',
+ });
+}, 0);
+
+/* (5s) Renko chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: Renko');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'Renko',
+ timeframe: 'D',
+ inputs: {
+ source: 'close',
+ sources: 'Close',
+ boxSize: 3,
+ style: 'ATR',
+ atrLength: 14,
+ wicks: true,
+ },
+ });
+}, 5000);
+
+/* (10s) Line Break chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: LineBreak');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'LineBreak',
+ timeframe: 'D',
+ inputs: {
+ source: 'close',
+ lb: 3,
+ },
+ });
+}, 10000);
+
+/* (15s) Kagi chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: Kagi');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'Kagi',
+ timeframe: 'D',
+ inputs: {
+ source: 'close',
+ style: 'ATR',
+ atrLength: 14,
+ reversalAmount: 1,
+ },
+ });
+}, 15000);
+
+/* (20s) Point & Figure chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: PointAndFigure');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'PointAndFigure',
+ timeframe: 'D',
+ inputs: {
+ sources: 'Close',
+ reversalAmount: 3,
+ boxSize: 1,
+ style: 'ATR',
+ atrLength: 14,
+ oneStepBackBuilding: false,
+ },
+ });
+}, 20000);
+
+/* (25s) Range chart */
+setTimeout(() => {
+ console.log('\nSetting chart type to: Range');
+
+ chart.setMarket('BINANCE:BTCEUR', {
+ type: 'Range',
+ timeframe: 'D',
+ inputs: {
+ range: 1,
+ phantomBars: false,
+ },
+ });
+}, 25000);
+
+/* (30s) Delete chart, close client */
+setTimeout(() => {
+ console.log('\nClosing client...');
+ client.end();
+}, 30000);