tradingview custom data feed

TradingView Custom Data Feed

Many traders use TradingView as their preferred platform for technical analysis and charting. One of the key features that TradingView offers is the ability to use custom data feeds, which can be very useful for traders who want to analyze specific data sets or markets that are not available on TradingView's default feed.

What is a Custom Data Feed?

A custom data feed is simply a way to connect TradingView with an external data source. This can be done using a variety of methods, such as an API, a CSV file, or even by manually entering data into TradingView. The custom data is then displayed on TradingView's charts, allowing traders to analyze the data in the same way they would with any other asset.

How to Set Up a Custom Data Feed on TradingView

The process for setting up a custom data feed on TradingView depends on the specific method you are using to connect to your data source. Here are a few examples:

API Connection

If your data source has an API, you can use TradingView's built-in API connector to connect to the data. Here is an example of how to set up an API connection:


// Define the custom data source
var myDataSource = new DatafeedBase({
  // Set up the connection details
  server: "mydatasource.com",
  protocol: "https",
  // Set up the credentials if needed
  username: "myusername",
  password: "mypassword",
  // Set up the supported resolutions
  supported_resolutions: ["1", "5", "15", "30", "60", "D", "W", "M"],
  // Set up the symbol search function
  searchSymbols: function (userInput, exchange, symbolType, onResultReadyCallback) {
    // Call the API to get the available symbols
    myAPI.getAvailableSymbols(userInput, exchange, symbolType)
      .then(function (symbols) {
        // Format the symbols in the TradingView format
        var formattedSymbols = [];
        symbols.forEach(function (symbol) {
          formattedSymbols.push({
            symbol: symbol.symbol,
            full_name: symbol.name,
            description: symbol.description,
            exchange: symbol.exchange,
            type: symbol.type,
          });
        });
        // Return the formatted symbols to TradingView
        onResultReadyCallback(formattedSymbols);
      });
  },
  // Set up the history fetching function
  getBars: function (symbolInfo, resolution, from, to, onHistoryCallback, onErrorCallback) {
    // Call the API to get the historical data
    myAPI.getHistoricalData(symbolInfo, resolution, from, to)
      .then(function (data) {
        // Format the data in the TradingView format
        var formattedData = [];
        data.forEach(function (bar) {
          formattedData.push({
            time: bar.time,
            open: bar.open,
            high: bar.high,
            low: bar.low,
            close: bar.close,
            volume: bar.volume,
          });
        });
        // Return the formatted data to TradingView
        onHistoryCallback(formattedData);
      });
  },
});

CSV File

If your data source is a CSV file, you can use TradingView's CSV import feature to connect to the data. Here is an example of how to set up a CSV connection:

  1. Save your data as a CSV file. The first row should contain the column headers.
  2. Upload the CSV file to a web server or file sharing service that supports direct linking to the file.
  3. In TradingView, click "Import" in the top menu bar.
  4. Select "CSV" as the data source type.
  5. Enter the direct link to the CSV file.
  6. Set the data format options, such as the time zone and date format.
  7. Click "Import" to import the data into TradingView.

Conclusion

Custom data feeds can be a powerful tool for traders who want to analyze specific data sets or markets that are not available on TradingView's default feed. Whether you are connecting to an API, a CSV file, or manually entering data, TradingView makes it easy to set up a custom data feed and start analyzing your data in real-time.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe