chart - PineScript Variable
Overview
Section titled “Overview”The chart record exposes read-only information about the user’s current chart configuration, such as whether a non-standard price style is active or which bars are visible. Use these fields to adapt overlays to the user’s environment.
Fields
Section titled “Fields”| Field | Type | Description |
|---|---|---|
chart.bg_color | series color | Background color of the pane where the script runs. |
chart.fg_color | series color | Foreground color (text/axes) of the pane. |
chart.is_standard | series bool | true when the chart uses standard candles/bars. |
chart.is_heikinashi | series bool | true on Heikin Ashi charts. |
chart.is_renko | series bool | true on Renko charts. |
chart.is_linebreak | series bool | true on Line Break charts. |
chart.is_kagi | series bool | true on Kagi charts. |
chart.is_range | series bool | true on Range charts. |
chart.is_pnf | series bool | true on Point & Figure charts. |
chart.left_visible_bar_time | series int | UNIX timestamp (ms) for the leftmost visible bar. |
chart.right_visible_bar_time | series int | UNIX timestamp (ms) for the rightmost visible bar. |
Remarks
Section titled “Remarks”- Only one of the style flags (
chart.is_*) is typicallytrueat a time; use them to adjust calculations for synthetic chart types. - Visible range timestamps update as the user scrolls or zooms, enabling dynamic filters (e.g., show labels only inside the viewport).
- Colors reflect user theme settings, letting you adjust overlay elements for contrast.
Example
Section titled “Example”//@version=5indicator("Chart metadata", overlay=true, max_labels_count=1)
description = str.format( "Style: {0}\nLeft: {1}\nRight: {2}", chart.is_heikinashi ? "Heikin Ashi" : chart.is_renko ? "Renko" : chart.is_linebreak ? "Line Break" : chart.is_kagi ? "Kagi" : chart.is_range ? "Range" : chart.is_pnf ? "Point & Figure" : "Standard", str.format_time(chart.left_visible_bar_time, "yyyy-MM-dd HH:mm"), str.format_time(chart.right_visible_bar_time, "yyyy-MM-dd HH:mm"))
if barstate.islastconfirmedhistory label.new(bar_index, high, text=description, textcolor=color.white, bgcolor=chart.bg_color, style=label.style_label_left)