Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To configure the TradingView charting library chart to update automatically, follow these steps:

  1. Set the symbol to update automatically: Use the setSymbol function to set the symbol for the chart to update automatically. For example:
var chart = new TradingView.widget({
  // ...
  symbol: "AAPL",
  // ...
});

chart.onChartReady(function() {
  chart.setSymbol("AAPL", function() {
    console.log("Symbol set");
  });
});
  1. Set the interval to update automatically: Use the setResolution function to set the interval for the chart to update automatically. For example:
var chart = new TradingView.widget({
  // ...
  symbol: "AAPL",
  interval: "D",
  // ...
});

chart.onChartReady(function() {
  chart.setResolution("D", function() {
    console.log("Interval set");
  });
});
  1. Enable real-time updates: Use the subscribeBars function to enable real-time updates for the chart. For example:
var chart = new TradingView.widget({
  // ...
  symbol: "AAPL",
  interval: "D",
  // ...
});

chart.onChartReady(function() {
  chart.subscribeBars(function() {
    console.log("Real-time updates enabled");
  });
});
  1. Update the chart data: Use the update method to update the chart data. For example:
chart.onChartReady(function() {
  chart.setSymbol("AAPL", function() {
    chart.setResolution("D", function() {
      chart.subscribeBars(function() {
        chart.update({
          time: new Date(),
          close: 100.00,
          open: 99.50,
          high: 101.00,
          low: 98.50,
          volume: 1000000
        });
      });
    });
  });
});

By following these steps, you can configure the TradingView charting library chart to update automatically.