How to Get Historical Data from TradingView for Backtesting
Historical data in TradingView refers to past price records—OHLC values, volume, and indicator readings—that traders export for backtesting strategies and analyzing market behavior. Whether you're testing an old strategy, digging into market trends, or building trading algorithms, knowing how to pull historical data from TradingView saves you time. I pulled 5,000 bars of AAPL data last month for a momentum backtest, and the built-in export took about 30 seconds.
TradingView's Built-in Export Feature
Inside TradingView there's a feature that lets you export the data from your chart directly. This includes the OHLC prices (Open, High, Low, Close), trading volume, and even the values of any indicators you have on your screen. It downloads everything as a CSV file, which opens in Excel, Google Sheets, Python, and just about any other analysis tool you might use.
The export captures exactly what you're seeing on screen. Before you hit download, double-check that your chart is set up the way you want it—with the right time frame and indicators. This gives you a snapshot of the market for backtesting, custom reports, or deeper analysis. I've made the mistake of exporting before switching to the daily timeframe and ended up with useless 5-minute bars, so verify first.
Step-by-Step: Exporting Chart Data from TradingView
Exporting historical data from TradingView is straightforward once you know where to click and what to check.
First, pull up the chart with the data you need. Set the right timeframe and make sure any indicators you want to save are visible. On a computer, look at the toolbar right above your chart. There's a dropdown menu—usually the one with three dots or labeled "Chart."
Click that menu and choose "Export chart data." A window pops up where you can tweak a few settings. You can pick exactly what data to include and 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. Why does this matter? Because some backtesting software expects timestamps in a specific format, and getting it wrong means your date column ends up looking like garbage.
A preview shows you exactly what your file will look like before you download it. Once you're happy, hit "Export," and a CSV file downloads to your computer.
On your phone, you can do the exact same thing. Tap the three-dot menu icon on the chart and follow the same steps.
One thing to watch out for: the export only saves the data loaded on your screen. If you need a longer history, zoom out on the chart to load more bars before you export. For more on that, check out our guide on how to zoom out on TradingView. If you export without zooming out, you might end up with just the last 100 bars—not enough for a meaningful backtest.
Working with Historical Data on the Platform
One of TradingView's most useful features is the ability to go deep into the past right from the chart itself. At the bottom of every chart, you'll find a timeline. You can click and drag to scroll through years, or decades, of price history for stocks, forex, commodities, and indices. Need to see what happened during a specific event? Use the "Go To" icon to jump to that exact date.
Why does this matter? It lets you see how your favorite technical indicators and drawing tools would have performed in the past. You can test ideas visually and spot patterns you might otherwise miss. I use this all the time when I want to check how a stock like TSLA behaved during the 2020 crash without exporting anything.
Here's a quick look at what you can do:
| Feature | What It Lets You Do | Why It's Helpful |
|---|---|---|
| Timeline Navigator | Scroll smoothly through years of price data. | Get a long-term perspective on an asset's behavior. |
| "Go To" Function | Instantly jump to a specific date or period. | Quickly analyze what happened during key market events. |
| Indicator Overlay | Apply studies (like RSI or Moving Averages) to past data. | Visually backtest how a strategy might have worked historically. |
| Drawing Tools | Mark 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 about giving you the context needed to make more informed decisions.
Automating with TvDatafeed
If you're a developer who needs to pull historical market information without manual downloads, the TvDatafeed Python library is a solid choice. Think of it as a script that fetches trading data directly into your Python environment.
This library lets you download up to 5,000 bars of data for most timeframes:
- 1-minute
- 5-minute
- Hourly
- Daily
- Weekly
- Monthly
Getting started is simple. Run this command in your terminal:
pip install --upgrade --no-cache-dir git+https://github.com/rongardF/tvdatafeed.git
Once installed, you import it into your script and set up the connection. You can use your TradingView username and password, though it often works without them (you just might not get access to every symbol without logging in).
The get_hist method is the main function you'll use. Parameters include:
- The stock or futures symbol (like 'NIFTY')
- The exchange (like 'NSE')
- The timeframe or interval
- How many bars to fetch
- If it's a futures contract, which one
For example, to pull the last 1,000 hours of data for a NIFTY futures contract:
data = tv.get_hist(symbol='NIFTY', exchange='NSE', interval=Interval.in_1_hour, n_bars=1000, fut_contract=1)
It returns the data as a pandas DataFrame, ready for analysis, building a model, or creating a chart without extra work. I prefer this method over manual CSV exports when I need to run a strategy test on multiple symbols—exporting AAPL, MSFT, and GOOGL one by one gets old fast.
One limitation I've run into: the library doesn't work well for tick-level data. If you need every single trade, you'll have to look elsewhere. Intraday bars work fine, though, and I haven't tested it on every exchange out there.
Data Limitations and Requirements
Your access to historical data depends on your account type. A free account has limits on how much old data you can pull and how far back you can go. A paid subscription opens up the full library of historical information.
Here's the general breakdown:
| Account Type | Export Volume | Historical Depth |
|---|---|---|
| Free Account | Restricted | Limited |
| Paid Subscription | Full Access | complete |
On the technical side, TradingView's system manages data by grabbing one-minute bars for entire days, working backward from the present to build a reliable historical record. This process also fills in any gaps or inconsistencies in the live data stream.
A key rule: the real-time streaming data should match the historical records, typically within a 5% tolerance for actively traded symbols. This keeps things reasonably trustworthy.
I've found that with free accounts, you often can't get data older than a few months for some symbols. That's fine for short-term analysis, but if you need a decade of daily SPY data, you'll want a paid plan or an alternative data source. I haven't tested this on every exchange, so your mileage may vary on smaller markets.
Beyond the Official Tools
So you've wished you could grab data from TradingView charts to use in your own projects, but found out there's no simple, official API for everyone to use. You're not alone. This is a common hurdle, and the developer community has gotten creative.
Community-Driven Solutions
Developers have built their own tools. The most common method is web scraping—using scripts to automatically read and collect the price and indicator data that TradingView displays on its charts. This is especially popular for folks building machine learning models who need large datasets.
You can often find these scripts on GitHub, ranging from simple Python scripts to larger libraries.
A Word of Caution
Before you go all-in, understand the downsides.
- Terms of Service: Intercepting the website's private API calls or aggressively scraping data often goes against TradingView's Terms of Service. Your account could be restricted.
- Fragility: These are unofficial methods. If TradingView updates its website or changes how its charts work, your scraping script could break overnight.
Because of these risks, check if an official data source meets your needs first.
A More Reliable Alternative
Among the workarounds, some solutions have proven more stable. The TvDatafeed library is a good example. It's a Python library that has gained trust within the community and is regularly updated. While still unofficial, it's more dependable than building a scraper from scratch.
Historical Data in Pine Script
If you're building indicators and strategies on TradingView, you'll need to understand how Pine Script handles historical data. It works differently from most programming languages.
Instead of writing loops to go through price data, Pine Script's engine does the looping for you. Think of it like a film projector, shining a light on each individual bar of your chart, one after another, from left to right. Your script runs its logic separately on each bar. This built-in design makes processing years of historical data efficient.
When you need calculations that look back at previous bars, use Pine Script's built-in functions. For example, math.sum() for a 20-bar sum is not only easier to write but also faster than a manual calculation. If you're new to Pine Script, our guide on TradingView's Pine Script Editor can help you build a strong foundation.
If you want to apply these concepts without coding, Pineify's visual editor lets you build complex indicators and strategies using the same historical data processing principles. You can create running totals, multi-bar calculations, and sophisticated conditions through an interface that handles the technical optimization for you. I've used it to set up a custom RSI strategy on ETH without writing a single line of code.
Getting the Most from Your TradingView Data
Getting real value from your history isn't just about clicking "export." It's about building simple habits to make sure the data you get is the data you actually need.
Before you do anything, double-check. Make sure your chart shows the right symbol, the correct timeframe, and the specific indicators you care about. It's an easy step to skip, but it saves frustration later. I once exported what I thought was AAPL data only to realize I had QQQ on screen—wasted an hour.
If you're analyzing long-term trends, zoom out on your chart first. This forces TradingView to load more historical bars into memory, which means you can export a larger dataset.
When you use automated tools (like TvDatafeed in Python), start small. Run a test with 10 or 20 bars to confirm everything works. Once you know it's set up correctly, then request the full dataset.
For Backtesting, Export Don't Recalculate When preparing data for backtesting, export the data with the indicators already included. Don't export raw price data and rebuild the indicators in another program. By exporting the values directly from TradingView, you guarantee they match what you saw on your screen, which keeps your backtest honest. For more on strategy development, our guide on crafting a winning Pine Script strategy with stop loss covers essential risk management techniques.
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 look different from the adjusted view on a daily chart. I've been burned by this—exporting forex data and thinking the daily close was at midnight when it was actually 5 PM EST.
Now that you know how to pull historical data from TradingView, pick one asset you're watching and export its data. Open the CSV in a spreadsheet and poke around. Look at the columns, sort the dates, plot a simple price chart. Getting familiar with the raw data is the best first step. If you're comfortable with Python, use the TvDatafeed library to automate the boring stuff. Set up a small script to grab data for you regularly, and build your own historical database over time. Keep notes on your process. Create different templates for different kinds of analysis—backtesting a simple moving average crossover, comparing volatility across two stocks, or prepping clean data for a machine learning project. The more you interact with this data, the better you'll understand the stories the charts are telling. And if you're looking to improve your technical analysis toolkit, the ATR stop loss in Pine Script guide can help you incorporate volatility measurements into your data analysis.
FAQ
Can I export historical data from TradingView on a free plan? Yes, you can export chart data even with a free account. Paid plans let you pull more data from further back, but the basic export button works for everyone.
What file format does TradingView use for export? CSV. It works in Excel, Google Sheets, and Python pandas without any conversion.
How much data can I pull with TvDatafeed? Up to 5,000 bars per request. Need more? Make multiple requests for different date ranges.
Does the CSV export include indicator values? Yes. The file includes columns for every indicator you have added to the chart, not just OHLCV data.
Is there an official API for automated downloads? No official public API exists. Unofficial libraries like TvDatafeed are the community workaround, but they come with no guarantees.

