rectangle
Draws a Rectangle using a starting time/price and an ending time/price. Great for marking supply/demand zones, fair value gaps, or consolidation areas. Supports fill, extension, labels, and even a midline inside the box.
Syntax (one line)
rectangle(startTime, topPrice, endTime, bottomPrice, styles?, text?)
Parameters
startTime (number) · Left edge time of the rectangle.
topPrice (number) · Upper price boundary.
endTime (number) · Right edge time of the rectangle.
bottomPrice (number) · Lower price boundary.
styles (RectangleLineToolOverrides) · Customize the appearance:
backgroundColor(RGBAColor | BaseColors) · Fill color.color(RGBAColor | BaseColors) · Border color.extendLeft(boolean) · Extend the box to the left.extendRight(boolean) · Extend the box to the right.fillBackground(boolean) · Fill inside the box.linewidth(number) · Border thickness.middleLine(object) · Optional midline:{ lineColor, lineStyle, lineWidth, showLine }.showLabel(boolean) · Show a label text inside the rectangle.textColor(RGBAColor | BaseColors) · Label text color.transparency(number) · 0–100 fill transparency (higher = lighter).fontSize,bold,italic,horzLabelsAlign,vertLabelsAlignfor label control.text(string) · Optional text shown ifshowLabelis true.
Return Value
(string) · The ID of the created rectangle.
Example
What this does: Every 40 bars, draws a light green rectangle covering a recent range, extended to the right, with a label.
Tips
Use
extendRightto project supply/demand zones into the future.Keep high
transparencyso price action remains visible.Add a
middleLineto track the mid-level of the zone.
Warning
Very narrow rectangles may be hard to read.
If
showLabelis true, pass a shorttextto avoid overlap with candles.
Good Practice
Reuse a fixed style set for demand vs supply (e.g., green vs red) for clarity.
Store your styles in a
constobject and reuse them to keep scripts tidy.
Last updated