create tradingview screen in typescript in javascript

To create a TradingView screen in TypeScript, you'll need to do the following steps:

  1. Create a new TypeScript file and import the necessary libraries:
index.ts
import ChartingLibraryWidget from './charting_library/charting_library.min';
import Datafeed from './charting_library/datafeed-api';
133 chars
3 lines
  1. Define your TradingView configuration options as an object:
index.ts
const widgetOptions = {
  debug: false,
  symbol: 'AAPL',
  datafeed: Datafeed,
  interval: 'D',
  container_id: 'tv_chart_container',
  library_path: './charting_library/',
  locale: 'en',
  drawings_access: { type: 'black', tools: [{ name: 'Regression Trend' }] },
  disabled_features: ['use_localstorage_for_settings'],
  enabled_features: ['study_templates'],
  charts_storage_api_version: '1.1',
  client_id: 'tradingview.com',
  user_id: 'public_user_id',
  fullscreen: false,
  autosize: true,
};
504 chars
18 lines
  1. Create the TradingView object using the ChartingLibraryWidget constructor and pass in your configuration options:
index.ts
const tvWidget = new ChartingLibraryWidget(widgetOptions);
59 chars
2 lines
  1. Initialize the TradingView widget once your page is loaded:
index.ts
function createWidget() {
  tvWidget
    .onChartReady(() => {
      console.log('Chart has loaded!');
    })
    .onScreenshotReady(() => {
      console.log('Screenshot is ready!');
    })
    .createChart();
}

window.addEventListener('load', createWidget);
261 chars
13 lines

With these simple steps, you can create a TradingView screen in TypeScript! Don't forget to customize your configuration options to fit your needs.

gistlibby LogSnag