Pine Script ExportNovember 7, 202612 min read

Pine Script Export: Get Chart Data, Results and Strategies Out

How to do a Pine Script export: download TradingView chart data as CSV, include plotted values, handle bar limits, and carry a tested strategy back into Pine.

Pine Script Export: Get Chart Data, Results and Strategies Out

Pine Script cannot write files on its own, so a Pine Script export means one of two things. You either download the chart's data and plotted indicator values from TradingView as a CSV, or you take a strategy tested elsewhere and export it as Pine code to run on your chart. This guide covers both, plus the limits that cause most failed exports.

TL;DR

  • Pine Script has no built-in function to save files to your computer. Exports run through TradingView's chart menu, not through your code.
  • Anything your script plots (and keeps visible) becomes a CSV column, next to time, open, high, low, close and volume.
  • The export contains only the bars loaded on the chart, so scroll back first. Hand-drawn lines and zones are never included.
  • The CSV is evidence for checking a backtest, not a forecast. Treat results as a stress test.
  • Going the other way, we export tested strategies from Backtestify in TradingView Pine script format.

Table of Contents

What "Pine Script export" actually covers

Traders search this phrase for three different jobs, and the method differs for each:

  1. Export the data behind a chart: prices plus every indicator value, as a CSV for Excel, Python or R.
  2. Export a strategy's results: trade list, win rate, profit factor, drawdown, for a spreadsheet.
  3. Export a strategy as Pine code: so a rule set you tested or improved off-platform runs on a TradingView chart.

The first is the one most people need, so it comes first.

Why a script cannot export data by itself

Pine Script runs on TradingView's servers in a sandbox. One published explanation notes that the language has no direct function for writing files such as CSVs to your machine or an outside database, and ties that to its architecture and security model. That is why every method below starts in the interface, not in the editor.

The practical workaround is simple. Make the script plot the numbers you want, then let the chart export carry them out.

How to export chart data as a CSV

The steps, as described by a TradingView export guide:

  1. Open the chart with the symbol, timeframe and indicators you want.
  2. Click the arrow next to Save on the top toolbar and choose "Download chart data...". The same option can also appear in the chart menu as "Export chart data".
  3. Pick a time format: ISO time or UNIX timestamp. Both are in UTC.
  4. Click Download.

You get one row per bar with time, open, high, low, close, volume and the visible indicator plots.

The menu wording shifts from time to time, so if you cannot find it, look in both the Save dropdown and the chart menu.

Plans and access

The same guide says the free Basic plan cannot export chart data and that Plus and above can. Its information on Essential is unclear, so confirm that tier on TradingView's own pricing page before you subscribe for this purpose.

Plan also sets how much history you can load. The guide lists these historical bar limits:

TradingView planHistorical bars
Basic5K
Essential10K
Plus10K
Premium20K
Ultimate40K

Limits like these change, so check the current figure on TradingView's plan page before you plan a long test around it.

If you are comparing price history across assets, such as live metal price charts, keep in mind that what you can download is always bounded by what the chart has loaded, not by what the data vendor holds.

Plans and access

Time formats and Excel

ISO time looks like 2020-07-21T06:00:00Z. A UNIX timestamp counts seconds since 1 January 1970 UTC. Excel reads neither as a date automatically. For a UNIX value in cell A2, use =A2/86400+DATE(1970,1,1) and format the cell as date and time.

One habit saves hours: stay in UTC through the whole analysis. Convert to your exchange's session time only at the end, and only for display.

Put your own Pine values in the export

The useful trick is that every value a script plots becomes a column. If no built-in indicator gives the number you need, write a short script in the Pine Editor, add it to the chart, then export.

For example, a script that plots a range percentage, an ATR percentage and volume produces columns named "Range %", "ATR %" and "Volume" beside the prices. Here is the idea in a few lines:

Plotted values become named CSV columns

//@version=6
indicator("Export helper", overlay=false)
rangePct = (high - low) / close * 100
plot(rangePct, title="Range %")
plot(ta.atr(14) / close * 100, title="ATR %")

Check TradingView's current Pine documentation for the version header, since it changes over time.

Use the plot title as the column name you want. Clear titles make the CSV readable months later.

Why a column goes missing

When an expected column is absent, the cause is almost always visibility. Hidden plots, indicators switched off in the Data Window settings and plots with display set to none are skipped. Volume appears only when the chart carries the Volume indicator.

Run this checklist before you click Download:

  • Every indicator you need is on the chart and visible.
  • The Data Window shows the values you expect.
  • Volume is on the chart if you want it.
  • No plot uses display none.

What never exports

Manually drawn objects such as trend lines, horizontal levels, zones and notes are not in the CSV. It holds prices and plotted values only. If your method depends on a level you drew by hand, turn that rule into code that plots the level, so the column exists.

This matters for price action work. If you want to know whether price respected your level, the level has to be a number on every bar.

Beat the bar limit

The file ends where the loaded history ends. Three ways to get more rows:

  • Scroll back first. Drag the chart left until more history loads, then export.
  • Use a higher timeframe. If you need daily or hourly bars, export those instead of minutes.
  • Export in pieces. Use different visible ranges and join the files on the timestamp column.

When you join pieces, drop duplicate timestamps at the seams and confirm the row count matches what you expect. For how much history a test actually needs, see our piece on how much historical data backtests need.

Exporting strategy results for a spreadsheet

Chart data export gives you bars and plots. Trade-level results (entries, exits, profit per trade) live in a different place: the strategy's own results panel inside TradingView. Look there for the list of trades and its export option, and check TradingView's current documentation for what your plan allows.

A second route avoids the panel entirely. Plot your strategy's position state, signal or equity as a series, then export the chart as above. You get a bar-by-bar record that lines up with price.

Once the data is in a spreadsheet, compute the numbers that matter:

  • Win rate: winning trades divided by all trades.
  • Profit factor: gross profit divided by gross loss.
  • Maximum drawdown: the largest fall from an equity peak to the following trough.

Always report them together. A high win rate with a poor profit factor is a common pattern in strategies that take small gains and absorb large losses.

If your numbers come from TradingView's tester, our eight-step Pine Script backtest checklist covers repainting and fill bugs that quietly inflate results.

Use the export as evidence, not as a prediction

A clean CSV can feel like proof. It is not. According to CMC Markets, backtest results do not guarantee future results, and a historical test cannot capture changing markets, slippage or the pressure of trading real money. It suggests treating a backtest as a stress test: you are checking whether a strategy fails obviously, not proving it will succeed.

The same source lists what exports and tests tend to leave out:

  • Slippage, spread widening and order delays.
  • Commissions and funding costs.
  • Data quality problems such as gaps, errors and survivorship bias.
  • Liquidity that may not hold at larger position sizes.

Build those costs into your spreadsheet columns before you read the totals. For a full method, see our step-by-step guide to backtesting a trading strategy.

Keep exported files personal

TradingView's exported data is for your own use. Redistributing exchange data can breach TradingView's terms and the exchange's licence. Share your method, your plotted formulas and your results, not the raw price files.

Exporting a tested strategy as Pine Script

The reverse direction is just as common. You describe or find a strategy, test it on historical data, tighten its rules, and then want it on your TradingView chart.

That is the workflow we built Backtestify around. You enter a strategy in plain English, we run it on real historical market data and show the trade-by-trade record with win rate, profit factor and maximum drawdown. You can then improve the rules and compare the original and improved versions side by side on recent data. Finished strategies can be exported in TradingView Pine script format.

After you paste exported code into the Pine Editor, do three checks:

  1. Add it to a chart and confirm it compiles without errors.
  2. Compare a handful of trades against the report, entry by entry.
  3. Run the same period in both places. Small gaps usually trace to data feeds, session settings or commission assumptions.

This closes the loop: test off-chart, export to Pine, then verify on the chart you trade from.

Try it with your own strategy

Backtestify has a Free tier, and the Pro plan, which unlocks unlimited backtesting, improvement and forecasting, costs $29 per month or $190 per year. You can test a strategy you saw on a trading channel before you put capital behind it, and compare the original with an improved version on recent data. See Backtestify Pro and plan details or start on the Free plan.

Backtestify

If you want to see how a finished report reads first, our blog on backtesting methodology shows how we approach testing and statistics.

A repeatable export workflow

Put it all together as a routine you can run on any strategy:

  1. Convert every rule to code that plots a number, including any levels you draw by hand.
  2. Make sure all plots are visible and the Volume indicator is on the chart.
  3. Scroll back until the history you need is loaded, or export in pieces.
  4. Download with ISO time and keep everything in UTC.
  5. Convert timestamps in your spreadsheet and join any pieces on time.
  6. Add costs and slippage assumptions before computing win rate, profit factor and drawdown.
  7. Split the data: tune on one period, then judge on a later period you did not touch.

Step 7 is the one that separates a useful test from a flattering one. For timeframe-specific advice, see our guides to intraday backtesting and swing trading backtests.

FAQ

Can Pine Script export data to a CSV file directly?

No. Pine Script runs in a sandbox on TradingView's servers and has no function that writes files to your computer. Plot the values you need, then use the chart's "Download chart data..." option to get them as a CSV.

Why are my indicator columns missing from the exported CSV?

Usually the plot is hidden, switched off in the Data Window settings, or set to display none. Make every plot visible and confirm the Volume indicator is on the chart if you want volume. Then export again.

Does the free TradingView plan allow chart data export?

According to one export guide, the free Basic plan cannot export chart data, while Plus and above can. Plans and features change, so confirm your tier on TradingView's pricing page.

How do I get more history in my export?

Scroll back on the chart so more bars load before you download, or switch to a higher timeframe. You can also export several visible ranges and join the files by timestamp. The file always ends where the loaded history ends.

Can I export a strategy from Backtestify to Pine Script?

Yes. Backtestify can export results in TradingView Pine script format, so a strategy you tested and improved can run on your chart. Paste the code into the Pine Editor, add it to a chart, and compare a few trades with the report.

Sources