plotbar() - Pine Script Function
plotbar()
Section titled “plotbar()”Overview
Section titled “Overview”plotbar() renders a traditional OHLC bar for each element in the supplied open, high, low, and close series. It is useful when you need to show alternate market sessions, synthetic bars, or higher-timeframe data without switching the main chart period.
Set overlay=true in your indicator() declaration to draw the bars in the price pane. Otherwise, `plotbar()` paints to the script’s separate pane.
Syntax
Section titled “Syntax”plotbar(open, high, low, close, title, color, editable, show_last, display, format, precision, force_overlay) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
open | series int/float | Open values for each bar. |
high | series int/float | High values. |
low | series int/float | Low values. |
close | series int/float | Close values. |
title | const string (optional) | Plot name shown in the style dialog. |
color | series color (optional) | Bar color. Defaults to bullish/bearish theme colors. |
display | input plot_display (optional) | Control where bar information appears (pane, status line, data window, etc.). |
Other optional arguments (editable, show_last, format, precision, force_overlay) mirror those provided by plot().
Remarks
Section titled “Remarks”- If any of the OHLC values are
naon a bar, no bar is drawn for that bar. - Use
plotbar()for transparent overlays by supplying a color with high alpha (color.new(color.green, 80)). - Combine with
request.security()to fetch and display higher-timeframe data while working on intraday charts.
Example
Section titled “Example”//@version=5indicator("Higher-timeframe bar overlay", overlay=true)
htf = input.timeframe("D", "Higher timeframe")
[htfOpen, htfHigh, htfLow, htfClose] = request.security(syminfo.tickerid, htf, [open, high, low, close])
barColor = htfClose >= htfOpen ? color.new(color.green, 20) : color.new(color.red, 20)
plotbar(htfOpen, htfHigh, htfLow, htfClose, title="Higher timeframe bars", color=barColor, force_overlay=true)