OPEN-SOURCE SCRIPT
Updated

Visible Range

73
Overview This is a precision tool designed for quantitative traders and engineers who need exact control over their chart's visual scope. Unlike standard time calculations that fail in markets with trading breaks (like A-Shares, Futures, or Stocks), this indicator uses a loop-back mechanism to count the actual number of visible bars, ensuring your indicators (e.g., MA60, MA200) have sufficient sample data.

Why use this? If you use multi-timeframe layouts (e.g., Daily/Hourly/15s), it is critical to know exactly how much data is visible.

The Problem: In markets like the Chinese A-Share market (T+1, 4-hour trading day), calculating Time Range / Timeframe results in massive errors because it includes closed market hours (lunch breaks, nights, weekends).

The Solution: This script iterates through the visible range to count the true bar_index, providing 100% accurate data density metrics.

Key Features

True Bar Counting: Uses a for loop to count actual candles, ignoring market breaks. perfect for non-24/7 markets.

Integer Precision: Displays time ranges (Days, Hours, Mins, Secs) in clean integers. No messy decimals.

Compact UI: Displays information in a single line (e.g., View: 30 Days (120 Bars)), default to the Top Right corner to save screen space.

Fully Customizable: Adjustable position, text size, and colors to fit any dark/light theme.

Performance Optimized: Includes max_bars_back limits to prevent browser lag on deep history lookups.

Settings

Position: Default Top Right (can be moved to any corner).

Max Bar Count: Default 5000 (Safety limit for loop calculation).
Release Notes
Minor bug fixes and enhancement

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.