Search code examples
tradingview-api

How to add multiple time resolutions (like 1D, 1W, 1M, All) to TradingView charting library


how can I add wanted time resolutions to a TradingView charting library chart like in the example below (1D, 5D, 1M,3M, ...) and trigger events to update data from custom API? https://www.tradingview.com/chart/03M7zkuw/?symbol=NASDAQ%3AAAPL

I cannot find any documentation, besides supported_resolutions in resolveSymbol function. And even with this setting set to ['1', '5', '15', '30', '60', '1D', '1W', '1M'], I still get only 5y and 1y option, like the setting is not doing anything.

What am I doing wrong?

My code in resolveSymbol javascript function:

var symbolInfo = {
            ticker: charts.chartContainer.data("ticker"),
            name: charts.chartContainer.data("ticker"),
            description: charts.chartContainer.data("ticker"),
            type: "",
            session: '24x7',
            timezone: 'Etc/UTC',
            exchange: "",
            minmov: 1,
            pricescale: 100,
            has_intraday: false,
            has_no_volume: true,
            has_weekly_and_monthly: false,
            supports_group_request: true,
            supported_resolutions: charts.configurationData.supported_resolutions,
            volume_precision: 2,
            data_status: 'streaming',
          };

          setTimeout(function() {
            onSymbolResolvedCallback(symbolInfo);
          });

Thank you!


Solution

  • So for future problems, the answer is to add time_frames to configurationData:

    time_frames: [
      { text: "1y", resolution: "1D", description: "1 Year" },
      { text: "3m", resolution: "1D", description: "3 Months"},
      { text: "1m", resolution: "1D", description: "1 Month" },
      { text: "1w", resolution: "60", description: "1 Week" },
      { text: "1d", resolution: "5", description: "1 Day" },
      { text: "1000y", resolution: "1D", description: "All", title: "All" }
    ]