Skip to main content

How to Get Historical Data from TradingView: A Complete Guide for Traders and Analysts

· 15 min read

TradingView has become that go-to charting tool for so many traders, investors, and folks just trying to understand the markets. No matter what you're doing—testing out an old strategy, digging into market trends, or even building your own trading algorithms—knowing how to pull historical data from TradingView is a game-changer. It opens the door to so much analysis you can do on your own terms. This guide will walk you through all the different ways to get that data, from the simple built-in export button to more advanced methods that can grab thousands of data points for you.

How to Get Historical Data from TradingView: A Complete Guide for Traders and Analysts

Getting to Know TradingView's Built-in Export Feature

Right within TradingView, there's a handy feature that lets you directly export the data from your chart. This includes the OHLC prices (Open, High, Low, Close), trading volume, and even the values of any indicators you have on your screen. The best part is it downloads everything as a CSV file, which is a universal format that plays nicely with Excel, Google Sheets, Python, and just about any other analysis tool you might use.

A key thing to remember is that the export will capture exactly what you're seeing. So, before you hit download, double-check that your chart is set up just how you want it—with the right time frame and indicators. This gives you a detailed snapshot of the market to use for your own backtesting, custom reports, or deeper analysis.

Your Simple Guide to Exporting Chart Data from TradingView

Pulling historical data from TradingView is surprisingly straightforward. Here’s how to do it, step-by-step.

First, pull up the chart with the data you need. Make sure it's set to the right timeframe and that any indicators you want to save are visible. On a computer, look at the toolbar right above your chart. You’ll find a dropdown menu—it's usually the one with three dots or is labeled "Chart."

Click that menu and choose "Export chart data." A window will pop up where you can tweak a few settings. You get to pick exactly what data is included and, helpfully, you can choose your preferred time format. If you're plugging the data into another program, a Unix timestamp might be best. If you just want to read it easily, go with the ISO format.

A handy preview shows you exactly what your file will look like before you download it. Once you're happy with everything, just hit "Export," and a CSV file will download right to your computer.

If you're on your phone, you can do the exact same thing. Just tap the three-dot menu icon on the chart and follow the same steps.

One thing to keep in mind: the export only saves the data that's currently loaded on your screen. So if you need a longer history, just zoom out on the chart to load more bars before you export. For more advanced chart management, check out our guide on how to zoom out on TradingView.

One of TradingView's most powerful features is the ability to dive deep into the past, right from the chart itself. It's like having a financial time machine at your fingertips.

At the bottom of every chart, you'll find a timeline. You can click and drag this to scroll through years, or even decades, of price history for stocks, forex, commodities, and indices. Need to see what happened during a specific market event? Use the "Go To" icon to instantly jump to that exact date.

Why is this so useful? It allows you to see how your favorite technical indicators and drawing tools would have performed in the past. You can test out ideas visually and spot patterns you might otherwise miss.

Here’s a quick look at what you can do:

FeatureWhat It Lets You DoWhy It's Helpful
Timeline NavigatorScroll smoothly through years of price data.Get a long-term perspective on an asset's behavior.
"Go To" FunctionInstantly jump to a specific date or period.Quickly analyze what happened during key market events.
Indicator OverlayApply studies (like RSI or Moving Averages) to past data.Visually backtest how a strategy might have worked historically.
Drawing ToolsMark support/resistance levels on old price action.Identify patterns and key levels that are still relevant today.

This combination of a clean layout and responsive design makes studying past market cycles and identifying long-term trends both intuitive and efficient. It’s all about giving you the context needed to make more informed decisions.

Get Trading Data Automatically with TvDatafeed

If you're a developer or someone who works with data and needs to pull historical market information without the hassle of manual downloads, the TvDatafeed Python library is a fantastic tool for that. Think of it as your personal assistant for fetching trading data directly into your Python environment.

This handy library lets you automatically download up to 5,000 bars of data for pretty much any timeframe you need. You can grab data for different intervals, like:

  • 1-minute
  • 5-minute
  • Hourly
  • Daily
  • Weekly
  • Monthly

Getting started is simple. Just pop this command into your terminal to install it:

pip install --upgrade --no-cache-dir git+https://github.com/rongardF/tvdatafeed.git

Once it's installed, you'll import it into your script and set up the connection. You can use your TradingView username and password, but the cool part is that it often works without them too (just know that you might not have access to every single symbol without logging in).

The real workhorse here is the get_hist method. This is the function you'll use to actually get your data. You tell it what you want by filling in parameters like:

  • The stock or futures symbol (like 'NIFTY')
  • The exchange it's traded on (like 'NSE')
  • The timeframe or interval you want
  • How many bars of data to fetch
  • If it's a futures contract, which specific one

For example, if you wanted to pull the last 1,000 hours of data for a NIFTY futures contract, your code would look something like this:

data = tv.get_hist(symbol='NIFTY', exchange='NSE', interval=Interval.in_1_hour, n_bars=1000, fut_contract=1)

The best part? It hands you the data back as a clean pandas DataFrame. This means it's ready to go for your next step, whether that's analysis, building a model, or creating a chart, without any extra fuss.

Understanding Data Limitations and Requirements

Before you dive into analyzing historical data from TradingView, it's helpful to know how the platform works so you can set up your project for success. Think of it like this: what you see on your chart is exactly what you'll get when you export. That means getting your timeframe right from the start is super important.

Your access to data depends on your account type. If you're using a free account, you'll run into some limits on how much old data you can pull and how far back you can go. Upgrading to a paid subscription is like getting the master key—it opens up the full, deep library of historical information.

Here’s a quick breakdown of what that generally looks like:

Account TypeExport VolumeHistorical Depth
Free AccountRestrictedLimited
Paid SubscriptionFull AccessComprehensive

If you're curious about the technical side, TradingView's system is built to manage this data efficiently. It uses special access points to grab one-minute data bars for entire days, working its way backward from the present moment to build a reliable historical record. This process also helps fill in any gaps or inconsistencies in the live data stream.

A key rule they follow is to ensure consistency: the real-time, streaming data you see should closely match the historical records, typically within a 5% tolerance for actively traded symbols. This helps keep everything accurate and trustworthy.

Beyond the Official Tools: How to Access TradingView Data

So, you've ever wished you could grab data from TradingView charts to use in your own projects, but quickly found out there isn't a simple, official API for everyone to use? You're not alone. This is a common hurdle, and the developer community has gotten pretty creative in finding ways around it.

Here’s a look at the common approaches people take, along with some important things to consider before you dive in.

Community-Driven Solutions

Because there's no universal public API, developers have built their own tools. The most common method you'll find is web scraping. In simple terms, this uses scripts to automatically read and collect the price and indicator data that TradingView publicly displays on its charts. This is especially popular for folks building machine learning models who need large, historical datasets.

You can often find these scripts and tools on platforms like GitHub, where developers share their code. They range from simple Python scripts to more robust libraries.

A Word of Caution

Before you get too excited, it's crucial to understand the potential downsides of these workarounds.

  • Terms of Service: Techniques like intercepting the website's private API calls or aggressively scraping data often go against TradingView's Terms of Service. Your account could be restricted if you're not careful.
  • Fragility: These are unofficial methods. If TradingView updates its website or changes how its charts work, your scraping script or tool could break overnight.

Because of these risks, it's always best to see if an official data source meets your needs first.

A More Reliable Community Project

Among the various workarounds, some solutions have proven to be more stable and well-maintained. The TvDatafeed library is a great example. It's a Python library that has gained significant trust within the community and is regularly updated to work with changes on the TradingView site. While still unofficial, it represents a more polished and dependable approach than building a scraper from scratch.

Working with Pine Script and Historical Data

If you're building your own indicators and strategies on TradingView, you'll quickly need to get comfortable with how Pine Script handles historical data. It works quite differently from most programming languages you might be used to.

Instead of you writing loops to go through price data, Pine Script's engine does the looping for you. Imagine it's like a film projector, shining a light on each individual bar (or frame) of your chart, one after another, from left to right. Your script runs its logic separately on each of those bars. This built-in design is what makes processing years of historical data so efficient—you don't have to manage the looping process yourself.

When you need to perform calculations that look back at previous bars, it's best to use Pine Script's built-in functions. For example, if you want a 20-bar sum, using math.sum() is not only easier to write but is also optimized to be much faster than if you tried to create the same calculation manually.

For tasks where you need a running total that accumulates over the entire history of the chart, self-referencing variables are your most powerful and efficient tool. Getting a solid grasp of this relationship between your code and the historical data is the foundation for creating effective and responsive custom tools on TradingView. If you're new to Pine Script, our guide on TradingView's Pine Script Editor can help you build a strong foundation.

Pineify Website

If you want to apply these Pine Script concepts without writing code, Pineify's visual editor lets you build complex indicators and strategies using the same efficient historical data processing principles. You can create running totals, multi-bar calculations, and sophisticated conditions through an intuitive interface that handles all the technical optimization for you.

Getting the Most from Your TradingView Data

Getting real value from your TradingView history isn't just about clicking 'export.' It's about building a few simple habits to make sure the data you get is the data you actually need.

Before you do anything, always do a quick double-check. Make sure your chart is showing the right symbol, the correct timeframe, and the specific indicators you care about. It’s an easy step to skip, but it saves so much frustration later.

If you're trying to analyze long-term trends, it's a good idea to zoom out on your chart first. This forces TradingView to load more historical bars into its memory, which means you can export a much larger dataset for your analysis.

When you're using automated tools (like TvDatafeed in Python), start small. Run a test with just 10 or 20 bars to confirm everything is working as expected. Once you know it's set up correctly, then you can go back and request the full, massive dataset with confidence.

For Backtesting, Export Don't Recalculate This is a big one for accuracy. When you're preparing data for backtesting, always export the data with the indicators already included. Don't just export the raw price data and then try to rebuild the indicators in another program. By exporting the values directly from TradingView, you guarantee they match exactly what you saw on your screen, which keeps your backtest honest. For more advanced strategy development, our guide on crafting a winning Pine Script strategy with stop loss covers essential risk management techniques.

A final heads-up: pay close attention to date and time stamps, especially if you trade overnight sessions or forex. The way TradingView represents time in its raw data can sometimes look different from the neat, adjusted view you see on a daily chart. Being aware of this small difference will prevent a lot of confusion when you start your analysis.

Your TradingView Data Export Questions, Answered

I'm on a free plan. Can I still get my historical data out of TradingView? Absolutely! You can export chart data even with a free account. The main difference is that paid plans let you pull more data from further back in history. But the basic "export" button is there for everyone.

What kind of file will I get when I export? You'll get a CSV file. This is the best kind of file for data because it's so universal. You can open it directly in spreadsheet programs like Excel or Google Sheets, and it works perfectly with data analysis tools like Python's pandas library.

How much data can I pull at once using a tool like TvDatafeed? With the TvDatafeed library, you can grab up to 5,000 "bars" of data in a single request. A "bar" is just one candlestick on your chart, whether it's a 1-minute, 1-hour, or 1-day chart. If you need more than 5,000 bars, you can simply make multiple requests for different date ranges to build a larger dataset.

Will my export include the indicators I'm using? Yes! This is a really useful feature. When you download your data, the CSV file won't just have the open, high, low, close, and volume. It will also have columns with the calculated values for every indicator you've added to the chart.

Is there a way to automate this process? TradingView itself doesn't have an official, public API for automatically grabbing chart data. However, the community has built some clever workarounds. Unofficial Python libraries, like TvDatafeed, have become popular for this exact purpose, allowing you to pull data directly into your automated analysis scripts.

Your Next Steps

Now that you know how to pull historical data from TradingView, here’s how you can get your hands dirty and make the most of it.

Start simple: pick one asset you're currently watching or trading, and export its data. Open the CSV in a spreadsheet (like Excel or Google Sheets) and just poke around. Look at the columns, sort the dates, and maybe even plot a simple price chart. Getting familiar with the raw data is the best first step.

If you’ve dabbled in Python, this is a great place to use it. The TvDatafeed library can help you automate the boring stuff. Set up a small script to grab data for you regularly, and slowly build your own little historical database over time.

As you go, keep notes. Jot down your process. You could even create different spreadsheet templates for different kinds of analysis, like:

  • Backtesting a simple strategy: See how a "buy when the price crosses above the 50-day average" rule would have worked.
  • Market research: Compare the volatility of two different stocks over the same period.
  • Prepping for models: Getting clean, consistent data is the first and most important step for any machine learning project.

Hit a snag? Have a success story? Trading is more fun when you share the journey. Drop into a trading community or leave a comment below. Tell us what you're building or what's tripping you up—someone has probably been there too.

The real magic happens when you move from theory to practice. The more you interact with this data, the better you'll understand the stories the charts are telling. So, go ahead—export that first CSV file and see what you find. And if you're looking to enhance your technical analysis toolkit, our guide on ATR stop loss in Pine Script can help you incorporate volatility measurements into your data analysis.