FAQ – Using 3rd Party Data in TradingView

TradingView has a really nice database of datasets: market data, fundamentals, etc. But sometimes when developing indicators or strategies you want to use a dataset that is not available within TradingView. Question I very ofter receive: “Can I use 3rd party data in TradingView ?”

The quick answer is “no”, but there is 1 exception and 1 trick which might help you to use 3rd party data to some extent.

The exception is that you can use data from Quandl. Quandl is a really great bank of datasets. You can find there quite a lot of data you might need in your analysis. So 1st thing you have to do is to search for data in Quandl.

If you found a dataset you want to use and it’s free (this won’t work for premium subscriptions) you can easily load this dataset to TradingView. Copy the Quandl Code in the top right corner:

And paste it to TradingView symbol search in format “QUANDL:your_quandl_code”, for example: “QUANDL:CHRIS/CME_CSC1”. Then press enter and you’ll see data immediately displayed on your chart.

You can use the same symbol format to get data from Quandl inside your PineScript code:

data = security("QUANDL:CHRIS/CME_CSC1", 'D', close)

But what if you can find the dataset you need on Quandl or you have your own dataset you want to load to TradingView? If your data is in the low timeframe, for example monthly or you needed it for a limited period of time in total not more than a few hundred data points you can try to encode your data inside PineScript.

Here is an example of how you can do that. In this script, I calculate the S&P market capitalization. To do that you need to multiply the S&P Index to S&P divider. Unfortunately, S&P divider is not available in TradingVIew or Quand, so I have to add it manually. Divider changes every quarter so it’s not a problem for me to simulate a few years of data like that. Here is the code for it:

study("3rd-party data - S&P Market Cap")

data = float(na)

data := time >= timestamp(2019, 03, 30, 00, 00) ? 8332.84 : data
data := time >= timestamp(2019, 06, 30, 00, 00) ? 8302.34 : data
data := time >= timestamp(2019, 09, 30, 00, 00) ? 8300.00 : data
data := time >= timestamp(2019, 12, 31, 00, 00) ? 8282.73 : data
data := time >= timestamp(2020, 03, 31, 00, 00) ? 8289.27 : data
data := time >= timestamp(2020, 06, 30, 00, 00) ? 8269.11 : data

plot(data * close / pow(10, 6), title = "S&P Market Cap")

As you can see I create the “data” variable as a “Not Available” number and next update it based on the current time. This way you can create variables with custom data. Next, I use this variable in computations without any issues.

Here is how S&P Market cap looks:

Problem is that if you want to include a big chunk of data in your code it’s very boring and time-consuming to create this kind of code manually. Also, It’s quite easy to make a mistake and very hard to spot it afterward.

As a solution to this, you can write a small script in another programming language which will generate a PineScript code for you. Here is an example of such a script in the programming language called R, you can use Python or any other programming languages easily for that as well.


data = tibble(
  date  = seq(as.Date('2000-01-01'), Sys.Date(), '1 month'), 
  value = round(rnorm(length(date)), 3)

for (i in 1:nrow(data)){
    cat(str_c('data := time >= timestamp(', year(data$date[i]), ', ', month(data$date[i]), ', ', day(data$date[i]), ', 00, 00) ? ', data$value[i] , ' : data\n'))

In this script I generate a random monthly data frame with date and value:

After that, I go with a loop through all rows and generate a line of PineScript for all the dates/values. Script will output lines like these:

data := time >= timestamp(2000, 1, 1, 00, 00) ? -0.155 : data
data := time >= timestamp(2000, 2, 1, 00, 00) ? 0.193 : data
data := time >= timestamp(2000, 3, 1, 00, 00) ? -0.346 : data
data := time >= timestamp(2000, 4, 1, 00, 00) ? -0.104 : data
data := time >= timestamp(2000, 5, 1, 00, 00) ? 0.754 : data
data := time >= timestamp(2000, 6, 1, 00, 00) ? 0.963 : data
data := time >= timestamp(2000, 7, 1, 00, 00) ? 0.159 : data
data := time >= timestamp(2000, 8, 1, 00, 00) ? -0.123 : data
data := time >= timestamp(2000, 9, 1, 00, 00) ? 0.216 : data

You just have to copy these files to your PineScript editor and replace the “data” assigning section. This way you can get limited custom data with low frequency inside PineScript and TradingView.

It’s not a great way to do that, you have too many limitations and it might be a bit slow in TradingView. Do you know other ways to load 3rd party data in TradingView? Let me know!

If you want to learn more about PineScript check out my PineScript Programming Course.

Also, for more interesting content from me follow me on TradingView and YouTube.