plotshape() - Pine Script Function
plotshape()
Section titled “plotshape()”Overview
Section titled “Overview”plotshape() draws pre-defined glyphs—triangles, flags, labels, arrows—whenever a condition evaluates to true. It is a versatile alternative to plotchar() when you prefer consistent iconography or need text labels anchored to bars.
The `series` argument is treated as boolean for all locations except location.absolute. Use `location.absolute` when you need to position shapes at a specific price value.
Syntax
Section titled “Syntax”plotshape(series, title, style, location, color, offset, text, textcolor, editable, size, show_last, display, format, precision, force_overlay) → voidParameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
series | series int/float/bool | Determines whether a shape is drawn on each bar. |
style | input shape (optional) | Glyph to draw (e.g., shape.triangleup, shape.labeldown). Defaults to shape.xcross. |
location | input location (optional) | Placement relative to the bar (location.abovebar, location.belowbar, location.absolute, etc.). |
color | series color (optional) | Fill color for the shape. |
text | const string (optional) | Optional caption displayed inside label-style shapes or on hover. |
size | const size (optional) | Glyph size ranging from size.tiny to size.huge. |
offset | simple int (optional) | Horizontal shift in bars. |
Other optional arguments (title, textcolor, editable, show_last, display, format, precision, force_overlay) mirror plot() defaults.
Remarks
Section titled “Remarks”- Shapes are hidden on bars where
seriesevaluates tona. - Label styles such as
shape.labelupandshape.labeldownaccept multiline text via\n. - Combine
plotshape()withdisplay=display.noneto generate handles forfill()or for toggling visibility through script inputs.
Example
Section titled “Example”//@version=5indicator("plotshape() breakouts", overlay=true)
length = input.int(20, "Range lookback", minval=2)upper = ta.highest(high, length)lower = ta.lowest(low, length)
breakoutUp = ta.cross(close, upper)breakoutDn = ta.cross(lower, close)
plotshape(breakoutUp, title="Breakout up", style=shape.triangleup, location=location.abovebar, color=color.new(color.green, 0), size=size.small, text="Range breakout")
plotshape(breakoutDn, title="Breakout down", style=shape.triangledown, location=location.belowbar, color=color.new(color.red, 0), size=size.small, text="Range breakdown")