Skip to content

How many bars does a TradingView chart have?

How many bars does a TradingView chart have?

Section titled “How many bars does a TradingView chart have?”

TL;DR
Bar counts depend on plan limits, symbol history, and exchange data; use a helper label to display how many bars are available.

DifficultyBeginner
Time to implement10-15 min
CategoryUtility

Backtests and indicators only see the bars TradingView loads. Knowing the count prevents you from assuming extra history exists—and helps you pick the best data source (some exchanges provide deeper history than others).

CallPurpose
bar_indexZero-based index of the current bar (last bar ≈ total bars - 1).
syminfo.tickerSymbol name to annotate bar counts.
label.new, label.set_text, label.set_xyDisplays the bar count in the corner of the chart.
barstate.islastEnsure you update the label on the final bar only.
  1. Check plan limits and exchange data
    Different TradingView plans load different maximum bars; some exchanges provide more history. Test alternate exchanges (symbol@EXCHANGE) to find the deepest data.

  2. Display the bar count
    Use a single var label and update it on the last bar.

    var label countLabel = label.new(na, na, style=label.style_label_left)
    if barstate.islast
    label.set_text(countLabel, "Bars: " + str.tostring(bar_index + 1))
    label.set_xy(countLabel, bar_index, high)
  3. Use the information
    Adjust lookback lengths, backtests, and data requests using the reported bar count.

//@version=5
indicator("Chart bar counter", overlay=true)
var label countLabel = label.new(
x = na,
y = na,
text = "",
style = label.style_label_left,
textcolor = color.white,
color = color.new(color.teal, 0),
size = size.large
)
if barstate.islast
totalBars = bar_index + 1
labelText = str.format("{0}\nBars: {1,number,#,###}", syminfo.ticker, totalBars)
label.set_text(countLabel, labelText)
label.set_xy(countLabel, bar_index, high)
Why this works.
  • `var` ensures the label is created only once; subsequent bars update it.
  • `bar_index + 1` converts the zero-based index into a human-readable bar count.
  • Formatting with `#,###` adds thousand separators for long histories.
  • Free plans load fewer bars (approx. 5,000); Premium plans exceed 30,000+. Expect variance by symbol.
  • Some exchanges (e.g., IDC for FX) offer decades of data, while others start only a few years back.
  • Use the bar count when setting lengths for moving averages or backtests—avoid requesting more bars than exist.
  • When you scroll further back, TradingView may load additional history; the counter updates accordingly.

Why does the bar count change when I scroll?

Section titled “Why does the bar count change when I scroll?”

TradingView dynamically loads more data as you scroll. The counter updates once the new bars are downloaded.

Two exchanges show different bar counts—what should I trust?

Section titled “Two exchanges show different bar counts—what should I trust?”

Pick the exchange with longer and more reliable history for your use case. Document which data feed you rely on in your strategy notes.

  • TradingView’s available history depends on plan tier, exchange, and symbol age.
  • A simple label powered by bar_index lets you see the exact number of bars on the chart.
  • Use that information to size lookbacks, pick exchanges, and set realistic backtest windows.

Adapted from tradingcode.net, optimised for Algo Trade Analytics users.